Changeset 2766 in subversion


Ignore:
Timestamp:
Jul 19, 2009 5:28:30 AM (4 years ago)
Author:
alec
Message:
  • handle big attachments with file pointers to not exceed memory_limit in rcmail_save_attachment()
Location:
trunk/roundcubemail
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/plugins/database_attachments/database_attachments.php

    r2401 r2766  
    6464 
    6565        $key = $this->_key($args['name']); 
     66 
     67        if ($args['path']) 
     68            $args['data'] = file_get_contents($args['path']); 
     69 
    6670        $data = base64_encode($args['data']); 
    6771 
  • trunk/roundcubemail/plugins/filesystem_attachments/filesystem_attachments.php

    r2401 r2766  
    7474    { 
    7575        $args['status'] = false; 
    76         $rcmail = rcmail::get_instance(); 
    77         $temp_dir = unslashify($rcmail->config->get('temp_dir')); 
    78         $tmp_path = tempnam($temp_dir, 'rcmAttmnt'); 
     76         
     77        if (!$args['path']) { 
     78            $rcmail = rcmail::get_instance(); 
     79            $temp_dir = unslashify($rcmail->config->get('temp_dir')); 
     80            $tmp_path = tempnam($temp_dir, 'rcmAttmnt'); 
    7981 
    80         if ($fp = fopen($tmp_path, 'w')) { 
    81             fwrite($fp, $args['data']); 
    82             fclose($fp); 
     82            if ($fp = fopen($tmp_path, 'w')) { 
     83                fwrite($fp, $args['data']); 
     84                fclose($fp); 
     85                $args['path'] = $tmp_path; 
     86            } else 
     87                return $args; 
     88        } 
     89         
     90        $args['id'] = count($_SESSION['plugins']['filesystem_attachments']['tmp_files'])+1; 
     91        $args['status'] = true; 
    8392             
    84             $args['id'] = count($_SESSION['plugins']['filesystem_attachments']['tmp_files'])+1; 
    85             $args['path'] = $tmp_path; 
    86             $args['status'] = true; 
    87              
    88             // Note the file for later cleanup 
    89             $_SESSION['plugins']['filesystem_attachments']['tmp_files'][] = $tmp_path; 
    90         } 
     93        // Note the file for later cleanup 
     94        $_SESSION['plugins']['filesystem_attachments']['tmp_files'][] = $args['path']; 
    9195 
    9296        return $args; 
  • trunk/roundcubemail/program/steps/mail/compose.inc

    r2731 r2766  
    602602{ 
    603603  global $OUTPUT; 
    604    
     604echo "^^^^^";   
    605605  $cid_map = array(); 
    606606  foreach ((array)$message->mime_parts as $pid => $part) 
     
    644644{ 
    645645  $part = $message->mime_parts[$pid]; 
    646    
     646  $mem_limit = parse_bytes(ini_get('memory_limit')); 
     647  $curr_mem = function_exists('memory_get_usage') ? memory_get_usage() : 16*1024*1024; // safe value: 16MB 
     648  $data = $path = null; 
     649 
     650  // don't load too big attachments into memory 
     651  if ($mem_limit > 0 && $part->size > $mem_limit - $curr_mem) { 
     652    $rcmail = rcmail::get_instance(); 
     653    $temp_dir = unslashify($rcmail->config->get('temp_dir')); 
     654    $path = tempnam($temp_dir, 'rcmAttmnt'); 
     655    if ($fp = fopen($path, 'w')) { 
     656      $message->get_part_content($pid, $fp); 
     657      fclose($fp); 
     658    } else 
     659      return false; 
     660  } else { 
     661    $data = $message->get_part_content($pid); 
     662  } 
     663 
    647664  $attachment = array( 
    648665    'name' => $part->filename ? $part->filename : 'Part_'.$pid.'.'.$part->ctype_secondary, 
    649666    'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary, 
    650667    'content_id' => $part->content_id, 
    651     'data' => $message->get_part_content($pid), 
     668    'data' => $data, 
     669    'path' => $path 
    652670  ); 
    653671   
    654672  $attachment = rcmail::get_instance()->plugins->exec_hook('save_attachment', $attachment); 
     673 
    655674  if ($attachment['status']) { 
    656675    unset($attachment['data'], $attachment['status']); 
    657676    return $attachment; 
    658   } 
    659  
     677  } else if ($path) { 
     678    @unlink($path); 
     679  } 
     680   
    660681  return false; 
    661682} 
Note: See TracChangeset for help on using the changeset viewer.