--- trunk/sender.pl 2005/05/18 09:46:49 42 +++ trunk/sender.pl 2005/08/02 18:28:57 69 @@ -13,13 +13,14 @@ sender.pl --new=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 @@ -35,11 +36,16 @@ "new=s" => \$opt->{'new'}, "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( @@ -73,6 +79,12 @@ 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. + +Optional parametar C<--aliases='/full/path/to/aliases'> can be used to +specify aliases file other than C. + =cut if ($list_name = $opt->{'new'}) { @@ -82,9 +94,13 @@ die "need e-mail address for list (as argument or on STDIN)\n" unless ($email); + my $aliases = $opt->{'aliases'} || '/etc/aliases'; + my $id = $nos->new_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"; @@ -110,9 +126,9 @@ } foreach my $list (@lists) { - print $list->name," <",$list->email,">\n"; - foreach my $user_on_list ($user_list->search(list_id => $list->id)) { - print "\t",$user_on_list->user_id->full_name," <", $user_on_list->user_id->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'}, ">",( $u->{'ext_id'} ? ' ['.$u->{'ext_id'}.']' : '' ),"\n"; } } @@ -129,9 +145,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 +159,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 +235,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