--- trunk/sender.pl 2005/05/15 22:30:54 24 +++ trunk/sender.pl 2005/05/16 22:32:58 32 @@ -11,11 +11,16 @@ =head1 SYNOPSYS + sender.pl --new=mylist sender.pl --add=mylist members.txt sender.pl --list[=mylist] sender.pl --queue[=mylist message.txt] sender.pl --send=mylist +In C something like: + + mylist: "| /path/to/sender.pl --inbox=mylist" + =head2 Command options =over 20 @@ -24,20 +29,18 @@ my $debug = 0; my $verbose = 0; -my $list_opt; -my $add_opt; -my $queue_opt; -my $send_opt; -my $email_opt; +my $opt; my $result = GetOptions( - "list:s" => \$list_opt, - "add=s" => \$add_opt, - "queue:s" => \$queue_opt, - "send:s" => \$send_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( @@ -64,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] @@ -74,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; } @@ -90,6 +118,7 @@ } } + =item --add=list_name Add users to list. Users are stored in file (which can be supplied as @@ -103,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; @@ -120,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 @@ -135,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; @@ -145,12 +170,12 @@ $message_text .= $_; } - my $id = $nos->add_message_to_queue( - list => $queue_opt, + my $id = $nos->add_message_to_list( + list => $list_name, message => $message_text, - ); + ) || die "can't add message to list $list_name\n"; - print "added message $id to list $queue_opt\n"; + print "added message $id to list $list_name\n"; } else { # list messages in queue @@ -173,6 +198,7 @@ } + =item --send[=list_name] Send e-mails waiting in queue, or with optional argument, just send messages @@ -180,12 +206,23 @@ =cut -} elsif (defined($send_opt)) { +} elsif (defined($list_name = $opt->{'send'})) { + + $nos->send_queued_messages($list_name); + + +=item --inbox=list_name + +Feed incomming message back into notice sender. + +=cut + +} elsif ($opt->{'inbox'}) { - $nos->send_queued_messages($send_opt); + warn "inbox option is not implemented"; } else { - die "see perldoc $0 for help"; + die "see perldoc $0 for help\n"; } =back