Hi Fred,

On Wed, 23 Aug 2006 01:53:11 -0700
Fred Moyer <[EMAIL PROTECTED]> wrote:

> David Nicol wrote:
> Here's the revised version, a bit shorter:
[...]
>     # write the data and recalculate length
>     $self->{_body_file}->print(ref $data eq "SCALAR" ?
>         $$data  . $self->body_as_string :
>         $data   . $self->body_as_string )
this one's scary ;) 
... what happens if you write something in front of a 100 MB or larger
mail? 
... or several huge mails are processed at the same time?

This avoids copying the full mail to RAM by making an inplace
edit (it's untested in qpsmtpd, it may trash the messages... but
something similar should work...) 

  if ($self->{_body_file}) {
    #warn("body_write to file\n");

    # go to the beginning of the file
    $self->body_resetpos
      unless $self->{body_file_writing};
    $self->{_body_file_writing} = 1;

    {
        my @oldARGV = @ARGV;
        @ARGV = $self->body_filename;
        my $oldfh = select $self->{body_file};
        local $^I = '';
        local $.  = 0;
        while (<>) {
            print $data if $. == 1;
            print $_;
        }
        @ARGV = @oldARGV;
        select $oldfh;
    };
    $self->{_body_file_writing} = 0;
  }

        Hanno

Reply via email to