Re: Net_SMTP memory issue & quick fix
| From: | Jon Parise | Date: | Fri, 04 Apr 2003 07:39:18 +0000 |
| Subject: | Re: Net_SMTP memory issue & quick fix | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-14878@lists.php.net to get a copy of this message | ||
On Mon, Mar 03, 2003 at 05:46:16PM +0100, Brice Joly wrote:
> I'm using Mail_mime to send an attachment via Mail::factory('smtp'), and I
> have some memory issues with Net_SMTP.
> The problem being that the file I'm sending is a server-generated .pdf (more
> than 500Kb) and when Net_SMTP checks CRLF in the mail body, it also checks
> INSIDE the attachments. Since that means 3 preg_replace() in a row on a
> 500Kb file, server memory is spoiled and I come up with the 8MB memory size
> error... presumably during the very first preg_replace().
>
> Since I thought there was no need to check CRLF into the attachements (at
> least in my case, I'm no mime guru so that might not be true for any file
> type), I decided to change the data() function responsible for those
> preg_replace().
I've spent some time thinking about this problem (about a month, now
that I glance at the date of the original message!), and I've
committed what I think is the best solution. I'm open to additional
comments and suggestions, of course.
The SMTP standard requires that message be quoted. Net_SMTP performs
this quoting because there is no guarantee that the caller will have
already performed any necessary quoting. I think it's best to keep
the Net_SMTP class as ignorant as possible in this respect, such that
it will always do the right thing (even if the operation may redundant
at the cost of performance).
Now, to address your specific problems and others like it:
I've introduce a new class method named quotedata(). It implements
the existing set of standards-compliant quoting routines, and, by
default, the Net_SMTP class uses this method internally to quote
message data.
Because quoting is now handled as a separate class method, it is
possible to extend the Net_SMTP class and override that quotedata()
method in order to implement additional or alternate behavior.
For example, to disable quoting wholesale (untested):
class Net_SMTP_raw extends Net_SMTP
{
function quotedata(&$data)
{
/* Don't perform any message quoting. */
}
}
... and use Net_SMTP_raw in the place of Net_SMTP.
You could add your suggested boundary detection logic to a custom
quotedata() method so that it would not quote the attachment data.
I realize that you'll need to do a little more work to make a custom
extended class interoperate with other PEAR packages (e.g. the Mail
package), but I believe that this is the right thing to do and is in
PEAR's spirit of providing extensible component interfaces.
--
Jon Parise (jon@php.net) :: The PHP Project (http://www.php.net/)