Move common code to a function

pull/6629/head
Aleksander Machniak 5 years ago
parent 79c1135052
commit 7a4aed8320

@ -609,7 +609,6 @@ function rcmail_message_body($attrib)
$safe_mode = $MESSAGE->is_safe || intval($_GET['_safe']);
$out = '';
$part_no = 0;
$token = $RCMAIL->get_request_token();
$header_attrib = array();
foreach ($attrib as $attr => $value) {
@ -643,13 +642,10 @@ function rcmail_message_body($attrib)
else if (!$part->size) {
continue;
}
// Check if we have enough memory to handle the message in it
// #1487424: we need up to 10x more memory than the body
else if (!rcube_utils::mem_check($part->size * 10)) {
$out .= html::span('part-notice', $RCMAIL->gettext('messagetoobig'). ' '
. html::a('?_task=mail&_action=get&_download=1&_uid='.$MESSAGE->uid.'&_token='.$token.'&_part='.$part->mime_id
.'&_mbox='. urlencode($MESSAGE->folder), $RCMAIL->gettext('download')));
$out .= rcmail_part_too_big_message($MESSAGE, $part->mime_id);
continue;
}
@ -698,9 +694,7 @@ function rcmail_message_body($attrib)
// Check if we have enough memory to handle the message in it
// #1487424: we need up to 10x more memory than the body
if (!rcube_utils::mem_check(strlen($MESSAGE->body) * 10)) {
$out .= html::span('part-notice', $RCMAIL->gettext('messagetoobig'). ' '
. html::a('?_task=mail&_action=get&_download=1&_uid='.$MESSAGE->uid.'&_token='.$token.'&_part=0'
.'&_mbox='. urlencode($MESSAGE->folder), $RCMAIL->gettext('download')));
$out .= rcmail_part_too_big_message($MESSAGE, 0);
}
else {
$plugin = $RCMAIL->plugins->exec_hook('message_body_prefix',
@ -783,3 +777,24 @@ function rcmail_message_body($attrib)
return html::div($attrib, $out);
}
/**
* Returns a HTML notice element for too big message parts
*/
function rcmail_part_too_big_message($MESSAGE, $part_id)
{
global $RCMAIL;
$token = $RCMAIL->get_request_token();
$url = $RCMAIL->url(array(
'task' => 'mail',
'action' => 'get',
'download' => 1,
'uid' => $MESSAGE->uid,
'part' => $part_id,
'mbox' => $MESSAGE->folder,
'token' => $token,
));
return html::div('part-notice', $RCMAIL->gettext('messagetoobig'). ' ' . html::a($url, $RCMAIL->gettext('download')));
}

Loading…
Cancel
Save