Large file attachments consume too much memory when sending messages.
|Reported by:||dopry||Owned by:|
When sending a file several copies of the attached files are stored as passed around. I believe four copies are being stored in memory. in program/steps/mail/sendmail.inc, 1 copy in $msg_body and 1 copy in MAIL_MIME->_parts (the assign by reference of $msg_body to MAIL_MIME->get has no effect in this case and a copy is created). in program/includes/rcube_sendmail a copied is made when SMTP_CONN->data is called. in program lib/Net/SMTP.php a copied is made by preg_replace for its internal cache.
Two copies of the attached files can be eliminated. 1) unset MIME_MAIL->_parts after msg_body is assigned in program/steps/mail/sendmail.inc. 2) create a $data variable in program/includes/rcube_sendmail and do a call time pass by reference into SMTP_CONN->send, then preg_replace will store a reference. It would be more appropriate to change the function definition of data in Net/SMTP.php to recieve the variable by reference.
These two techniques will save having two copies of the mime attachments in memory, reducing the php memory overhead for attachments to only 2 x total attachment size + ~3 megs. instead of 4x total attachment size + ~3 megs.