--- trunk/Nos.pm 2005/05/24 14:02:05 47 +++ trunk/Nos.pm 2005/05/24 16:44:34 49 @@ -26,12 +26,6 @@ use Email::Simple; use Email::Address; use Mail::DeliveryStatus::BounceParser; -use Data::Dumper; - -my $email_send_driver = 'Email::Send::IO'; -my @email_send_options; - -#$email_send_driver = 'Sendmail'; =head1 NAME @@ -259,8 +253,6 @@ my $this_user = $users->search( $key => $args->{$key} )->first || return; -print Dumper($this_user); - $this_user->delete || croak "can't delete user\n"; return $users->dbi_commit || croak "can't commit"; @@ -332,7 +324,11 @@ Send queued messages or just ones for selected list - $nos->send_queued_messages("My list",'smtp'); + $nos->send_queued_messages( + list => 'My list', + driver => 'smtp', + sleep => 3, + ); Second option is driver which will be used for e-mail delivery. If not specified, C driver will be used which will dump e-mail to C. @@ -347,14 +343,22 @@ =back +Default sleep wait between two messages is 3 seconds. + =cut sub send_queued_messages { my $self = shift; - my $list_name = shift; + my $arg = {@_}; + + my $list_name = $arg->{'list'} || ''; + my $driver = $arg->{'driver'} || ''; + my $sleep = $arg->{'sleep'}; + $sleep ||= 3 unless defined($sleep); - my $driver = shift || ''; + my $email_send_driver = 'Email::Send::IO'; + my @email_send_options; if (lc($driver) eq 'smtp') { $email_send_driver = 'Email::Send::SMTP'; @@ -401,6 +405,7 @@ my $from_addr; my $from_email_only = $from . "+" . $hash . ( $domain ? '@' . $domain : ''); + $from_addr .= '"' . $u->list_id->from_addr . '" ' if ($u->list_id->from_addr); $from_addr .= '<' . $from_email_only . '>'; my $to = '"' . $u->user_id->name . '" <' . $to_email . '>'; @@ -408,8 +413,8 @@ my $m_obj = Email::Simple->new($msg) || croak "can't parse message"; $m_obj->header_set('Return-Path', $from_email_only) || croak "can't set Return-Path: header"; - $m_obj->header_set('Sender', $from_email_only) || croak "can't set Return-Path: header"; - $m_obj->header_set('Errors-To', $from_email_only) || croak "can't set Return-Path: header"; + $m_obj->header_set('Sender', $from_email_only) || croak "can't set Sender: header"; + $m_obj->header_set('Errors-To', $from_email_only) || croak "can't set Errors-To: header"; $m_obj->header_set('From', $from_addr) || croak "can't set From: header"; $m_obj->header_set('To', $to) || croak "can't set To: header"; @@ -429,6 +434,11 @@ hash => $hash, }); $sent->dbi_commit; + + if ($sleep) { + warn "sleeping $sleep seconds\n"; + sleep($sleep); + } } } $m->all_sent(1); @@ -463,6 +473,8 @@ my $to = $m->header('To') || die "can't find To: address in incomming message\n"; + my $return_path = $m->header('Return-Path') || ''; + my @addrs = Email::Address->parse( $to ); die "can't parse To: $to address\n" unless (@addrs); @@ -478,7 +490,7 @@ } } - croak "can't find hash in e-mail $to\n" unless ($hash); + warn "can't find hash in e-mail $to\n" unless ($hash); my $sent = $self->{'loader'}->find_class('sent'); @@ -497,12 +509,12 @@ my $is_bounce = 0; - { + if ($return_path eq '<>' || $return_path eq '') { no warnings; my $bounce = eval { Mail::DeliveryStatus::BounceParser->new( $arg->{'message'}, { report_non_bounces=>1 }, ) }; - carp "can't check if this message is bounce!" if ($@); + warn "can't check if this message is bounce!" if ($@); $is_bounce++ if ($bounce && $bounce->is_bounce); } @@ -519,10 +531,7 @@ $this_received->dbi_commit; - print "message_id: ",($message_id || "not found")," -- $is_bounce\n"; - - - warn "inbox is not yet implemented"; +# print "message_id: ",($message_id || "not found")," -- $is_bounce\n"; }