--- trunk/sender.pl 2005/05/18 13:12:54 45 +++ trunk/sender.pl 2005/08/22 20:24:04 72 @@ -2,7 +2,7 @@ use strict; use blib; -use Nos; +use Nos 0.7; use Getopt::Long; =head1 NAME @@ -11,15 +11,17 @@ =head1 SYNOPSYS - sender.pl --new=mylist + sender.pl --create=mylist + sender.pl --drop=mylist sender.pl --add=mylist members.txt + sender.pl --delete=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" + mylist: "| cd /path/to && ./sender.pl --inbox=mylist" =head2 Command options @@ -32,14 +34,20 @@ my $opt; my $result = GetOptions( - "new=s" => \$opt->{'new'}, + "create=s" => \$opt->{'create'}, + "drop=s" => \$opt->{'drop'}, "list:s" => \$opt->{'list'}, "add=s" => \$opt->{'add'}, + "delete=s" => \$opt->{'delete'}, "queue:s" => \$opt->{'queue'}, "send:s" => \$opt->{'send'}, "inbox=s" => \$opt->{'inbox'}, "debug" => \$debug, "verbose" => \$verbose, + "from=s" => \$opt->{'from'}, + "driver=s" => \$opt->{'email_send_driver'}, + "sleep=i" => \$opt->{'sleep'}, + "aliases=s" => \$opt->{'aliases'}, ); my $nos = new Nos( @@ -68,28 +76,61 @@ my $list_name; +=item --aliases=/full/path/to/aliases -=item --new=list_name my-list@example.com +Optional parametar C<--aliases> can be used to specify aliases file other +than default C. + +=cut + +my $aliases = $opt->{'aliases'} || '/etc/aliases'; + + +=item --create=list_name my-list@example.com Adds new list. You can also feed list name as first line to C. +You can also add C<--from='Full name of list'> to specify full name (comment) +in outgoing e-mail. + =cut -if ($list_name = $opt->{'new'}) { +if ($list_name = $opt->{'create'}) { my $email = shift @ARGV || <>; chomp($email); die "need e-mail address for list (as argument or on STDIN)\n" unless ($email); - my $id = $nos->new_list( + my $id = $nos->create_list( list => $list_name, + from => ($opt->{'from'} || ''), email => $email, + aliases => $aliases, ) || die "can't add list $list_name\n"; print "added list $list_name with ID $id\n"; +=item --drop=list_name + +Remove list. + +Optional parametar C<--aliases='/full/path/to/aliases'> can be used to +specify aliases file other than C. + +=cut + +} elsif ($list_name = $opt->{'drop'}) { + + my $id = $nos->drop_list( + list => $list_name, + aliases => $aliases, + ) || die "can't remove list $list_name\n"; + + print "drop list $list_name with ID $id\n"; + + =item --list[=list_name] List all available lists and users on them. @@ -110,9 +151,9 @@ } foreach my $list (@lists) { - print $list->name," <",$list->email,">\n"; + print $list->name,": ",$list->from_addr," <",$list->email,">\n"; foreach my $u ($nos->list_members( list => $list->name )) { - print "\t",$u->{'name'}, " <", $u->{'email'}, ">\n"; + print "\t",$u->{'name'}, " <", $u->{'email'}, ">",( $u->{'ext_id'} ? ' ['.$u->{'ext_id'}.']' : '' ),"\n"; } } @@ -129,9 +170,7 @@ } elsif ($list_name = $opt->{'add'}) { - my $list = $lists->find_or_create({ - name => $list_name, - }) || die "can't add list $list_name\n"; + my $list = $nos->_get_list($list_name) || die "can't find list $list_name\n"; my $added = 0; @@ -145,6 +184,28 @@ print "list ",$list->name," has $added users\n"; +=item --delete=list_name + +Delete users from list. User e-mails can be stored in file (which can be +supplied as argument) or read from C. + +=cut +} elsif ($list_name = $opt->{'delete'}) { + + my $list = $nos->_get_list($list_name) || die "can't find list $list_name\n"; + + my $deleted = 0; + + while(<>) { + chomp; + next if (/^#/ || /^\s*$/); + my $email = $_; + $deleted++ if ($nos->delete_member_from_list( email => $email, list => $list_name )); + } + + print "list ",$list->name," lost $deleted users\n"; + + =item --queue[=list_name] Queue message for later delivery. Message can be read from file (specified as @@ -199,11 +260,29 @@ Send e-mails waiting in queue, or with optional argument, just send messages for single list. +Optional argument C<--driver=smtp> forces sending using SMTP server at +localhost (127.0.0.1). + +Optional argument C<--sleep=42> defines that sender will sleep 42 seconds +between sending e-mail. + =cut } elsif (defined($list_name = $opt->{'send'})) { - $nos->send_queued_messages($list_name); + unless ($opt->{'email_send_driver'}) { + print "WARNING: this will dump debugging output to STDERR\n"; + print "enter alternative driver (e.g. smtp): "; + my $d = ; + chomp($d); + $opt->{'email_send_driver'} = $d; + } + + $nos->send_queued_messages( + list => $list_name, + driver => $opt->{'email_send_driver'}, + sleep => $opt->{'sleep'}, + ); =item --inbox=list_name