--- trunk/sender.pl 2005/05/16 20:58:44 29 +++ trunk/sender.pl 2005/05/16 21:54:41 30 @@ -11,6 +11,7 @@ =head1 SYNOPSYS + sender.pl --new=mylist sender.pl --add=mylist members.txt sender.pl --list[=mylist] sender.pl --queue[=mylist message.txt] @@ -28,22 +29,18 @@ my $debug = 0; my $verbose = 0; -my $list_opt; -my $add_opt; -my $queue_opt; -my $send_opt; -my $email_opt; -my $inbox_opt; +my $opt; my $result = GetOptions( - "list:s" => \$list_opt, - "add=s" => \$add_opt, - "queue:s" => \$queue_opt, - "send:s" => \$send_opt, - "inbox=s" => \$inbox_opt, + "new=s" => \$opt->{'new'}, + "list:s" => \$opt->{'list'}, + "add=s" => \$opt->{'add'}, + "queue:s" => \$opt->{'queue'}, + "send:s" => \$opt->{'send'}, + "inbox=s" => \$opt->{'inbox'}, "debug" => \$debug, "verbose" => \$verbose, - "email=s" => \$email_opt, + "email=s" => \$opt->{'email'}, ); my $nos = new Nos( @@ -70,6 +67,29 @@ JOIN lists on list_id = lists.id } ); +my $list_name; + + +=item --new=list_name my-list@example.com + +Adds new list. You can also feed list name as first line to C. + +=cut + +if ($list_name = $opt->{'new'}) { + + my $email = shift @ARGV || <>; + chomp($email); + + die "need e-mail address for list (as argument or on STDIN)\n" unless ($email); + + my $l = $nos->_get_list($list_name) || $nos->_add_list( + list => $list_name, + email => $email, + ) || die "can't add list $list_name\n"; + + print "added list $list_name with ID ",$l->id,"\n"; + =item --list[=list_name] @@ -80,10 +100,12 @@ =cut -if (defined($list_opt)) { +} elsif (defined($list_name = $opt->{'list'})) { + my @lists; - if ($list_opt ne '') { - @lists = $lists->search( name=> $list_opt )->first || die "can't find list $list_opt"; + + if ($list_name ne '') { + @lists = $lists->search( name=> $list_name )->first || die "can't find list $list_name"; } else { @lists = $lists->retrieve_all; } @@ -96,6 +118,7 @@ } } + =item --add=list_name Add users to list. Users are stored in file (which can be supplied as @@ -109,16 +132,11 @@ =cut -} elsif ($add_opt) { - my $list = $lists->find_or_create({ - name => $add_opt, - }) || die "can't add list $add_opt\n"; +} elsif ($list_name = $opt->{'add'}) { - if ($email_opt && $list->email ne $email_opt) { - $list->email($email_opt); - $list->update; - $list->dbi_commit; - } + my $list = $lists->find_or_create({ + name => $list_name, + }) || die "can't add list $list_name\n"; my $added = 0; @@ -126,11 +144,12 @@ chomp; next if (/^#/ || /^\s*$/); my ($email, $name) = split(/\s+/,$_, 2); - $added++ if ($nos->add_member_to_list( email => $email, name => $name, list => $add_opt )); + $added++ if ($nos->add_member_to_list( email => $email, name => $name, list => $list_name )); } 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 @@ -141,9 +160,9 @@ =cut -} elsif (defined($queue_opt)) { +} elsif (defined($list_name = $opt->{'queue'})) { - if ($queue_opt ne '') { + if ($list_name ne '') { # add message to list queue my $message_text; @@ -152,11 +171,11 @@ } my $id = $nos->add_message_to_list( - list => $queue_opt, + list => $list_name, message => $message_text, ); - print "added message $id to list $queue_opt\n"; + print "added message $id to list $list_name\n"; } else { # list messages in queue @@ -179,6 +198,7 @@ } + =item --send[=list_name] Send e-mails waiting in queue, or with optional argument, just send messages @@ -186,9 +206,10 @@ =cut -} elsif (defined($send_opt)) { +} elsif (defined($list_name = $opt->{'send'})) { + + $nos->send_queued_messages($list_name); - $nos->send_queued_messages($send_opt); =item --inbox=list_name @@ -196,12 +217,12 @@ =cut -} elsif ($inbox_opt) { +} elsif ($opt->{'inbox'}) { warn "inbox option is not implemented"; } else { - die "see perldoc $0 for help"; + die "see perldoc $0 for help\n"; } =back