[prev in list] [next in list] [prev in thread] [next in thread] 

List:       perl-mailbox
Subject:    RE: Mail::Box v2.016 released
From:       "Edward Wildgoose" <Edward.Wildgoose () FRMHedge ! com>
Date:       2002-06-26 13:14:10
[Download RAW message or body]


 - transport failures in Mail::Transport::SMTP returned. Still
   some work to do.
-- 


Mark, I don't feel that the changes here add any significant value to
the error checking.  Below is the current version of the send
sub-routine that I modified based on your advice before (although I
still don't agree that this is easier to read than my original
submission...  Obviously if we can ignore the $server->quit call then
this can be made to look much nicer?)

The point is that you really need to check the results of each call to
fully determine if an error occurred.

Secondly it would be very nice to be able to override the destination
list so that you can send an email TO a certain recipient, but the
message shows additional recipients.  Consider what might happen if you
needed to use two different SMTP servers, say.  However, this becomes a
very useful way to forge mail, so perhaps consider not implementing
it...

Thanks,
 Ed W


sub trySend($)
{   my ($self, $message) = @_;


    my $success = 0;
    my $error = 0;
    my $error_code = 0;
    my $error_message = '';
    my $server;

    unless ($server = $self->contactAnyServer)
    {   # $error_code = $server->code;
        # $error_message = $server->message;
        return wantarray
               ? (0, $error_code, $error_message, 'CONNECT')
               : 0;
    }



    my $from   = $message->from;
    unless($server->mail($message->from->address))
    {   $error_code = $server->code;
        $error_message = $server->message;
        $server->quit;
        return wantarray
           ? (0, $error_code, $error_message, 'FROM')
           : 0;
    }


    foreach my $to ($message->destinations)
    {    unless($server->to($to->address))
         {   $error_code = $server->code;
             $error_message = $server->message;
             $server->quit;
             return wantarray
                 ? (0, $error_code, $error_message, 'RCPT')
                 : 0;
         }
    }


    $server->data;

    # Print the message's header
    # This is first prepared in an array of lines.

    my @lines;
    require IO::Lines;
    my $lines = IO::Lines->new(\@lines);
    $message->head->printUndisclosed($lines);
    $server->datasend($_) foreach @lines;

    # Print the message's body
    my $bodydata = $message->body->file;
    $server->datasend($_) while <$bodydata>;

    unless ($server->dataend)
    {   $error_code = $server->code;
        $error_message = $server->message;
        $server->quit;
        return wantarray
                 ? (0, $error_code, $error_message, 'DATA')
                 : 0;
    }


    # If we get this far, then must have sent mail correctly
    $success = 1;
    $error_code = $server->code;
    $error_message = $server->message;

    # Hangup the connection
    $server->quit;


    wantarray ? (1, $error_code, $error_message, '') : $success;
}


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic