3 |
use strict; |
use strict; |
4 |
use Class::DBI::Loader::Pg; |
use Class::DBI::Loader::Pg; |
5 |
use Getopt::Long; |
use Getopt::Long; |
6 |
use Data::Dumper; |
use Mail::CheckUser qw(check_email); |
7 |
|
use Email::Valid; |
8 |
|
|
9 |
=head1 NAME |
=head1 NAME |
10 |
|
|
13 |
=head1 SYNOPSYS |
=head1 SYNOPSYS |
14 |
|
|
15 |
sender.pl --add=mylist members.txt |
sender.pl --add=mylist members.txt |
16 |
sender.pl --list |
sender.pl --list[=mylist] |
17 |
sender.pl --queue=mylist message.txt |
sender.pl --queue=mylist message.txt |
18 |
sender.pl --send=mylist |
sender.pl --send=mylist |
19 |
|
|
27 |
|
|
28 |
=cut |
=cut |
29 |
|
|
30 |
my ($list_opt,$debug) = (0,0); |
my $debug = 0; |
31 |
|
my $list_opt; |
32 |
my $add_opt; |
my $add_opt; |
33 |
my $queue_opt; |
my $queue_opt; |
34 |
|
|
35 |
my $result = GetOptions( |
my $result = GetOptions( |
36 |
"list" => \$list_opt, |
"list:s" => \$list_opt, |
37 |
"add=s" => \$add_opt, |
"add=s" => \$add_opt, |
38 |
"queue=s" => \$queue_opt, |
"queue=s" => \$queue_opt, |
39 |
"debug" => \$debug, |
"debug" => \$debug, |
55 |
my $users = $loader->find_class('users'); |
my $users = $loader->find_class('users'); |
56 |
my $user_list = $loader->find_class('user_list'); |
my $user_list = $loader->find_class('user_list'); |
57 |
my $messages = $loader->find_class('messages'); |
my $messages = $loader->find_class('messages'); |
58 |
my $message_list = $loader->find_class('message_list'); |
my $queue = $loader->find_class('queue'); |
59 |
|
|
60 |
=item --list |
=item --list[=list_name] |
61 |
|
|
62 |
List all available lists and users on them |
List all available lists and users on them. Optional value is name of list |
63 |
|
and it will produce users just on that list. |
64 |
|
|
65 |
=cut |
=cut |
66 |
|
|
67 |
if ($list_opt) { |
if (defined($list_opt)) { |
68 |
foreach my $list ($lists->retrieve_all) { |
my @lists; |
69 |
|
if ($list_opt ne '') { |
70 |
|
@lists = $lists->search( name=> $list_opt )->first || die "can't find list $list_opt"; |
71 |
|
} else { |
72 |
|
@lists = $lists->retrieve_all; |
73 |
|
} |
74 |
|
|
75 |
|
foreach my $list (@lists) { |
76 |
print $list->name,"\n"; |
print $list->name,"\n"; |
77 |
foreach my $user_on_list ($user_list->search(list_id => $list->id)) { |
foreach my $user_on_list ($user_list->search(list_id => $list->id)) { |
78 |
my $user = $users->retrieve( id => $user_on_list->user_id ); |
my $user = $users->retrieve( id => $user_on_list->user_id ); |
102 |
chomp; |
chomp; |
103 |
next if (/^#/ || /^\s*$/); |
next if (/^#/ || /^\s*$/); |
104 |
my ($email, $name) = split(/\s+/,$_, 2); |
my ($email, $name) = split(/\s+/,$_, 2); |
105 |
|
if (! Email::Valid->address($email)) { |
106 |
|
print "SKIPPING $name <$email>\n"; |
107 |
|
next; |
108 |
|
} |
109 |
print "# $name <$email>\n"; |
print "# $name <$email>\n"; |
110 |
my $this_user = $users->find_or_create({ |
my $this_user = $users->find_or_create({ |
111 |
email => $email, |
email => $email, |
150 |
|
|
151 |
$this_message->dbi_commit(); |
$this_message->dbi_commit(); |
152 |
|
|
153 |
$message_list->find_or_create({ |
$queue->find_or_create({ |
154 |
message_id => $this_message->id, |
message_id => $this_message->id, |
155 |
list_id => $this_list->id, |
list_id => $this_list->id, |
156 |
}) || die "can't add message ",$this_message->id," to list ",$this_list->id, ": ",$this_list->name; |
}) || die "can't add message ",$this_message->id," to list ",$this_list->id, ": ",$this_list->name; |