--- trunk/Nos.pm 2005/08/24 21:27:40 75 +++ trunk/Nos.pm 2005/08/25 11:58:15 79 @@ -27,6 +27,7 @@ use Email::Address; use Mail::DeliveryStatus::BounceParser; use Class::DBI::AbstractSearch; +use SQL::Abstract; use Mail::Alias; use Cwd qw(abs_path); @@ -116,20 +117,6 @@ $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; } @@ -727,23 +714,52 @@ email => "john.doe@example.com", ); -This method is used by C when receiving e-mail messages. +Each element in returned array will have following structure: + + { + id => 42, # unique ID of received message + list => 'My list', # useful if filtering by email + ext_id => 9999, # ext_id from message sender + email => 'jdoe@example.com', # e-mail of message sender + bounced => 0, # true if message is bounce + date => '2005-08-24 18:57:24', # date of receival in ISO format + } + =cut sub received_messages { my $self = shift; - my $arg = {@_}; + my $arg = {@_} if (@_); - croak "need list name or email" unless ($arg->{'list'} || $arg->{'email'}); +# croak "need list name or email" unless ($arg->{'list'} || $arg->{'email'}); - $arg->{'list'} = lc($arg->{'list'}); - $arg->{'email'} = lc($arg->{'email'}); + my $sql = 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 + }; + + my $where; - my $rcvd = $self->{'loader'}->find_class('received')->search_received(); + $where->{'lists.name'} = lc($arg->{'list'}) if ($arg->{'list'}); + $where->{'users.email'} = lc($arg->{'email'}) if ($arg->{'email'}); - return $rcvd; + # hum, yammy one-liner + my($stmt, @bind) = SQL::Abstract->new->where($where); + + my $dbh = $self->{'loader'}->find_class('received')->db_Main; + + my $sth = $dbh->prepare($sql . $stmt); + $sth->execute(@bind); + return $sth->fetchall_hash; } @@ -1139,47 +1155,55 @@ } } -=head1 UNIMPLEMENTED FUNCTIONS - -This is a stub for documentation of unimplemented functions. - =head2 MessagesReceived +Return statistics about received messages. + my @result = MessagesReceived( list => 'My list', email => 'jdoe@example.com', ); -You can specify just C or C or any combination of those. +You must specify C or C or any combination of those. -It will return array of hashes with following structure: +For format of returned array element see C. - { - 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 MessagesReceived { + my $self = shift; + + if ($_[0] !~ m/^HASH/) { + die "need at least list or email" unless (scalar @_ < 2); + return $nos->received_messages( + list => $_[0], email => $_[1], + ); + } else { + my $arg = shift; + die "need list or email argument" unless ($arg->{'list'} || $arg->{'email'}); + return $nos->received_messages( $arg ); + } +} + +### + +=head1 UNIMPLEMENTED SOAP FUNCTIONS + +This is a stub for documentation of unimplemented functions. =head2 MessagesReceivedByDate =head2 MessagesReceivedByDateWithContent -=head2 ReceivedMessasgeContent +=head2 ReceivedMessageContent Return content of received message. my $mail_body = ReceivedMessageContent( id => 42 ); -=cut - -### - =head1 NOTE ON ARRAYS IN SOAP Returning arrays from SOAP calls is somewhat fuzzy (at least to me). It