--- trunk/Nos.pm 2005/08/24 17:19:16 74 +++ trunk/Nos.pm 2005/08/24 21:27:40 75 @@ -16,7 +16,7 @@ our @EXPORT = qw( ); -our $VERSION = '0.7'; +our $VERSION = '0.8'; use Class::DBI::Loader; use Email::Valid; @@ -116,6 +116,20 @@ $self->{'hash_len'} ||= 8; + $self->{'loader'}->find_class('received')->set_sql( + 'received' => qq{ + select + received.id as id, + lists.name as list, + users.ext_id as ext_id, + users.email as email, + bounced,received.date as date + from received + join lists on lists.id = list_id + join users on users.id = user_id + }, + ); + $self ? return $self : return undef; } @@ -475,8 +489,12 @@ =back +Any other driver name will try to use C module. + Default sleep wait between two messages is 3 seconds. +This method will return number of succesfully sent messages. + =cut sub send_queued_messages { @@ -489,12 +507,17 @@ my $sleep = $arg->{'sleep'}; $sleep ||= 3 unless defined($sleep); + # number of messages sent o.k. + my $ok = 0; + my $email_send_driver = 'Email::Send::IO'; my @email_send_options; if (lc($driver) eq 'smtp') { $email_send_driver = 'Email::Send::SMTP'; @email_send_options = ['127.0.0.1']; + } elsif ($driver && $driver ne '') { + $email_send_driver = 'Email::Send::' . $driver; } else { warn "dumping all messages to STDERR\n"; } @@ -564,7 +587,8 @@ } croak "can't send e-mail: $sent_status\n\nOriginal e-mail follows:\n".$m_obj->as_string unless ($sent_status); - my @bad = @{ $sent_status->prop('bad') }; + my @bad; + @bad = @{ $sent_status->prop('bad') } if (eval { $sent_status->can('prop') }); croak "failed sending to ",join(",",@bad) if (@bad); if ($sent_status) { @@ -578,6 +602,7 @@ print " - $sent_status\n"; + $ok++; } else { warn "ERROR: $sent_status\n"; } @@ -593,6 +618,8 @@ $m->dbi_commit; } + return $ok; + } =head2 inbox_message @@ -691,6 +718,34 @@ # print "message_id: ",($message_id || "not found")," -- $is_bounce\n"; } +=head2 received_messages + +Returns all received messages for given list or user. + + my @received = $nos->received_message( + list => 'My list', + email => "john.doe@example.com", + ); + +This method is used by C when receiving e-mail messages. + +=cut + +sub received_messages { + my $self = shift; + + my $arg = {@_}; + + croak "need list name or email" unless ($arg->{'list'} || $arg->{'email'}); + + $arg->{'list'} = lc($arg->{'list'}); + $arg->{'email'} = lc($arg->{'email'}); + + my $rcvd = $self->{'loader'}->find_class('received')->search_received(); + + return $rcvd; +} + =head1 INTERNAL METHODS @@ -923,6 +978,10 @@ aliases => '/etc/aliases', ); +If you are writing SOAP server (like C example), you will need to +call this method once to make new instance of Nos::SOAP and specify C +and options for it. + =cut sub new {