27 |
use Email::Address; |
use Email::Address; |
28 |
use Mail::DeliveryStatus::BounceParser; |
use Mail::DeliveryStatus::BounceParser; |
29 |
use Class::DBI::AbstractSearch; |
use Class::DBI::AbstractSearch; |
30 |
|
use SQL::Abstract; |
31 |
use Mail::Alias; |
use Mail::Alias; |
32 |
use Cwd qw(abs_path); |
use Cwd qw(abs_path); |
33 |
|
|
117 |
|
|
118 |
$self->{'hash_len'} ||= 8; |
$self->{'hash_len'} ||= 8; |
119 |
|
|
|
$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 |
|
|
}, |
|
|
); |
|
|
|
|
120 |
$self ? return $self : return undef; |
$self ? return $self : return undef; |
121 |
} |
} |
122 |
|
|
714 |
email => "john.doe@example.com", |
email => "john.doe@example.com", |
715 |
); |
); |
716 |
|
|
717 |
This method is used by C<sender.pl> when receiving e-mail messages. |
Each element in returned array will have following structure: |
718 |
|
|
719 |
|
{ |
720 |
|
id => 42, # unique ID of received message |
721 |
|
list => 'My list', # useful if filtering by email |
722 |
|
ext_id => 9999, # ext_id from message sender |
723 |
|
email => 'jdoe@example.com', # e-mail of message sender |
724 |
|
bounced => 0, # true if message is bounce |
725 |
|
date => '2005-08-24 18:57:24', # date of receival in ISO format |
726 |
|
} |
727 |
|
|
728 |
|
|
729 |
=cut |
=cut |
730 |
|
|
731 |
sub received_messages { |
sub received_messages { |
732 |
my $self = shift; |
my $self = shift; |
733 |
|
|
734 |
my $arg = {@_}; |
my $arg = {@_} if (@_); |
735 |
|
|
736 |
croak "need list name or email" unless ($arg->{'list'} || $arg->{'email'}); |
# croak "need list name or email" unless ($arg->{'list'} || $arg->{'email'}); |
737 |
|
|
738 |
$arg->{'list'} = lc($arg->{'list'}); |
my $sql = qq{ |
739 |
$arg->{'email'} = lc($arg->{'email'}); |
select |
740 |
|
received.id as id, |
741 |
|
lists.name as list, |
742 |
|
users.ext_id as ext_id, |
743 |
|
users.email as email, |
744 |
|
bounced,received.date as date |
745 |
|
from received |
746 |
|
join lists on lists.id = list_id |
747 |
|
join users on users.id = user_id |
748 |
|
}; |
749 |
|
|
750 |
|
my $where; |
751 |
|
|
752 |
my $rcvd = $self->{'loader'}->find_class('received')->search_received(); |
$where->{'lists.name'} = lc($arg->{'list'}) if ($arg->{'list'}); |
753 |
|
$where->{'users.email'} = lc($arg->{'email'}) if ($arg->{'email'}); |
754 |
|
|
755 |
return $rcvd; |
# hum, yammy one-liner |
756 |
|
my($stmt, @bind) = SQL::Abstract->new->where($where); |
757 |
|
|
758 |
|
my $dbh = $self->{'loader'}->find_class('received')->db_Main; |
759 |
|
|
760 |
|
my $sth = $dbh->prepare($sql . $stmt); |
761 |
|
$sth->execute(@bind); |
762 |
|
return $sth->fetchall_hash; |
763 |
} |
} |
764 |
|
|
765 |
|
|
1155 |
} |
} |
1156 |
} |
} |
1157 |
|
|
|
=head1 UNIMPLEMENTED FUNCTIONS |
|
|
|
|
|
This is a stub for documentation of unimplemented functions. |
|
|
|
|
1158 |
=head2 MessagesReceived |
=head2 MessagesReceived |
1159 |
|
|
1160 |
|
Return statistics about received messages. |
1161 |
|
|
1162 |
my @result = MessagesReceived( |
my @result = MessagesReceived( |
1163 |
list => 'My list', |
list => 'My list', |
1164 |
email => 'jdoe@example.com', |
email => 'jdoe@example.com', |
1165 |
); |
); |
1166 |
|
|
1167 |
You can specify just C<list> or C<email> or any combination of those. |
You must specify C<list> or C<email> or any combination of those. |
1168 |
|
|
1169 |
It will return array of hashes with following structure: |
For format of returned array element see C<received_messages>. |
1170 |
|
|
1171 |
{ |
=cut |
1172 |
id => 42, # unique ID of received message |
|
1173 |
list => 'My list', # useful only of filtering by email |
sub MessagesReceived { |
1174 |
ext_id => 9999, # ext_id from message user |
my $self = shift; |
1175 |
email => 'jdoe@example.com', # e-mail of user |
|
1176 |
bounced => 0, # true value if message is bounce |
if ($_[0] !~ m/^HASH/) { |
1177 |
date => '2005-08-24 18:57:24', # date of recival in ISO format |
die "need at least list or email" unless (scalar @_ < 2); |
1178 |
} |
return $nos->received_messages( |
1179 |
|
list => $_[0], email => $_[1], |
1180 |
|
); |
1181 |
|
} else { |
1182 |
|
my $arg = shift; |
1183 |
|
die "need list or email argument" unless ($arg->{'list'} || $arg->{'email'}); |
1184 |
|
return $nos->received_messages( $arg ); |
1185 |
|
} |
1186 |
|
} |
1187 |
|
|
1188 |
|
### |
1189 |
|
|
1190 |
|
=head1 UNIMPLEMENTED SOAP FUNCTIONS |
1191 |
|
|
1192 |
|
This is a stub for documentation of unimplemented functions. |
1193 |
|
|
1194 |
=head2 MessagesReceivedByDate |
=head2 MessagesReceivedByDate |
1195 |
|
|
1196 |
=head2 MessagesReceivedByDateWithContent |
=head2 MessagesReceivedByDateWithContent |
1197 |
|
|
1198 |
=head2 ReceivedMessasgeContent |
=head2 ReceivedMessageContent |
1199 |
|
|
1200 |
Return content of received message. |
Return content of received message. |
1201 |
|
|
1202 |
my $mail_body = ReceivedMessageContent( id => 42 ); |
my $mail_body = ReceivedMessageContent( id => 42 ); |
1203 |
|
|
|
=cut |
|
1204 |
|
|
1205 |
|
|
1206 |
|
|
|
|
|
|
### |
|
|
|
|
1207 |
=head1 NOTE ON ARRAYS IN SOAP |
=head1 NOTE ON ARRAYS IN SOAP |
1208 |
|
|
1209 |
Returning arrays from SOAP calls is somewhat fuzzy (at least to me). It |
Returning arrays from SOAP calls is somewhat fuzzy (at least to me). It |