From 03149131f754dd122f8707fbfc9e7ff47e9d6524 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Sat, 10 Nov 2012 21:08:14 +0100 Subject: New feature: display attached images as thumbnails below message body --- program/steps/mail/func.inc | 49 ++++++++++++++++++++++++++++++++++++++------- program/steps/mail/get.inc | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 7 deletions(-) (limited to 'program/steps/mail') diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index f128a3834..c0d36daf4 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -1186,7 +1186,9 @@ function rcmail_message_body($attrib) } // list images after mail body - if ($CONFIG['inline_images'] && !empty($MESSAGE->attachments)) { + if ($RCMAIL->config->get('inline_images', true) && !empty($MESSAGE->attachments)) { + $thumbnail_size = $RCMAIL->config->get('image_thumbnail_size', 240); + foreach ($MESSAGE->attachments as $attach_prop) { // skip inline images if ($attach_prop->content_id && $attach_prop->disposition == 'inline') { @@ -1195,12 +1197,45 @@ function rcmail_message_body($attrib) // Content-Type: image/*... if (rcmail_part_image_type($attach_prop)) { - $out .= html::tag('hr') . html::p(array('align' => "center"), - html::img(array( - 'src' => $MESSAGE->get_part_url($attach_prop->mime_id, true), - 'title' => $attach_prop->filename, - 'alt' => $attach_prop->filename, - ))); + // display thumbnails + if ($thumbnail_size) { + $show_link = array( + 'href' => $MESSAGE->get_part_url($attach_prop->mime_id, false), + 'onclick' => sprintf( + 'return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)', + JS_OBJECT_NAME, + $attach_prop->mime_id, + rcmail_fix_mimetype($attach_prop->mimetype)) + ); + $out .= html::p('image-attachment', + html::a($show_link + array('class' => 'image-link'), + html::img(array( + 'class' => 'image-thumbnail', + 'src' => $MESSAGE->get_part_url($attach_prop->mime_id, true) . '&_thumb=1', + 'title' => $attach_prop->filename, + 'alt' => $attach_prop->filename, + 'style' => sprintf('max-width:%dpx; max-height:%dpx', $thumbnail_size, $thumbnail_size), + )) + ) . + html::span('image-filename', Q($attach_prop->filename)) . + html::span('image-filesize', Q($RCMAIL->show_bytes($attach_prop->size))) . + html::span('attachment-links', + html::a($show_link['href'] . '&_download=1', rcube_label('download')) + ) . + html::br(array('style' => 'clear:both')) + ); + } + else { + $out .= html::tag('fieldset', 'image-attachment', + html::tag('legend', 'image-filename', Q($attach_prop->filename)) . + html::p(array('align' => "center"), + html::img(array( + 'src' => $MESSAGE->get_part_url($attach_prop->mime_id, true), + 'title' => $attach_prop->filename, + 'alt' => $attach_prop->filename, + ))) + ); + } } } } diff --git a/program/steps/mail/get.inc b/program/steps/mail/get.inc index bcd57dee0..2397358a1 100644 --- a/program/steps/mail/get.inc +++ b/program/steps/mail/get.inc @@ -60,6 +60,42 @@ if (!empty($_GET['_frame'])) { exit; } +// render thumbnail of an image attachment +else if ($_GET['_thumb']) { + $pid = get_input_value('_part', RCUBE_INPUT_GET); + if ($part = $MESSAGE->mime_parts[$pid]) { + $thumbnail_size = $RCMAIL->config->get('image_thumbnail_size', 240); + $temp_dir = $RCMAIL->config->get('temp_dir'); + list(,$ext) = explode('/', $part->mimetype); + $cache_basename = $temp_dir . '/' . md5($MESSAGE->headers->messageID . $part->mime_id . ':' . $RCMAIL->user->ID . ':' . $thumbnail_size); + $cache_file = $cache_basename . '.' . $ext; + $mimetype = $part->mimetype; + + // render thumbnail image if not done yet + if (!is_file($cache_file)) { + $fp = fopen(($orig_name = $cache_basename . '.orig.' . $ext), 'w'); + $MESSAGE->get_part_content($part->mime_id, $fp); + fclose($fp); + + $image = new rcube_image($orig_name); + if ($imgtype = $image->resize($RCMAIL->config->get('image_thumbnail_size', 240), $cache_file, true)) { + $mimetype = 'image/' . $imgtype; + unlink($orig_name); + } + else { + rename($orig_name, $cache_file); + } + } + + if (is_file($cache_file)) { + header('Content-Type: ' . $mimetype); + readfile($cache_file); + } + } + + exit; +} + else if (strlen($pid = get_input_value('_part', RCUBE_INPUT_GET))) { if ($part = $MESSAGE->mime_parts[$pid]) { -- cgit v1.2.3