From e69d1e7f0474e1055203b2274a3ba266a4c05f65 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Thu, 10 Jan 2019 14:20:11 +0100 Subject: [PATCH] Fix so max_message_size limit is checked also when forwarding messages as attachments (#6580) --- CHANGELOG | 1 + program/include/rcmail_output_html.php | 2 +- program/localization/en_US/messages.inc | 1 + program/steps/mail/compose.inc | 26 +++++++++++++++++++++---- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 3e319595a..6d7a6a513 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -40,6 +40,7 @@ CHANGELOG Roundcube Webmail - Elastic: Fix unwanted thread expanding when selecting a collapsed thread in non-mobile mode (#6445) - Elastic: Add "status bar" for mobile in mail composer - Log errors caused by low pcre.backtrack_limit when sending a mail message (#6433) +- Fix so max_message_size limit is checked also when forwarding messages as attachments (#6580) - Fix so performance stats are logged to the main console log also when per_user_logging=true - Fix malformed message saved into Sent folder when using big attachments and low memory limit (#6498) - Fix incorrect IMAP SASL GSSAPI negotiation (#6308) diff --git a/program/include/rcmail_output_html.php b/program/include/rcmail_output_html.php index 761d2755e..c35ff54ae 100644 --- a/program/include/rcmail_output_html.php +++ b/program/include/rcmail_output_html.php @@ -1706,7 +1706,7 @@ EOF; * Add inline javascript code * * @param string $script JS code snippet - * @param string $position Target position [head|head_top|foot] + * @param string $position Target position [head|head_top|foot|docready] */ public function add_script($script, $position = 'head') { diff --git a/program/localization/en_US/messages.inc b/program/localization/en_US/messages.inc index 441bfa137..7b3356354 100644 --- a/program/localization/en_US/messages.inc +++ b/program/localization/en_US/messages.inc @@ -129,6 +129,7 @@ $messages['fileuploaderror'] = 'File upload failed.'; $messages['filesizeerror'] = 'The uploaded file exceeds the maximum size of $size.'; $messages['filecounterror'] = 'You can upload maximum $count files at once.'; $messages['msgsizeerror'] = 'Failed to attach a file. Maximum size of a message ($size) exceeded.'; +$messages['msgsizeerrorfwd'] = 'Maximum size of a message ($size) exceeded. $num message(s) have not been attached.'; $messages['copysuccess'] = 'Successfully copied $nr contacts.'; $messages['movesuccess'] = 'Successfully moved $nr contacts.'; $messages['copyerror'] = 'Could not copy any contacts.'; diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc index b00936d6e..6ae288aa7 100644 --- a/program/steps/mail/compose.inc +++ b/program/steps/mail/compose.inc @@ -1033,17 +1033,21 @@ function rcmail_write_forward_attachments() { global $RCMAIL, $COMPOSE, $MESSAGE; - $storage = $RCMAIL->get_storage(); - $names = array(); - $refs = array(); - if ($MESSAGE->pgp_mime) { return; } + $storage = $RCMAIL->get_storage(); + $names = array(); + $refs = array(); + $size_errors = 0; + $size_limit = parse_bytes($RCMAIL->config->get('max_message_size')); + $total_size = 10 * 1024; // size of message body, to start with + $loaded_attachments = array(); foreach ((array)$COMPOSE['attachments'] as $attachment) { $loaded_attachments[$attachment['name'] . $attachment['mimetype']] = $attachment; + $total_size += $attachment['size']; } if ($COMPOSE['forward_uid'] == '*') { @@ -1085,6 +1089,13 @@ function rcmail_write_forward_attachments() continue; } + if ($size_limit && $size_limit < $total_size + $message->headers->size) { + $size_errors++; + continue; + } + + $total_size += $message->headers->size; + rcmail_save_attachment($message, null, $COMPOSE['id'], array('filename' => $name)); if ($message->headers->messageID) { @@ -1096,9 +1107,16 @@ function rcmail_write_forward_attachments() if (count($refs) == 1) { $COMPOSE['reply_msgid'] = $refs[0]; } + if (!empty($refs)) { $COMPOSE['references'] = implode(' ', $refs); } + + if ($size_errors) { + $limit = $RCMAIL->show_bytes($size_limit); + $error = $RCMAIL->gettext(array('name' => 'msgsizeerrorfwd', 'vars' => array('num' => $size_errors, 'size' => $limit))); + $RCMAIL->output->add_script(sprintf("%s.display_message('%s', 'error');", rcmail_output::JS_OBJECT_NAME, rcube::JQ($error)), 'docready'); + } } // Saves an image as attachment