709 |
|
|
710 |
Returns all received messages for given list or user. |
Returns all received messages for given list or user. |
711 |
|
|
712 |
my @received = $nos->received_message( |
my @received = $nos->received_messages( |
713 |
list => 'My list', |
list => 'My list', |
714 |
email => "john.doe@example.com", |
email => "john.doe@example.com", |
715 |
|
from_date => '2005-01-01 10:15:00', |
716 |
|
to_date => '2005-01-01 12:00:00', |
717 |
|
message => 0, |
718 |
); |
); |
719 |
|
|
720 |
|
If don't specify C<list> or C<email> it will return all received messages. |
721 |
|
Results will be sorted by received date, oldest first. |
722 |
|
|
723 |
|
Other optional parametars include: |
724 |
|
|
725 |
|
=over 10 |
726 |
|
|
727 |
|
=item from_date |
728 |
|
|
729 |
|
Date (in ISO format) for lower limit of dates received |
730 |
|
|
731 |
|
=item to_date |
732 |
|
|
733 |
|
Return just messages older than this date |
734 |
|
|
735 |
|
=item message |
736 |
|
|
737 |
|
Include whole received message in result. This will probably make result |
738 |
|
array very large. Use with care. |
739 |
|
|
740 |
|
=back |
741 |
|
|
742 |
Each element in returned array will have following structure: |
Each element in returned array will have following structure: |
743 |
|
|
744 |
{ |
my $row = { |
745 |
id => 42, # unique ID of received message |
id => 42, # unique ID of received message |
746 |
list => 'My list', # useful if filtering by email |
list => 'My list', # useful if filtering by email |
747 |
ext_id => 9999, # ext_id from message sender |
ext_id => 9999, # ext_id from message sender |
750 |
date => '2005-08-24 18:57:24', # date of receival in ISO format |
date => '2005-08-24 18:57:24', # date of receival in ISO format |
751 |
} |
} |
752 |
|
|
753 |
|
If you specified C<message> option, this hash will also have C<message> key |
754 |
|
which will contain whole received message. |
755 |
|
|
756 |
=cut |
=cut |
757 |
|
|
768 |
lists.name as list, |
lists.name as list, |
769 |
users.ext_id as ext_id, |
users.ext_id as ext_id, |
770 |
users.email as email, |
users.email as email, |
771 |
|
}; |
772 |
|
$sql .= qq{ message,} if ($arg->{'message'}); |
773 |
|
$sql .= qq{ |
774 |
bounced,received.date as date |
bounced,received.date as date |
775 |
from received |
from received |
776 |
join lists on lists.id = list_id |
join lists on lists.id = list_id |
777 |
join users on users.id = user_id |
join users on users.id = user_id |
778 |
}; |
}; |
779 |
|
|
780 |
|
my $order = qq{ order by date desc }; |
781 |
|
|
782 |
my $where; |
my $where; |
783 |
|
|
784 |
$where->{'lists.name'} = lc($arg->{'list'}) if ($arg->{'list'}); |
$where->{'lists.name'} = lc($arg->{'list'}) if ($arg->{'list'}); |
785 |
$where->{'users.email'} = lc($arg->{'email'}) if ($arg->{'email'}); |
$where->{'users.email'} = lc($arg->{'email'}) if ($arg->{'email'}); |
786 |
|
$where->{'received.date'} = { '>=', $arg->{'date_from'} } if ($arg->{'date_from'}); |
787 |
|
$where->{'received.date'} = { '<=', $arg->{'date_to'} } if ($arg->{'date_to'}); |
788 |
|
|
789 |
# hum, yammy one-liner |
# hum, yammy one-liner |
790 |
my($stmt, @bind) = SQL::Abstract->new->where($where); |
my($stmt, @bind) = SQL::Abstract->new->where($where); |
791 |
|
|
792 |
my $dbh = $self->{'loader'}->find_class('received')->db_Main; |
my $dbh = $self->{'loader'}->find_class('received')->db_Main; |
793 |
|
|
794 |
my $sth = $dbh->prepare($sql . $stmt); |
my $sth = $dbh->prepare($sql . $stmt . $order); |
795 |
$sth->execute(@bind); |
$sth->execute(@bind); |
796 |
return $sth->fetchall_hash; |
return $sth->fetchall_hash; |
797 |
} |
} |
1196 |
my @result = MessagesReceived( |
my @result = MessagesReceived( |
1197 |
list => 'My list', |
list => 'My list', |
1198 |
email => 'jdoe@example.com', |
email => 'jdoe@example.com', |
1199 |
|
from_date => '2005-01-01 10:15:00', |
1200 |
|
to_date => '2005-01-01 12:00:00', |
1201 |
|
message => 0, |
1202 |
); |
); |
1203 |
|
|
1204 |
You must specify C<list> or C<email> or any combination of those. |
You must specify C<list> or C<email> or any combination of those two. Other |
1205 |
|
parametars are optional. |
1206 |
|
|
1207 |
For format of returned array element see C<received_messages>. |
For format of returned array element see C<received_messages>. |
1208 |
|
|
1215 |
die "need at least list or email" unless (scalar @_ < 2); |
die "need at least list or email" unless (scalar @_ < 2); |
1216 |
return $nos->received_messages( |
return $nos->received_messages( |
1217 |
list => $_[0], email => $_[1], |
list => $_[0], email => $_[1], |
1218 |
|
from_date => $_[2], to_date => $_[3], |
1219 |
|
message => $_[4] |
1220 |
); |
); |
1221 |
} else { |
} else { |
1222 |
my $arg = shift; |
my $arg = shift; |