diff options
author | Aleksander Machniak <alec@alec.pl> | 2012-05-30 12:17:26 +0200 |
---|---|---|
committer | Aleksander Machniak <alec@alec.pl> | 2012-05-30 12:17:26 +0200 |
commit | d487cd5a6c3e6a7eaa125957a022495ba038b460 (patch) | |
tree | 14e4f4ffccd4ccf2e41a4a9ce42fd20812a3222f /program/steps/mail | |
parent | ca1c2a8c9c69ddf92cfd07a9e5ff4ec1deb22b6b (diff) | |
parent | 19cc5b91c963736fd06dd701d4a583ccdf4b5bfa (diff) |
Merge branch 'dev-browser-capabilities'
Conflicts:
CHANGELOG
Diffstat (limited to 'program/steps/mail')
-rw-r--r-- | program/steps/mail/func.inc | 56 | ||||
-rw-r--r-- | program/steps/mail/get.inc | 40 | ||||
-rw-r--r-- | program/steps/mail/show.inc | 31 |
3 files changed, 115 insertions, 12 deletions
diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index 05d589503..33041d43d 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -81,8 +81,8 @@ if (empty($RCMAIL->action) || $RCMAIL->action == 'list') { $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(); @@ -115,6 +115,9 @@ if (empty($RCMAIL->action) || $RCMAIL->action == 'list') { 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', 'movingmessage', 'copyingmessage', 'deletingmessage', 'markingmessage', @@ -1103,12 +1106,7 @@ function rcmail_message_body($attrib) } // 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 @@ function rcmail_message_body($attrib) 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 diff --git a/program/steps/mail/get.inc b/program/steps/mail/get.inc index 750011f74..658538a20 100644 --- a/program/steps/mail/get.inc +++ b/program/steps/mail/get.inc @@ -22,7 +22,7 @@ // show loading page if (!empty($_GET['_preload'])) { - $url = preg_replace('/[&?]+_preload=1/', '', $_SERVER['REQUEST_URI']); + $url = preg_replace('/([&?]+)_preload=/', '\\1_embed=', $_SERVER['REQUEST_URI']); $message = rcube_label('loadingdata'); header('Content-Type: text/html; charset=' . RCMAIL_CHARSET); @@ -76,6 +76,17 @@ else if (strlen($pid = get_input_value('_part', RCUBE_INPUT_GET))) { // overwrite modified vars from plugin $mimetype = $plugin['mimetype']; + + // TIFF to JPEG conversion, if needed + $tiff_support = !empty($_SESSION['browser_caps']) && !empty($_SESSION['browser_caps']['tif']); + if (!empty($_REQUEST['_embed']) && !$tiff_support + && $RCMAIL->config->get('im_convert_path') + && rcmail_part_image_type($part) == 'image/tiff' + ) { + $tiff2jpeg = true; + $mimetype = 'image/jpeg'; + } + list($ctype_primary, $ctype_secondary) = explode('/', $mimetype); if ($plugin['body']) $part->body = $plugin['body']; @@ -150,8 +161,33 @@ else if (strlen($pid = get_input_value('_part', RCUBE_INPUT_GET))) { header("Content-Disposition: $disposition; filename=\"$filename\""); + // handle tiff to jpeg conversion + if (!empty($tiff2jpeg)) { + $temp_dir = unslashify($RCMAIL->config->get('temp_dir')); + $file_path = tempnam($temp_dir, 'rcmAttmnt'); + + // write content to temp file + if ($part->body) { + $saved = file_put_contents($file_path, $part->body); + } + else if ($part->size) { + $fd = fopen($file_path, 'w'); + $saved = $RCMAIL->storage->get_message_part($MESSAGE->uid, $part->mime_id, $part, false, $fd); + fclose($fd); + } + + // convert image to jpeg and send it to the browser + if ($saved) { + $image = new rcube_image($file_path); + if ($image->convert(rcube_image::TYPE_JPG, $file_path)) { + header("Content-Length: " . filesize($file_path)); + readfile($file_path); + } + unlink($file_path); + } + } // do content filtering to avoid XSS through fake images - if (!empty($_REQUEST['_embed']) && $browser->ie && $browser->ver <= 8) { + else if (!empty($_REQUEST['_embed']) && $browser->ie && $browser->ver <= 8) { if ($part->body) { echo preg_match('/<(script|iframe|object)/i', $part->body) ? '' : $part->body; $sent = true; diff --git a/program/steps/mail/show.inc b/program/steps/mail/show.inc index 2d4d8e5a5..158ba31c8 100644 --- a/program/steps/mail/show.inc +++ b/program/steps/mail/show.inc @@ -21,6 +21,16 @@ $PRINT_MODE = $RCMAIL->action=='print' ? TRUE : FALSE; +// Read browser capabilities and store them in session +if ($caps = get_input_value('_caps', RCUBE_INPUT_GET)) { + $browser_caps = array(); + foreach (explode(',', $caps) as $cap) { + $cap = explode('=', $cap); + $browser_caps[$cap[0]] = $cap[1]; + } + $_SESSION['browser_caps'] = $browser_caps; +} + // similar code as in program/steps/mail/get.inc if ($uid = get_input_value('_uid', RCUBE_INPUT_GET)) { $MESSAGE = new rcube_message($uid); @@ -51,8 +61,25 @@ if ($uid = get_input_value('_uid', RCUBE_INPUT_GET)) { $OUTPUT->set_env('mailbox', $mbox_name); // mimetypes supported by the browser (default settings) - $mimetypes = $RCMAIL->config->get('client_mimetypes', 'text/plain,text/html,text/xml,image/jpeg,image/gif,image/png,application/x-javascript,application/pdf,application/x-shockwave-flash'); - $OUTPUT->set_env('mimetypes', is_string($mimetypes) ? explode(',', $mimetypes) : (array)$mimetypes); + $mimetypes = $RCMAIL->config->get('client_mimetypes', 'text/plain,text/html,text/xml,image/jpeg,image/gif,image/png,image/bmp,image/tiff,application/x-javascript,application/pdf,application/x-shockwave-flash'); + $mimetypes = is_string($mimetypes) ? explode(',', $mimetypes) : (array)$mimetypes; + + // Remove unsupported types, which makes that attachment which cannot be + // displayed in a browser will be downloaded directly without displaying an overlay page + if (empty($_SESSION['browser_caps']['pdf']) && ($key = array_search('application/pdf', $mimetypes)) !== false) { + unset($mimetypes[$key]); + } + if (empty($_SESSION['browser_caps']['flash']) && ($key = array_search('application/x-shockwave-flash', $mimetypes)) !== false) { + unset($mimetypes[$key]); + } + if (empty($_SESSION['browser_caps']['tif']) && ($key = array_search('image/tiff', $mimetypes)) !== false) { + // we can convert tiff to jpeg + if (!$RCMAIL->config->get('im_convert_path')) { + unset($mimetypes[$key]); + } + } + + $OUTPUT->set_env('mimetypes', $mimetypes); if ($CONFIG['drafts_mbox']) $OUTPUT->set_env('drafts_mailbox', $CONFIG['drafts_mbox']); |