Roundcube Community Forum

 

Download attachment link in message view

Started by qpmailman, October 18, 2006, 01:58:03 PM

Previous topic - Next topic

qpmailman

I figured out how to add a download attachments link when viewing the messages.

modify the code in program/steps/mail/show.inc line 112
from:
   $out .= sprintf('<li><a href=&quot;%s&amp;_part=%s&quot; onclick=&quot;return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)&quot;>%s</a></li>'.&quot;\n&quot;,
            htmlentities($GET_URL),
            $attach_prop['part_id'],
            $JS_OBJECT_NAME,
            $attach_prop['part_id'],
            $attach_prop['mimetype'],
            $attach_prop['filename']);

To:
   $out .= sprintf('
  • %s [%s]
  • '."\n",
                htmlentities($GET_URL),
                $attach_prop['part_id'],
                $JS_OBJECT_NAME,
                $attach_prop['part_id'],
                $attach_prop['mimetype'],
                $attach_prop['filename'],
                htmlentities($GET_URL),
                $attach_prop['part_id'],
              rcube_label('download'));

    This puts a download link next to the link with the attachment name.

    Don't forget to back up the original file.

     :D

    encode

    Thanks for an excellent and useful modification :D


    kmn

    Hello,

    The code hack above does not apply to latest rc. What change does it need?

    Thanks

    Light Shadow

    I'm using the SVN #657. I suppose that for other versions this should work (in 0.1-rc1 this code starts on line 130).

    You should replace this:
       $out .= sprintf('<li><a href=&quot;%s&amp;_part=%s&quot; onclick=&quot;return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)&quot;>%s</a></li>'.&quot;\n&quot;,
                htmlspecialchars($GET_URL),
                $attach_prop->mime_id,
                JS_OBJECT_NAME,
                $attach_prop->mime_id,
                $attach_prop->mimetype,
                $attach_prop->filename);

    with this:

       $out .= sprintf('
  • %s [%s]
  • '."\n",
                htmlspecialchars($GET_URL),
                $attach_prop->mime_id,
                JS_OBJECT_NAME,
                $attach_prop->mime_id,
                $attach_prop->mimetype,
                $attach_prop->filename,
                htmlspecialchars($GET_URL),
                $attach_prop->mime_id,
                rcube_label('download'));

    Thanks qpmailman!

    rhuckle

    Here Is Another Method Just Showing 1 Link To Click On Saying Download Attachment - filename
    ( ie [Download Attachment - roundcube.zip )

    this is what the user will see not the filename which they were also able to click on as well as the download link, meaning it had 2 links to download the attachment

    i come to an conclusion that i only needed 1 link and not 2 with the filename showing also

    So here is how i achieved this method

    Open show.inc ( program/steps/mail )

    Find

    $out .= sprintf('
  • %s
  • '."\n",
                htmlspecialchars($GET_URL),
                $attach_prop->mime_id,
                JS_OBJECT_NAME,
                $attach_prop->mime_id,
                $attach_prop->mimetype,
                $attach_prop->filename);

    Replace With

    $out .= sprintf('
  • %s - %s
  • '."\n",
                htmlspecialchars($GET_URL),
                $attach_prop->mime_id,
                rcube_label('Download Attachment'),
                $attach_prop->filename);

    The Above Will Show [Download Attachment] - filename.zip

    (instead of just file name without the filename being a link)

    Hope This Helps :)

    kmn

    Thanks rhuckle.

    Exactly what I was looking for.

    Regards

    kmn

    deathstar

    Just an after thought, but where you're using rube_label('Download Attachment'), it would be better to put something like rcube_label('download_attachment'). Then you can add download_attachment to your localization file, with a full description... Something like $labels['download_attachment'] = "Download this attachment".

    encode

    I'm using SVN 1190, and the download link added in by the code in Light Shadow's post doesn't seem to work properly.

    It behaves the same as me clicking on the attachment link - starts loading the binary file (doc, pdf, etc) in the current window as text. When I right click and choose save link as, the filename has .htm appended to it.

    What can I do to fix this?

    Thanks.