Browse Source

Don't list images attached to multipart/related part as attachments (#7184)

pull/8150/merge
Aleksander Machniak 3 years ago
parent
commit
a2aa107f1a
  1. 1
      CHANGELOG.md
  2. 7
      program/actions/mail/index.php
  3. 79
      program/actions/mail/show.php

1
CHANGELOG.md

@ -5,6 +5,7 @@
- Update to jQuery-UI 1.13.1 (#8455)
- Use navigator.pdfViewerEnabled for PDF viewer detection
- Remove use of unreliable charset detection (#8344)
- Don't list images attached to multipart/related part as attachments (#7184)
- Password: Add support for ssha256 algorithm (#8459)
- Fix slow loading of long HTML content into the HTML editor (#8108)
- Fix bug where SMTP password didn't work if it contained '%p' (#8435)

7
program/actions/mail/index.php

@ -1113,6 +1113,13 @@ class rcmail_action_mail_index extends rcmail_action
return $out;
}
/**
* Detect if a message attachment is an image (that can be displayed in the browser).
*
* @param rcube_message_part $part Message part - attachment
*
* @return string|null Image MIME type
*/
public static function part_image_type($part)
{
$mimetype = strtolower($part->mimetype);

79
program/actions/mail/show.php

@ -176,6 +176,13 @@ class rcmail_action_mail_show extends rcmail_action_mail_index
exit;
}
/**
* Handler for the template object 'messageattachments'.
*
* @param array $attrib Named parameters
*
* @return string HTML content showing the message attachments list
*/
public static function message_attachments($attrib)
{
if (empty(self::$MESSAGE->attachments)) {
@ -198,6 +205,11 @@ class rcmail_action_mail_show extends rcmail_action_mail_index
$mimetype = $type;
}
// Skip inline images
if (strpos($mimetype, 'image/') === 0 && !self::is_attachment(self::$MESSAGE, $attach_prop)) {
continue;
}
if (!empty($attrib['maxlength']) && mb_strlen($filename) > $attrib['maxlength']) {
$title = $filename;
$filename = abbreviate_string($filename, $attrib['maxlength']);
@ -329,6 +341,14 @@ class rcmail_action_mail_show extends rcmail_action_mail_index
return html::div($attrib, $msg);
}
/**
* Handler for the template object 'messageobjects' that contains
* warning/info boxes, buttons, etc. related to the displayed message.
*
* @param array $attrib Named parameters
*
* @return string HTML content showing the message objects
*/
public static function message_objects($attrib)
{
if (empty($attrib['id'])) {
@ -350,6 +370,13 @@ class rcmail_action_mail_show extends rcmail_action_mail_index
return html::div($attrib, $content);
}
/**
* Handler for the template object 'contactphoto'.
*
* @param array $attrib Named parameters
*
* @return string HTML content for the IMG tag
*/
public static function message_contactphoto($attrib)
{
$rcmail = rcmail::get_instance();
@ -755,13 +782,13 @@ class rcmail_action_mail_show extends rcmail_action_mail_index
$download_label = rcube::Q($rcmail->gettext('download'));
foreach (self::$MESSAGE->attachments as $attach_prop) {
// skip inline images
if (!empty($attach_prop->content_id) && $attach_prop->disposition == 'inline') {
continue;
}
// Content-Type: image/*...
if ($mimetype = self::part_image_type($attach_prop)) {
// Skip inline images
if (!self::is_attachment(self::$MESSAGE, $attach_prop)) {
continue;
}
// display thumbnails
if ($thumbnail_size) {
$supported = in_array($mimetype, self::$CLIENT_MIMETYPES);
@ -824,8 +851,13 @@ class rcmail_action_mail_show extends rcmail_action_mail_index
/**
* Returns a HTML notice element for too big message parts
*
* @param rcube_message $message Email message object
* @param string $part_id Message part identifier
*
* @return string HTML content
*/
public static function part_too_big_message($MESSAGE, $part_id)
public static function part_too_big_message($message, $part_id)
{
$rcmail = rcmail::get_instance();
$token = $rcmail->get_request_token();
@ -833,17 +865,20 @@ class rcmail_action_mail_show extends rcmail_action_mail_index
'task' => 'mail',
'action' => 'get',
'download' => 1,
'uid' => $MESSAGE->uid,
'uid' => $message->uid,
'part' => $part_id,
'mbox' => $MESSAGE->folder,
'mbox' => $message->folder,
'token' => $token,
]);
return html::span('part-notice', $rcmail->gettext('messagetoobig') . ' ' . html::a($url, $rcmail->gettext('download')));
return html::span('part-notice', $rcmail->gettext('messagetoobig')
. ' ' . html::a($url, $rcmail->gettext('download')));
}
/**
* Handle disposition notification requests
*
* @param rcube_message $message Email message object
*/
public static function mdn_request_handler($message)
{
@ -899,4 +934,30 @@ class rcmail_action_mail_show extends rcmail_action_mail_index
}
}
}
/**
* Check whether the message part is a normal attachment
*
* @param rcube_message $message Message object
* @param rcube_message_part $part Message part
*
* @return bool
*/
protected static function is_attachment($message, $part)
{
// Inline attachment with Content-Id specified
if (!empty($part->content_id) && $part->disposition == 'inline') {
return false;
}
// Any image attached to multipart/related message (#7184)
$parent_id = preg_replace('/\.[0-9]+$/', '', $part->mime_id);
$parent = $message->mime_parts[$parent_id] ?? null;
if ($parent && $parent->mimetype == 'multipart/related') {
return false;
}
return true;
}
}
Loading…
Cancel
Save