--- trunk/Nos.pm 2005/08/24 17:19:16 74 +++ trunk/Nos.pm 2005/08/24 22:11:00 76 @@ -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,46 @@ # 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", + ); + +Each element in returned array will have following structure: + + { + id => 42, # unique ID of received message + list => 'My list', # useful only of filtering by email + ext_id => 9999, # ext_id from message user + email => 'jdoe@example.com', # e-mail of user + bounced => 0, # true value if message is bounce + date => '2005-08-24 18:57:24', # date of recival in ISO format + } + + +=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 @out; + + my $sth = $self->{'loader'}->find_class('received')->sql_received; + $sth->execute(); + return $sth->fetchall_hash; +} + =head1 INTERNAL METHODS @@ -923,6 +990,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 { @@ -1093,16 +1164,7 @@ You can specify just C or C or any combination of those. -It will return array of hashes with following structure: - - { - id => 42, # unique ID of received message - list => 'My list', # useful only of filtering by email - ext_id => 9999, # ext_id from message user - email => 'jdoe@example.com', # e-mail of user - bounced => 0, # true value if message is bounce - date => '2005-08-24 18:57:24', # date of recival in ISO format - } +For format of returned array element see C. =head2 MessagesReceivedByDate