Changeset 5490 in subversion


Ignore:
Timestamp:
Nov 25, 2011 8:47:07 AM (19 months ago)
Author:
alec
Message:
  • Prevent from memory_limit exceeding when trying to parse big messages bodies (#1487424): don't try to parse it, display notice with a link to download it directly
Location:
trunk/roundcubemail
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/CHANGELOG

    r5485 r5490  
    22=========================== 
    33 
     4- Prevent from memory_limit exceeding when trying to parse big messages bodies (#1487424) 
    45- Add possibility to add SASL mechanisms for SMTP in smtp_connect hook (#1487937) 
    56- Mark (with different color) folders with recent messages (#1486234) 
  • trunk/roundcubemail/program/include/main.inc

    r5473 r5490  
    18471847 
    18481848/** 
     1849 * Check if we can process not exceeding memory_limit 
     1850 * 
     1851 * @param integer Required amount of memory 
     1852 * @return boolean 
     1853 */ 
     1854function rcmail_mem_check($need) 
     1855{ 
     1856  $mem_limit = parse_bytes(ini_get('memory_limit')); 
     1857  $memory    = function_exists('memory_get_usage') ? memory_get_usage() : 16*1024*1024; // safe value: 16MB 
     1858 
     1859  return $mem_limit && $memory + $need > $mem_limit ? false : true; 
     1860} 
     1861 
     1862 
     1863/** 
    18491864 * Check if working in SSL mode 
    18501865 * 
  • trunk/roundcubemail/program/localization/en_US/labels.inc

    r5457 r5490  
    153153$labels['invert'] = 'Invert'; 
    154154$labels['filter'] = 'Filter'; 
    155  
    156155$labels['list'] = 'List'; 
    157156$labels['threads'] = 'Threads'; 
  • trunk/roundcubemail/program/localization/en_US/messages.inc

    r5319 r5490  
    158158$messages['mispellingsfound'] = 'Spelling errors detected in the message.'; 
    159159$messages['parentnotwritable'] = 'Unable to create/move folder into selected parent folder. No access rights.'; 
     160$messages['messagetoobig'] = 'The message part is too big to process it.'; 
    160161 
    161162?> 
  • trunk/roundcubemail/program/steps/mail/func.inc

    r5486 r5490  
    973973 */ 
    974974function rcmail_message_body($attrib) 
    975   { 
     975{ 
    976976  global $CONFIG, $OUTPUT, $MESSAGE, $IMAP, $RCMAIL, $REMOTE_OBJECTS; 
    977977 
     
    990990      $header_attrib[$regs[1]] = $value; 
    991991 
    992   if (!empty($MESSAGE->parts)) 
    993     { 
    994     foreach ($MESSAGE->parts as $i => $part) 
    995       { 
     992  if (!empty($MESSAGE->parts)) { 
     993    foreach ($MESSAGE->parts as $i => $part) { 
    996994      if ($part->type == 'headers') 
    997995        $out .= rcmail_message_headers(sizeof($header_attrib) ? $header_attrib : NULL, $part->headers); 
    998       else if ($part->type == 'content' && $part->size) 
    999         { 
     996      else if ($part->type == 'content' && $part->size) { 
     997        // Check if we have enough memory to handle the message in it 
     998        // #1487424: we need up to 10x more memory than the body 
     999        if (!rcmail_mem_check($part->size * 10)) { 
     1000          $out .= html::span('part-notice', rcube_label('messagetoobig'). ' ' 
     1001            . html::a('?_task=mail&_action=get&_download=1&_uid='.$MESSAGE->uid.'&_part='.$part->mime_id 
     1002              .'&_mbox='. urlencode($IMAP->get_mailbox_name()), rcube_label('download'))); 
     1003          continue; 
     1004        } 
     1005 
    10001006        if (empty($part->ctype_parameters) || empty($part->ctype_parameters['charset'])) 
    10011007          $part->ctype_parameters['charset'] = $MESSAGE->headers->charset; 
     
    10311037        else 
    10321038          $out .= html::div('message-part', $plugin['prefix'] . $body); 
    1033         } 
    10341039      } 
    10351040    } 
     1041  } 
    10361042  else { 
    1037     $plugin = $RCMAIL->plugins->exec_hook('message_body_prefix', array( 
    1038       'part' => $MESSAGE, 'prefix' => '')); 
    1039  
    1040     $out .= html::div('message-part', $plugin['prefix'] . html::tag('pre', array(), 
    1041       rcmail_plain_body(Q($MESSAGE->body, 'strict', false)))); 
    1042     } 
     1043    // Check if we have enough memory to handle the message in it 
     1044    // #1487424: we need up to 10x more memory than the body 
     1045    if (!rcmail_mem_check(strlen($MESSAGE->body) * 10)) { 
     1046      $out .= html::span('part-notice', rcube_label('messagetoobig'). ' ' 
     1047        . html::a('?_task=mail&_action=get&_download=1&_uid='.$MESSAGE->uid.'&_part=0' 
     1048          .'&_mbox='. urlencode($IMAP->get_mailbox_name()), rcube_label('download'))); 
     1049    } 
     1050    else { 
     1051      $plugin = $RCMAIL->plugins->exec_hook('message_body_prefix', array( 
     1052        'part' => $MESSAGE, 'prefix' => '')); 
     1053 
     1054      $out .= html::div('message-part', $plugin['prefix'] . html::tag('pre', array(), 
     1055        rcmail_plain_body(Q($MESSAGE->body, 'strict', false)))); 
     1056    } 
     1057  } 
    10431058 
    10441059  // list images after mail body 
     
    10581073            'alt' => $attach_prop->filename, 
    10591074          ))); 
    1060         } 
     1075      } 
    10611076    } 
    10621077  } 
     
    10671082 
    10681083  return html::div($attrib, $out); 
    1069   } 
     1084} 
    10701085 
    10711086 
  • trunk/roundcubemail/program/steps/mail/get.inc

    r5479 r5490  
    7171} 
    7272 
    73 else if ($pid = get_input_value('_part', RCUBE_INPUT_GET)) { 
     73else if (strlen($pid = get_input_value('_part', RCUBE_INPUT_GET))) { 
    7474 
    7575  if ($part = $MESSAGE->mime_parts[$pid]) { 
     
    110110    // deliver part content 
    111111    if ($ctype_primary == 'text' && $ctype_secondary == 'html' && empty($plugin['download'])) { 
    112       // get part body if not available 
    113       if (!$part->body) 
    114         $part->body = $MESSAGE->get_part_content($part->mime_id); 
     112      // Check if we have enough memory to handle the message in it 
     113      // #1487424: we need up to 10x more memory than the body 
     114      if (!rcmail_mem_check($part->size * 10)) { 
     115        $out = '<body>' . rcube_label('messagetoobig'). ' ' 
     116          . html::a('?_task=mail&_action=get&_download=1&_uid='.$MESSAGE->uid.'&_part='.$part->mime_id 
     117            .'&_mbox='. urlencode($IMAP->get_mailbox_name()), rcube_label('download')) . '</body></html>'; 
     118      } 
     119      else { 
     120        // get part body if not available 
     121        if (!$part->body) 
     122          $part->body = $MESSAGE->get_part_content($part->mime_id); 
     123 
     124        $out = rcmail_print_body($part, array('safe' => $MESSAGE->is_safe, 'inline_html' => false)); 
     125      } 
    115126 
    116127      $OUTPUT = new rcube_html_page(); 
    117       $OUTPUT->write(rcmail_print_body($part, array('safe' => $MESSAGE->is_safe, 'inline_html' => false))); 
     128      $OUTPUT->write($out); 
    118129    } 
    119130    else { 
     
    121132      @set_time_limit(0); 
    122133 
    123       $filename = $part->filename ? $part->filename : ($MESSAGE->subject ? $MESSAGE->subject : 'roundcube') . '.'.$ctype_secondary; 
     134      $ext      = '.' . ($mimetype == 'text/plain' ? 'txt' : $ctype_secondary); 
     135      $filename = $part->filename ? $part->filename : ($MESSAGE->subject ? $MESSAGE->subject : 'roundcube') . $ext; 
    124136      $filename = preg_replace('[\r\n]', '', $filename); 
    125137 
  • trunk/roundcubemail/skins/default/common.css

    r5454 r5490  
    233233 
    234234#message div.notice, 
     235#messagebody .part-notice, 
    235236#message-objects div.notice 
    236237{ 
  • trunk/roundcubemail/skins/default/mail.css

    r5483 r5490  
    12041204} 
    12051205 
    1206 #message-objects div 
     1206#messagebody span.part-notice 
     1207{ 
     1208  display: block; 
     1209} 
     1210 
     1211#message-objects div, 
     1212#messagebody span.part-notice 
    12071213{ 
    12081214  margin: 8px; 
     
    12111217} 
    12121218 
    1213 #message-objects div a 
     1219#message-objects div a, 
     1220#messagebody span.part-notice a 
    12141221{ 
    12151222  color: #666666; 
     
    12171224} 
    12181225 
    1219 #message-objects div a:hover 
     1226#message-objects div a:hover, 
     1227#messagebody span.part-notice a:hover 
    12201228{ 
    12211229  color: #333333; 
Note: See TracChangeset for help on using the changeset viewer.