16 |
our @EXPORT = qw( |
our @EXPORT = qw( |
17 |
); |
); |
18 |
|
|
19 |
our $VERSION = '0.7'; |
our $VERSION = '0.8'; |
20 |
|
|
21 |
use Class::DBI::Loader; |
use Class::DBI::Loader; |
22 |
use Email::Valid; |
use Email::Valid; |
116 |
|
|
117 |
$self->{'hash_len'} ||= 8; |
$self->{'hash_len'} ||= 8; |
118 |
|
|
119 |
|
$self->{'loader'}->find_class('received')->set_sql( |
120 |
|
'received' => qq{ |
121 |
|
select |
122 |
|
received.id as id, |
123 |
|
lists.name as list, |
124 |
|
users.ext_id as ext_id, |
125 |
|
users.email as email, |
126 |
|
bounced,received.date as date |
127 |
|
from received |
128 |
|
join lists on lists.id = list_id |
129 |
|
join users on users.id = user_id |
130 |
|
}, |
131 |
|
); |
132 |
|
|
133 |
$self ? return $self : return undef; |
$self ? return $self : return undef; |
134 |
} |
} |
135 |
|
|
489 |
|
|
490 |
=back |
=back |
491 |
|
|
492 |
|
Any other driver name will try to use C<Email::Send::that_driver> module. |
493 |
|
|
494 |
Default sleep wait between two messages is 3 seconds. |
Default sleep wait between two messages is 3 seconds. |
495 |
|
|
496 |
|
This method will return number of succesfully sent messages. |
497 |
|
|
498 |
=cut |
=cut |
499 |
|
|
500 |
sub send_queued_messages { |
sub send_queued_messages { |
507 |
my $sleep = $arg->{'sleep'}; |
my $sleep = $arg->{'sleep'}; |
508 |
$sleep ||= 3 unless defined($sleep); |
$sleep ||= 3 unless defined($sleep); |
509 |
|
|
510 |
|
# number of messages sent o.k. |
511 |
|
my $ok = 0; |
512 |
|
|
513 |
my $email_send_driver = 'Email::Send::IO'; |
my $email_send_driver = 'Email::Send::IO'; |
514 |
my @email_send_options; |
my @email_send_options; |
515 |
|
|
516 |
if (lc($driver) eq 'smtp') { |
if (lc($driver) eq 'smtp') { |
517 |
$email_send_driver = 'Email::Send::SMTP'; |
$email_send_driver = 'Email::Send::SMTP'; |
518 |
@email_send_options = ['127.0.0.1']; |
@email_send_options = ['127.0.0.1']; |
519 |
|
} elsif ($driver && $driver ne '') { |
520 |
|
$email_send_driver = 'Email::Send::' . $driver; |
521 |
} else { |
} else { |
522 |
warn "dumping all messages to STDERR\n"; |
warn "dumping all messages to STDERR\n"; |
523 |
} |
} |
587 |
} |
} |
588 |
|
|
589 |
croak "can't send e-mail: $sent_status\n\nOriginal e-mail follows:\n".$m_obj->as_string unless ($sent_status); |
croak "can't send e-mail: $sent_status\n\nOriginal e-mail follows:\n".$m_obj->as_string unless ($sent_status); |
590 |
my @bad = @{ $sent_status->prop('bad') }; |
my @bad; |
591 |
|
@bad = @{ $sent_status->prop('bad') } if (eval { $sent_status->can('prop') }); |
592 |
croak "failed sending to ",join(",",@bad) if (@bad); |
croak "failed sending to ",join(",",@bad) if (@bad); |
593 |
|
|
594 |
if ($sent_status) { |
if ($sent_status) { |
602 |
|
|
603 |
print " - $sent_status\n"; |
print " - $sent_status\n"; |
604 |
|
|
605 |
|
$ok++; |
606 |
} else { |
} else { |
607 |
warn "ERROR: $sent_status\n"; |
warn "ERROR: $sent_status\n"; |
608 |
} |
} |
618 |
$m->dbi_commit; |
$m->dbi_commit; |
619 |
} |
} |
620 |
|
|
621 |
|
return $ok; |
622 |
|
|
623 |
} |
} |
624 |
|
|
625 |
=head2 inbox_message |
=head2 inbox_message |
718 |
# print "message_id: ",($message_id || "not found")," -- $is_bounce\n"; |
# print "message_id: ",($message_id || "not found")," -- $is_bounce\n"; |
719 |
} |
} |
720 |
|
|
721 |
|
=head2 received_messages |
722 |
|
|
723 |
|
Returns all received messages for given list or user. |
724 |
|
|
725 |
|
my @received = $nos->received_message( |
726 |
|
list => 'My list', |
727 |
|
email => "john.doe@example.com", |
728 |
|
); |
729 |
|
|
730 |
|
This method is used by C<sender.pl> when receiving e-mail messages. |
731 |
|
|
732 |
|
=cut |
733 |
|
|
734 |
|
sub received_messages { |
735 |
|
my $self = shift; |
736 |
|
|
737 |
|
my $arg = {@_}; |
738 |
|
|
739 |
|
croak "need list name or email" unless ($arg->{'list'} || $arg->{'email'}); |
740 |
|
|
741 |
|
$arg->{'list'} = lc($arg->{'list'}); |
742 |
|
$arg->{'email'} = lc($arg->{'email'}); |
743 |
|
|
744 |
|
my $rcvd = $self->{'loader'}->find_class('received')->search_received(); |
745 |
|
|
746 |
|
return $rcvd; |
747 |
|
} |
748 |
|
|
749 |
|
|
750 |
=head1 INTERNAL METHODS |
=head1 INTERNAL METHODS |
751 |
|
|
978 |
aliases => '/etc/aliases', |
aliases => '/etc/aliases', |
979 |
); |
); |
980 |
|
|
981 |
|
If you are writing SOAP server (like C<soap.cgi> example), you will need to |
982 |
|
call this method once to make new instance of Nos::SOAP and specify C<dsn> |
983 |
|
and options for it. |
984 |
|
|
985 |
=cut |
=cut |
986 |
|
|
987 |
sub new { |
sub new { |