--- trunk/Nos.pm 2005/08/25 11:58:15 79 +++ trunk/Nos.pm 2005/08/26 11:48:09 82 @@ -709,14 +709,42 @@ Returns all received messages for given list or user. - my @received = $nos->received_message( + my @received = $nos->received_messages( list => 'My list', email => "john.doe@example.com", + from_date => '2005-01-01 10:15:00', + to_date => '2005-01-01 12:00:00', + message => 0, ); +If don't specify C or C it will return all received messages. +Results will be sorted by received date, oldest first. + +Other optional parametars include: + +=over 10 + +=item from_date + +Date (in ISO format) for lower limit of dates received + +=item to_date + +Return just messages older than this date + +=item message + +Include whole received message in result. This will probably make result +array very large. Use with care. + +=back + +Date ranges are inclusive, so results will include messages sent on +particular date specified with C or C. + Each element in returned array will have following structure: - { + my $row = { id => 42, # unique ID of received message list => 'My list', # useful if filtering by email ext_id => 9999, # ext_id from message sender @@ -725,6 +753,8 @@ date => '2005-08-24 18:57:24', # date of receival in ISO format } +If you specified C option, this hash will also have C key +which will contain whole received message. =cut @@ -741,23 +771,30 @@ lists.name as list, users.ext_id as ext_id, users.email as email, + }; + $sql .= qq{ message,} if ($arg->{'message'}); + $sql .= qq{ bounced,received.date as date from received join lists on lists.id = list_id join users on users.id = user_id }; + my $order = qq{ order by date asc }; + my $where; $where->{'lists.name'} = lc($arg->{'list'}) if ($arg->{'list'}); $where->{'users.email'} = lc($arg->{'email'}) if ($arg->{'email'}); + $where->{'received.date'} = { '>=', $arg->{'date_from'} } if ($arg->{'date_from'}); + $where->{'received.date'} = { '<=', $arg->{'date_to'} } if ($arg->{'date_to'}); # 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); + my $sth = $dbh->prepare($sql . $stmt . $order); $sth->execute(@bind); return $sth->fetchall_hash; } @@ -829,7 +866,10 @@ $self_path =~ s#/[^/]+$##; $self_path =~ s#/t/*$#/#; - $target .= qq#| cd $self_path && ./sender.pl --inbox="$list"#; + $target .= qq#"| cd $self_path && ./sender.pl --inbox='$list'"#; + + # remove hostname from email to make Postfix's postalias happy + $email =~ s/@.+//; if ($a->exists($email)) { $a->update($email, $target) or croak "can't update alias ".$a->error_check; @@ -1162,9 +1202,13 @@ my @result = MessagesReceived( list => 'My list', email => 'jdoe@example.com', + from_date => '2005-01-01 10:15:00', + to_date => '2005-01-01 12:00:00', + message => 0, ); -You must specify C or C or any combination of those. +You must specify C or C or any combination of those two. Other +parametars are optional. For format of returned array element see C. @@ -1177,6 +1221,8 @@ die "need at least list or email" unless (scalar @_ < 2); return $nos->received_messages( list => $_[0], email => $_[1], + from_date => $_[2], to_date => $_[3], + message => $_[4] ); } else { my $arg = shift; @@ -1187,23 +1233,6 @@ ### -=head1 UNIMPLEMENTED SOAP FUNCTIONS - -This is a stub for documentation of unimplemented functions. - -=head2 MessagesReceivedByDate - -=head2 MessagesReceivedByDateWithContent - -=head2 ReceivedMessageContent - -Return content of received message. - - my $mail_body = ReceivedMessageContent( id => 42 ); - - - - =head1 NOTE ON ARRAYS IN SOAP Returning arrays from SOAP calls is somewhat fuzzy (at least to me). It