Aleksander Machniak
2013-12-25 c97625e02a95ebd995af8a06c27229581a071ddd
program/steps/mail/get.inc
@@ -5,7 +5,7 @@
 | program/steps/mail/get.inc                                            |
 |                                                                       |
 | This file is part of the Roundcube Webmail client                     |
 | Copyright (C) 2005-2011, The Roundcube Dev Team                       |
 | Copyright (C) 2005-2013, The Roundcube Dev Team                       |
 |                                                                       |
 | Licensed under the GNU General Public License version 3 or            |
 | any later version with exceptions for skins & plugins.                |
@@ -113,19 +113,25 @@
    $mimetype = rcmail_fix_mimetype($part->mimetype);
    // allow post-processing of the message body
    $plugin = $RCMAIL->plugins->exec_hook('message_part_get',
      array('uid' => $MESSAGE->uid, 'id' => $part->mime_id, 'mimetype' => $mimetype, 'part' => $part, 'download' => !empty($_GET['_download'])));
        $plugin = $RCMAIL->plugins->exec_hook('message_part_get', array(
            'uid'      => $MESSAGE->uid,
            'id'       => $part->mime_id,
            'mimetype' => $mimetype,
            'part'     => $part,
            'download' => !empty($_GET['_download'])
        ));
    if ($plugin['abort'])
        if ($plugin['abort']) {
      exit;
        }
    // overwrite modified vars from plugin
    $mimetype   = $plugin['mimetype'];
    $extensions = rcube_mime::get_mime_extensions($mimetype);
    if ($plugin['body'])
        if ($plugin['body']) {
      $part->body = $plugin['body'];
        }
    // compare file mimetype with the stated content-type headers and file extension to avoid malicious operations
    if (!empty($_REQUEST['_embed']) && empty($_REQUEST['_nocheck'])) {
@@ -148,24 +154,28 @@
        list($real_ctype_primary, $real_ctype_secondary) = explode('/', $real_mimetype);
        // accept text/plain with any extension
        if ($real_mimetype == 'text/plain' && $real_mimetype == $mimetype)
                if ($real_mimetype == 'text/plain' && $real_mimetype == $mimetype) {
          $file_extension = 'txt';
                }
        // ignore differences in text/* mimetypes. Filetype detection isn't very reliable here
        if ($real_ctype_primary == 'text' && strpos($mimetype, $real_ctype_primary) === 0)
                if ($real_ctype_primary == 'text' && strpos($mimetype, $real_ctype_primary) === 0) {
          $real_mimetype = $mimetype;
                }
        // get valid file extensions
        $extensions = rcube_mime::get_mime_extensions($real_mimetype);
        $valid_extension = (!$file_extension || in_array($file_extension, (array)$extensions));
        // ignore filename extension if mimeclass matches (#1489029)
        if (!empty($_REQUEST['_mimeclass']) && $real_ctype_primary == $_REQUEST['_mimeclass'])
                if (!empty($_REQUEST['_mimeclass']) && $real_ctype_primary == $_REQUEST['_mimeclass']) {
          $valid_extension = true;
                }
        // fix mimetype for images wrongly declared as octet-stream
        if ($mimetype == 'application/octet-stream' && strpos($real_mimetype, 'image/') === 0 && $valid_extension)
                if ($mimetype == 'application/octet-stream' && strpos($real_mimetype, 'image/') === 0 && $valid_extension) {
          $mimetype = $real_mimetype;
                }
        $valid = ($real_mimetype == $mimetype && $valid_extension);
      }
@@ -193,14 +203,16 @@
                  'expected' => $mimetype . ($file_extension ? " (.$file_extension)" : ''),
                  'detected' => $real_mimetype . ($extensions[0] ? " (.$extensions[0])" : ''),
                )
              )) .
              html::p(array('class' => 'rcmail-inline-buttons'),
                html::tag('button',
                  array('onclick' => "location.href='" . $RCMAIL->url(array_merge($_GET, array('_nocheck' => 1))) . "'"),
                  $RCMAIL->gettext('showanyway')))
                            ))
                            . html::p(array('class' => 'rcmail-inline-buttons'),
                                html::tag('button', array(
                                    'onclick' => "location.href='" . $RCMAIL->url(array_merge($_GET, array('_nocheck' => 1))) . "'"
                                ),
                                $RCMAIL->gettext('showanyway'))
              )
          )));
                        ))));
        }
        exit;
      }
    }
@@ -239,8 +251,9 @@
      }
      else {
        // get part body if not available
        if (!$part->body)
                if (!$part->body) {
          $part->body = $MESSAGE->get_part_content($part->mime_id);
                }
        // show images?
        rcmail_check_safe($MESSAGE);
@@ -254,14 +267,15 @@
          if ($body_pos = strpos($out, '<body')) {
            $body_start = strpos($out, '>', $body_pos) + 1;
          }
          $out = substr($out, 0, $body_start) .
            html::div(array('class' => 'rcmail-inline-message rcmail-inline-warning'),
                    $out = substr($out, 0, $body_start)
                        . html::div(array('class' => 'rcmail-inline-message rcmail-inline-warning'),
              rcube::Q($RCMAIL->gettext('blockedimages')) . '&nbsp;' .
              html::tag('button',
                array('onclick' => "location.href='" . $RCMAIL->url(array_merge($_GET, array('_safe' => 1))) . "'"),
                rcube::Q($RCMAIL->gettext('showimages')))
            ) .
            substr($out, $body_start);
                        )
                        . substr($out, $body_start);
        }
      }
@@ -366,7 +380,6 @@
    exit;
  }
}
// print message
else {
  // send correct headers for content type