--- trunk/sender.pl 2005/05/14 12:31:27 6 +++ trunk/sender.pl 2005/05/14 20:54:40 13 @@ -3,20 +3,37 @@ use strict; use Class::DBI::Loader::Pg; use Getopt::Long; -use Data::Dumper; +use Mail::CheckUser qw(check_email); +use Email::Valid; =head1 NAME sender.pl - command line notify sender utility +=head1 SYNOPSYS + + sender.pl --add=mylist members.txt + sender.pl --list[=mylist] + sender.pl --queue=mylist message.txt + sender.pl --send=mylist + +=head2 All options + +=over 20 + +=item --debug + +Turn on debugging output from C + =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, @@ -38,16 +55,41 @@ 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[=list_name] -if ($list_opt) { - foreach my $list ($lists->retrieve_all) { +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 (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 ); print "\t",$user->full_name," <", $user->email, ">\n"; } } + +=item --add=list_name + +Add users to list. Users are stored in file (which can be supplied as +argument) or read from C. List should be in following format: + + email@example.com Optional full name of person + dpavlin@rot13.org Dobrica Pavlinusic + +=cut + } elsif ($add_opt) { #my $noticer = $loader->find_class('Noticer') || die "can't find my class!"; my $list = $lists->find_or_create({ @@ -60,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, @@ -79,6 +125,13 @@ print "list ",$list->name," has $added users\n"; +=item --queue=list_name + +Queue message for later delivery. Message can be read from file (specified as +argument) or read from C. + +=cut + } elsif ($queue_opt) { my $this_list = $lists->search( name => $queue_opt, @@ -97,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; @@ -105,11 +158,14 @@ print "added message ",$this_message->id, " to list ",$this_list->name,"\n"; } else { - die $0.' - --list show all lists and users - --add=name_of_list < users.txt add users (email@example.com full name) - --queue=name_of_list < message queue message for sending to list - --debug -'; + die "see perldoc $0 for help"; } +=back + +=head1 AUTHOR + +Dobrica Pavlinusic + +=cut +