Fix bug where original attachments with Content-Id were attached to the message on reply (#7122)

All Content-Disposition:inline parts that aren't used in the body are ignored on reply/forward/edit.
bnet/additions
Aleksander Machniak 5 years ago
parent 0c8b71059b
commit 88660cd465

@ -27,6 +27,7 @@ RELEASE 1.4.3
- Fix invalid Content-Transfer-Encoding on multipart messages - Mail_Mime fix (#7170) - Fix invalid Content-Transfer-Encoding on multipart messages - Mail_Mime fix (#7170)
- Fix regression where using an absolute path to SQLite database file on Windows didn't work (#7196) - Fix regression where using an absolute path to SQLite database file on Windows didn't work (#7196)
- Fix using unix:///path/to/socket.file in memcached driver (#7210) - Fix using unix:///path/to/socket.file in memcached driver (#7210)
- Fix bug where attachments with Content-Id were attached to the message on reply (#7122)
RELEASE 1.4.2 RELEASE 1.4.2
------------- -------------

@ -520,13 +520,11 @@ function rcmail_prepare_message_body()
$isHtml = rcmail_compose_editor_mode(); $isHtml = rcmail_compose_editor_mode();
$messages = array(); $messages = array();
// save inline images to files (before HTML body washing) // Create a (fake) image attachments map. We need it before we handle
if ($COMPOSE['mode'] == rcmail_sendmail::MODE_REPLY) { // the message body. After that we'll go throughout the list and check
rcmail_write_inline_attachments($MESSAGE); // which images were used in the body and attach them for real or skip.
} if ($isHtml) {
// save attachments to files (before HTML body washing) $CID_MAP = rcmail_cid_map($MESSAGE);
else {
rcmail_write_compose_attachments($MESSAGE, $isHtml);
} }
// set is_safe flag (before HTML body washing) // set is_safe flag (before HTML body washing)
@ -595,6 +593,10 @@ function rcmail_prepare_message_body()
else if ($COMPOSE['mode'] == rcmail_sendmail::MODE_DRAFT || $COMPOSE['mode'] == rcmail_sendmail::MODE_EDIT) { else if ($COMPOSE['mode'] == rcmail_sendmail::MODE_DRAFT || $COMPOSE['mode'] == rcmail_sendmail::MODE_EDIT) {
$body = rcmail_create_draft_body($body, $isHtml); $body = rcmail_create_draft_body($body, $isHtml);
} }
// Save forwarded files (or inline images) as attachments
// This will also update inline images location in the body
rcmail_write_compose_attachments($MESSAGE, $isHtml, $body);
} }
// new message // new message
else { else {
@ -936,12 +938,12 @@ function rcmail_remove_signature($body)
return $body; return $body;
} }
function rcmail_write_compose_attachments(&$message, $bodyIsHtml) function rcmail_write_compose_attachments(&$message, $bodyIsHtml, &$message_body)
{ {
global $RCMAIL, $COMPOSE, $CID_MAP; global $RCMAIL, $COMPOSE, $CID_MAP;
if ($message->pgp_mime || !empty($COMPOSE['forward_attachments'])) { if ($message->pgp_mime || !empty($COMPOSE['forward_attachments'])) {
return $CID_MAP; return;
} }
$messages = array(); $messages = array();
@ -967,11 +969,6 @@ function rcmail_write_compose_attachments(&$message, $bodyIsHtml)
continue; continue;
} }
// skip inline images when forwarding in text mode
if ($part->content_id && $part->disposition == 'inline' && !$bodyIsHtml && $COMPOSE['mode'] == rcmail_sendmail::MODE_FORWARD) {
continue;
}
// skip version.txt parts of multipart/encrypted messages // skip version.txt parts of multipart/encrypted messages
if ($message->pgp_mime && $part->mimetype == 'application/pgp-encrypted' && $part->filename == 'version.txt') { if ($message->pgp_mime && $part->mimetype == 'application/pgp-encrypted' && $part->filename == 'version.txt') {
continue; continue;
@ -984,43 +981,60 @@ function rcmail_write_compose_attachments(&$message, $bodyIsHtml)
} }
} }
$replace = null;
// skip inline images when not used in the body
if ($part->disposition == 'inline') {
if (!$bodyIsHtml) {
continue;
}
$idx = $part->content_id ? ('cid:' . $part->content_id) : $part->content_location;
if ($idx && isset($CID_MAP[$idx]) && strpos($message_body, $CID_MAP[$idx]) !== false) {
$replace = $CID_MAP[$idx];
}
else {
continue;
}
}
// skip any other attachment on Reply
else if ($COMPOSE['mode'] == rcmail_sendmail::MODE_REPLY) {
continue;
}
if (($attachment = $loaded_attachments[rcmail_attachment_name($part) . $part->mimetype]) if (($attachment = $loaded_attachments[rcmail_attachment_name($part) . $part->mimetype])
|| ($attachment = rcmail_save_attachment($message, $pid, $COMPOSE['id'])) || ($attachment = rcmail_save_attachment($message, $pid, $COMPOSE['id']))
) { ) {
if ($bodyIsHtml && ($part->content_id || $part->content_location)) { if ($replace) {
$url = sprintf('%s&_id=%s&_action=display-attachment&_file=rcmfile%s', $url = sprintf('%s&_id=%s&_action=display-attachment&_file=rcmfile%s',
$RCMAIL->comm_path, $COMPOSE['id'], $attachment['id']); $RCMAIL->comm_path, $COMPOSE['id'], $attachment['id']);
if ($part->content_id) $message_body = str_replace($replace, $url, $message_body);
$CID_MAP['cid:'.$part->content_id] = $url;
else
$CID_MAP[$part->content_location] = $url;
} }
} }
} }
} }
$COMPOSE['forward_attachments'] = true; $COMPOSE['forward_attachments'] = true;
return $CID_MAP;
} }
function rcmail_write_inline_attachments(&$message) // Create a map of attachment content-id/content-locations
function rcmail_cid_map($message)
{ {
global $RCMAIL, $COMPOSE, $CID_MAP;
if ($message->pgp_mime) { if ($message->pgp_mime) {
return $CID_MAP; return array();
} }
$messages = array(); $messages = array();
$map = array();
foreach ((array) $message->mime_parts() as $pid => $part) { foreach ((array) $message->mime_parts() as $pid => $part) {
if ($part->mimetype == 'message/rfc822') { if ($part->mimetype == 'message/rfc822') {
$messages[] = $part->mime_id; $messages[] = $part->mime_id;
} }
if (($part->content_id || $part->content_location) && $part->filename) { if ($part->content_id || $part->content_location) {
// skip attachments included in message/rfc822 attachment (#1486487, #1490607) // skip attachments included in message/rfc822 attachment (#1486487, #1490607)
foreach ($messages as $mimeid) { foreach ($messages as $mimeid) {
if (strpos($part->mime_id, $mimeid . '.') === 0) { if (strpos($part->mime_id, $mimeid . '.') === 0) {
@ -1028,19 +1042,14 @@ function rcmail_write_inline_attachments(&$message)
} }
} }
if ($attachment = rcmail_save_attachment($message, $pid, $COMPOSE['id'])) { $url = sprintf('RCMAP%s', md5($message->folder . '/' . $message->uid));
$url = sprintf('%s&_id=%s&_action=display-attachment&_file=rcmfile%s', $idx = $part->content_id ? ('cid:' . $part->content_id) : $part->content_location;
$RCMAIL->comm_path, $COMPOSE['id'], $attachment['id']);
if ($part->content_id) $map[$idx] = $url;
$CID_MAP['cid:'.$part->content_id] = $url;
else
$CID_MAP[$part->content_location] = $url;
}
} }
} }
return $CID_MAP; return $map;
} }
// Creates attachment(s) from the forwarded message(s) // Creates attachment(s) from the forwarded message(s)

Loading…
Cancel
Save