From d487cd5a6c3e6a7eaa125957a022495ba038b460 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak <alec@alec.pl> Date: Wed, 30 May 2012 06:17:26 -0400 Subject: [PATCH] Merge branch 'dev-browser-capabilities' --- program/steps/mail/func.inc | 56 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 48 insertions(+), 8 deletions(-) diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index 05d5895..33041d4 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -81,8 +81,8 @@ $OUTPUT->set_env('search_request', $search_request); } - $search_mods = $RCMAIL->config->get('search_mods', $SEARCH_MODS_DEFAULT); - $OUTPUT->set_env('search_mods', $search_mods); + $search_mods = $RCMAIL->config->get('search_mods', $SEARCH_MODS_DEFAULT); + $OUTPUT->set_env('search_mods', $search_mods); } $threading = (bool) $RCMAIL->storage->get_threading(); @@ -114,6 +114,9 @@ $OUTPUT->set_env('drafts_mailbox', $CONFIG['drafts_mbox']); if ($CONFIG['junk_mbox']) $OUTPUT->set_env('junk_mailbox', $CONFIG['junk_mbox']); + + if (!empty($_SESSION['browser_caps'])) + $OUTPUT->set_env('browser_capabilities', $_SESSION['browser_caps']); if (!$OUTPUT->ajax_call) $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash', @@ -1103,12 +1106,7 @@ } // Content-Type: image/*... - if (preg_match('/^image\//i', $attach_prop->mimetype) || - // ...or known file extension: many clients are using application/octet-stream - ($attach_prop->filename && - preg_match('/^application\/octet-stream$/i', $attach_prop->mimetype) && - preg_match('/\.(jpg|jpeg|png|gif|bmp)$/i', $attach_prop->filename)) - ) { + 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), @@ -1126,6 +1124,48 @@ return html::div($attrib, $out); } +function rcmail_part_image_type($part) +{ + $rcmail = rcmail::get_instance(); + + // Skip TIFF images if browser doesn't support this format... + $tiff_support = !empty($_SESSION['browser_caps']) && !empty($_SESSION['browser_caps']['tif']); + // until we can convert them to JPEG + $tiff_support = $tiff_support || $rcmail->config->get('im_convert_path'); + + // Content-type regexp + $mime_regex = $tiff_support ? '/^image\//i' : '/^image\/(?!tif)/i'; + + // Content-Type: image/*... + if (preg_match($mime_regex, $part->mimetype)) { + return $part->mimetype; + } + + // Many clients use application/octet-stream, we'll detect mimetype + // by checking filename extension + + // Supported image filename extensions to image type map + $types = array( + 'jpg' => 'image/jpeg', + 'jpeg' => 'image/jpeg', + 'png' => 'image/png', + 'gif' => 'image/gif', + 'bmp' => 'image/bmp', + ); + if ($tiff_support) { + $types['tif'] = 'image/tiff'; + $types['tiff'] = 'image/tiff'; + } + + if ($part->filename + && preg_match('/^application\/octet-stream$/i', $part->mimetype) + && preg_match('/\.([^.])$/i', $part->filename, $m) + && ($extension = strtolower($m[1])) + && isset($types[$extension]) + ) { + return $types[$extension]; + } +} /** * Convert all relative URLs according to a <base> in HTML -- Gitblit v1.9.1