diff options
author | Aleksander Machniak <alec@alec.pl> | 2013-11-03 15:05:39 +0100 |
---|---|---|
committer | Aleksander Machniak <alec@alec.pl> | 2013-11-03 15:05:39 +0100 |
commit | e28b12259fb40764ef658710c94f6bb110ba9c92 (patch) | |
tree | c0393096d1f3f4df80ae5b2d02deea1a9434b547 | |
parent | 64cb70284798f6f910e8545c738b8b82027e6bc7 (diff) |
Fix issue where mails with inline images of the same name contained only the first image multiple times (#1489406)
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | program/js/editor.js | 2 | ||||
-rw-r--r-- | program/steps/mail/sendmail.inc | 33 |
3 files changed, 27 insertions, 9 deletions
@@ -1,6 +1,7 @@ CHANGELOG Roundcube Webmail =========================== +- Fix issue where mails with inline images of the same name contained only the first image multiple times (#1489406) - Use left/right arrow keys to collapse/expand thread and spacebar to select a row, change Ctrl key behavior (#1489392) - Fix an issue where using arrow keys to go up a list can result in selected message being under headers (#1489403) - Fix an issue where Home/End keys don't focus list row properly, don't scrollTo properly (#1489396) diff --git a/program/js/editor.js b/program/js/editor.js index b349c9c35..020971d6e 100644 --- a/program/js/editor.js +++ b/program/js/editor.js @@ -162,7 +162,7 @@ function rcmail_editor_images() for (i in files) { att = files[i]; if (att.complete && att.mimetype.startsWith('image/')) { - list.push([att.name, rcmail.env.comm_path+'&_action=display-attachment&_file='+i+'&_id='+rcmail.env.compose_id]); + list.push([att.name, rcmail.env.comm_path+'&_id='+rcmail.env.compose_id+'&_action=display-attachment&_file='+i]); } } diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc index ccb8978be..52b02ecff 100644 --- a/program/steps/mail/sendmail.inc +++ b/program/steps/mail/sendmail.inc @@ -615,22 +615,39 @@ else { } // add stored attachments, if any -if (is_array($COMPOSE['attachments'])) -{ +if (is_array($COMPOSE['attachments'])) { foreach ($COMPOSE['attachments'] as $id => $attachment) { // This hook retrieves the attachment contents from the file storage backend $attachment = $RCMAIL->plugins->exec_hook('attachment_get', $attachment); - $dispurl = '/\ssrc\s*=\s*[\'"]*\S+display-attachment\S+file=rcmfile' . preg_quote($attachment['id']) . '[\s\'"]*/'; - $message_body = $MAIL_MIME->getHTMLBody(); - if ($isHtml && (preg_match($dispurl, $message_body) > 0)) { - $message_body = preg_replace($dispurl, ' src="'.$attachment['name'].'" ', $message_body); + if ($isHtml) { + $dispurl = '/\ssrc\s*=\s*[\'"]*\S+display-attachment\S+file=rcmfile' . preg_quote($attachment['id']) . '[\s\'"]*/'; + $message_body = $MAIL_MIME->getHTMLBody(); + $is_inline = preg_match($dispurl, $message_body); + } + else { + $is_inline = false; + } + + // inline image + if ($is_inline) { + // Mail_Mime does not support many inline attachments with the same name (#1489406) + // we'll generate cid: urls here to workaround this + $cid = preg_replace('/[^0-9a-zA-Z]/', '', uniqid(time(), true)); + if (preg_match('#(@[0-9a-zA-Z\-\.]+)#', $from, $matches)) { + $cid .= $matches[1]; + } else { + $cid .= '@localhost'; + } + + $message_body = preg_replace($dispurl, ' src="cid:' . $cid . '" ', $message_body); + $MAIL_MIME->setHTMLBody($message_body); if ($attachment['data']) - $MAIL_MIME->addHTMLImage($attachment['data'], $attachment['mimetype'], $attachment['name'], false); + $MAIL_MIME->addHTMLImage($attachment['data'], $attachment['mimetype'], $attachment['name'], false, $cid); else - $MAIL_MIME->addHTMLImage($attachment['path'], $attachment['mimetype'], $attachment['name'], true); + $MAIL_MIME->addHTMLImage($attachment['path'], $attachment['mimetype'], $attachment['name'], true, $cid); } else { $ctype = str_replace('image/pjpeg', 'image/jpeg', $attachment['mimetype']); // #1484914 |