16 |
our @EXPORT = qw( |
our @EXPORT = qw( |
17 |
); |
); |
18 |
|
|
19 |
our $VERSION = '0.4'; |
our $VERSION = '0.5'; |
20 |
|
|
21 |
use Class::DBI::Loader; |
use Class::DBI::Loader; |
22 |
use Email::Valid; |
use Email::Valid; |
108 |
my $arg = {@_}; |
my $arg = {@_}; |
109 |
|
|
110 |
confess "need list name" unless ($arg->{'list'}); |
confess "need list name" unless ($arg->{'list'}); |
111 |
confess "need list email" unless ($arg->{'list'}); |
confess "need list email" unless ($arg->{'email'}); |
112 |
|
|
113 |
|
$arg->{'list'} = lc($arg->{'list'}); |
114 |
|
$arg->{'email'} = lc($arg->{'email'}); |
115 |
|
|
116 |
my $l = $self->_get_list($arg->{'list'}) || |
my $l = $self->_get_list($arg->{'list'}) || |
117 |
$self->_add_list( @_ ) || |
$self->_add_list( @_ ) || |
129 |
list => "My list", |
list => "My list", |
130 |
email => "john.doe@example.com", |
email => "john.doe@example.com", |
131 |
name => "John A. Doe", |
name => "John A. Doe", |
132 |
|
ext_id => 42, |
133 |
); |
); |
134 |
|
|
135 |
C<name> parametar is optional. |
C<name> and C<ext_id> parametars are optional. |
136 |
|
|
137 |
Return member ID if user is added. |
Return member ID if user is added. |
138 |
|
|
143 |
|
|
144 |
my $arg = {@_}; |
my $arg = {@_}; |
145 |
|
|
146 |
my $email = $arg->{'email'} || croak "can't add user without e-mail"; |
my $email = lc($arg->{'email'}) || croak "can't add user without e-mail"; |
147 |
my $name = $arg->{'name'} || ''; |
my $name = $arg->{'name'} || ''; |
148 |
my $list_name = $arg->{'list'} || croak "need list name"; |
my $list_name = lc($arg->{'list'}) || croak "need list name"; |
149 |
|
my $ext_id = $arg->{'ext_id'}; |
150 |
|
|
151 |
my $list = $self->_get_list($list_name) || croak "list $list_name doesn't exist"; |
my $list = $self->_get_list($list_name) || croak "list $list_name doesn't exist"; |
152 |
|
|
169 |
$this_user->update; |
$this_user->update; |
170 |
} |
} |
171 |
|
|
172 |
|
if (defined($ext_id) && ($this_user->ext_id || '') ne $ext_id) { |
173 |
|
$this_user->ext_id($ext_id); |
174 |
|
$this_user->update; |
175 |
|
} |
176 |
|
|
177 |
my $user_on_list = $user_list->find_or_create({ |
my $user_on_list = $user_list->find_or_create({ |
178 |
user_id => $this_user->id, |
user_id => $this_user->id, |
179 |
list_id => $list->id, |
list_id => $list->id, |
201 |
email => 'dpavlin@rot13.org |
email => 'dpavlin@rot13.org |
202 |
} |
} |
203 |
|
|
204 |
If list is not found, returns false. |
If list is not found, returns false. If there is C<ext_id> in user data, |
205 |
|
that will also be returned. |
206 |
|
|
207 |
=cut |
=cut |
208 |
|
|
211 |
|
|
212 |
my $args = {@_}; |
my $args = {@_}; |
213 |
|
|
214 |
my $list_name = $args->{'list'} || confess "need list name"; |
my $list_name = lc($args->{'list'}) || confess "need list name"; |
215 |
|
|
216 |
my $lists = $self->{'loader'}->find_class('lists'); |
my $lists = $self->{'loader'}->find_class('lists'); |
217 |
my $user_list = $self->{'loader'}->find_class('user_list'); |
my $user_list = $self->{'loader'}->find_class('user_list'); |
226 |
email => $user_on_list->user_id->email, |
email => $user_on_list->user_id->email, |
227 |
}; |
}; |
228 |
|
|
229 |
|
my $ext_id = $user_on_list->user_id->ext_id; |
230 |
|
$row->{'ext_id'} = $ext_id if (defined($ext_id)); |
231 |
|
|
232 |
push @results, $row; |
push @results, $row; |
233 |
} |
} |
234 |
|
|
260 |
|
|
261 |
croak "need name or email of user to delete" unless ($args->{'name'} || $args->{'email'}); |
croak "need name or email of user to delete" unless ($args->{'name'} || $args->{'email'}); |
262 |
|
|
263 |
|
$args->{'email'} = lc($args->{'email'}) if ($args->{'email'}); |
264 |
|
|
265 |
my $key = 'name'; |
my $key = 'name'; |
266 |
$key = 'email' if ($args->{'email'}); |
$key = 'email' if ($args->{'email'}); |
267 |
|
|
299 |
|
|
300 |
my $args = {@_}; |
my $args = {@_}; |
301 |
|
|
302 |
my $list_name = $args->{'list'} || confess "need list name"; |
my $list_name = lc($args->{'list'}) || confess "need list name"; |
303 |
my $message_text = $args->{'message'} || croak "need message"; |
my $message_text = $args->{'message'} || croak "need message"; |
304 |
|
|
305 |
my $m = Email::Simple->new($message_text) || croak "can't parse message"; |
my $m = Email::Simple->new($message_text) || croak "can't parse message"; |
368 |
|
|
369 |
my $arg = {@_}; |
my $arg = {@_}; |
370 |
|
|
371 |
my $list_name = $arg->{'list'} || ''; |
my $list_name = lc($arg->{'list'}) || ''; |
372 |
my $driver = $arg->{'driver'} || ''; |
my $driver = $arg->{'driver'} || ''; |
373 |
my $sleep = $arg->{'sleep'}; |
my $sleep = $arg->{'sleep'}; |
374 |
$sleep ||= 3 unless defined($sleep); |
$sleep ||= 3 unless defined($sleep); |
379 |
if (lc($driver) eq 'smtp') { |
if (lc($driver) eq 'smtp') { |
380 |
$email_send_driver = 'Email::Send::SMTP'; |
$email_send_driver = 'Email::Send::SMTP'; |
381 |
@email_send_options = ['127.0.0.1']; |
@email_send_options = ['127.0.0.1']; |
382 |
|
} else { |
383 |
|
warn "dumping all messages to STDERR\n"; |
384 |
} |
} |
|
warn "using $driver [$email_send_driver]\n"; |
|
385 |
|
|
386 |
my $lists = $self->{'loader'}->find_class('lists'); |
my $lists = $self->{'loader'}->find_class('lists'); |
387 |
my $queue = $self->{'loader'}->find_class('queue'); |
my $queue = $self->{'loader'}->find_class('queue'); |
484 |
return unless ($arg->{'message'}); |
return unless ($arg->{'message'}); |
485 |
croak "need list name" unless ($arg->{'list'}); |
croak "need list name" unless ($arg->{'list'}); |
486 |
|
|
487 |
|
$arg->{'list'} = lc($arg->{'list'}); |
488 |
|
|
489 |
my $this_list = $self->_get_list($arg->{'list'}) || croak "can't find list ".$arg->{'list'}."\n"; |
my $this_list = $self->_get_list($arg->{'list'}) || croak "can't find list ".$arg->{'list'}."\n"; |
490 |
|
|
491 |
my $m = Email::Simple->new($arg->{'message'}) || croak "can't parse message"; |
my $m = Email::Simple->new($arg->{'message'}) || croak "can't parse message"; |
503 |
my $hash; |
my $hash; |
504 |
|
|
505 |
foreach my $a (@addrs) { |
foreach my $a (@addrs) { |
506 |
if ($a->address =~ m/\+([a-f0-9]{$hl})@/) { |
if ($a->address =~ m/\+([a-f0-9]{$hl})@/i) { |
507 |
$hash = $1; |
$hash = $1; |
508 |
last; |
last; |
509 |
} |
} |
510 |
} |
} |
511 |
|
|
512 |
warn "can't find hash in e-mail $to\n" unless ($hash); |
#warn "can't find hash in e-mail $to\n" unless ($hash); |
513 |
|
|
514 |
my $sent = $self->{'loader'}->find_class('sent'); |
my $sent = $self->{'loader'}->find_class('sent'); |
515 |
|
|
516 |
# will use null if no matching message_id is found |
# will use null if no matching message_id is found |
517 |
my $sent_msg = $sent->search( hash => $hash )->first; |
my $sent_msg; |
518 |
|
$sent_msg = $sent->search( hash => $hash )->first if ($hash); |
519 |
|
|
520 |
my ($message_id, $user_id) = (undef, undef); # init with NULL |
my ($message_id, $user_id) = (undef, undef); # init with NULL |
521 |
|
|
523 |
$message_id = $sent_msg->message_id || carp "no message_id"; |
$message_id = $sent_msg->message_id || carp "no message_id"; |
524 |
$user_id = $sent_msg->user_id || carp "no user_id"; |
$user_id = $sent_msg->user_id || carp "no user_id"; |
525 |
} else { |
} else { |
526 |
warn "can't find sender with hash $hash\n"; |
#warn "can't find sender with hash $hash\n"; |
527 |
|
my $users = $self->{'loader'}->find_class('users'); |
528 |
|
my $from = $m->header('From'); |
529 |
|
$from = $1 if ($from =~ m/<(.*)>/); |
530 |
|
my $this_user = $users->search( email => lc($from) )->first; |
531 |
|
$user_id = $this_user->id if ($this_user); |
532 |
} |
} |
533 |
|
|
534 |
|
|
539 |
my $bounce = eval { Mail::DeliveryStatus::BounceParser->new( |
my $bounce = eval { Mail::DeliveryStatus::BounceParser->new( |
540 |
$arg->{'message'}, { report_non_bounces=>1 }, |
$arg->{'message'}, { report_non_bounces=>1 }, |
541 |
) }; |
) }; |
542 |
warn "can't check if this message is bounce!" if ($@); |
#warn "can't check if this message is bounce!" if ($@); |
543 |
|
|
544 |
$is_bounce++ if ($bounce && $bounce->is_bounce); |
$is_bounce++ if ($bounce && $bounce->is_bounce); |
545 |
} |
} |
588 |
|
|
589 |
my $arg = {@_}; |
my $arg = {@_}; |
590 |
|
|
591 |
my $name = $arg->{'list'} || confess "can't add list without name"; |
my $name = lc($arg->{'list'}) || confess "can't add list without name"; |
592 |
my $email = $arg->{'email'} || confess "can't add list without e-mail"; |
my $email = lc($arg->{'email'}) || confess "can't add list without e-mail"; |
593 |
my $from_addr = $arg->{'from'}; |
my $from_addr = $arg->{'from'}; |
594 |
|
|
595 |
my $lists = $self->{'loader'}->find_class('lists'); |
my $lists = $self->{'loader'}->find_class('lists'); |
630 |
|
|
631 |
my $lists = $self->{'loader'}->find_class('lists') || confess "can't find lists class"; |
my $lists = $self->{'loader'}->find_class('lists') || confess "can't find lists class"; |
632 |
|
|
633 |
return $lists->search({ name => $name })->first; |
return $lists->search({ name => lc($name) })->first; |
634 |
} |
} |
635 |
|
|
636 |
### |
### |
672 |
|
|
673 |
$message_id = NewList( |
$message_id = NewList( |
674 |
list => 'My list', |
list => 'My list', |
675 |
|
from => 'Name of my list', |
676 |
email => 'my-list@example.com' |
email => 'my-list@example.com' |
677 |
); |
); |
678 |
|
|
683 |
|
|
684 |
if ($_[0] !~ m/^HASH/) { |
if ($_[0] !~ m/^HASH/) { |
685 |
return $nos->new_list( |
return $nos->new_list( |
686 |
list => $_[0], email => $_[1], |
list => $_[0], from => $_[1], email => $_[2], |
687 |
); |
); |
688 |
} else { |
} else { |
689 |
return $nos->new_list( %{ shift @_ } ); |
return $nos->new_list( %{ shift @_ } ); |