--- trunk/sender.pl 2005/05/14 13:12:00 8 +++ trunk/sender.pl 2005/05/14 20:54:40 13 @@ -3,7 +3,8 @@ use strict; use Class::DBI::Loader::Pg; use Getopt::Long; -use Data::Dumper; +use Mail::CheckUser qw(check_email); +use Email::Valid; =head1 NAME @@ -12,7 +13,7 @@ =head1 SYNOPSYS sender.pl --add=mylist members.txt - sender.pl --list + sender.pl --list[=mylist] sender.pl --queue=mylist message.txt sender.pl --send=mylist @@ -26,12 +27,13 @@ =cut -my ($list_opt,$debug) = (0,0); +my $debug = 0; +my $list_opt; my $add_opt; my $queue_opt; my $result = GetOptions( - "list" => \$list_opt, + "list:s" => \$list_opt, "add=s" => \$add_opt, "queue=s" => \$queue_opt, "debug" => \$debug, @@ -53,16 +55,24 @@ my $users = $loader->find_class('users'); my $user_list = $loader->find_class('user_list'); my $messages = $loader->find_class('messages'); -my $message_list = $loader->find_class('message_list'); +my $queue = $loader->find_class('queue'); -=item --list +=item --list[=list_name] -List all available lists and users on them +List all available lists and users on them. Optional value is name of list +and it will produce users just on that list. =cut -if ($list_opt) { - foreach my $list ($lists->retrieve_all) { +if (defined($list_opt)) { + my @lists; + if ($list_opt ne '') { + @lists = $lists->search( name=> $list_opt )->first || die "can't find list $list_opt"; + } else { + @lists = $lists->retrieve_all; + } + + foreach my $list (@lists) { print $list->name,"\n"; foreach my $user_on_list ($user_list->search(list_id => $list->id)) { my $user = $users->retrieve( id => $user_on_list->user_id ); @@ -92,6 +102,10 @@ chomp; next if (/^#/ || /^\s*$/); my ($email, $name) = split(/\s+/,$_, 2); + if (! Email::Valid->address($email)) { + print "SKIPPING $name <$email>\n"; + next; + } print "# $name <$email>\n"; my $this_user = $users->find_or_create({ email => $email, @@ -136,7 +150,7 @@ $this_message->dbi_commit(); - $message_list->find_or_create({ + $queue->find_or_create({ message_id => $this_message->id, list_id => $this_list->id, }) || die "can't add message ",$this_message->id," to list ",$this_list->id, ": ",$this_list->name;