--- trunk/sender.pl 2005/05/24 16:44:34 49 +++ trunk/sender.pl 2006/12/19 15:04:05 93 @@ -1,27 +1,28 @@ #!/usr/bin/perl -w use strict; -use blib; -use Nos; +use lib 'lib'; +use Nos 0.9; use Getopt::Long; +use Pod::Usage; =head1 NAME sender.pl - command line notify sender utility -=head1 SYNOPSYS +=head1 SYNOPSIS - 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 + sender.pl --help + sender.pl --man -In C something like: - - mylist: "| cd /path/to && ./sender.pl --inbox=mylist" - -=head2 Command options +=head1 OPTIONS =over 20 @@ -32,9 +33,11 @@ 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'}, @@ -43,7 +46,13 @@ "from=s" => \$opt->{'from'}, "driver=s" => \$opt->{'email_send_driver'}, "sleep=i" => \$opt->{'sleep'}, -); + "aliases=s" => \$opt->{'aliases'}, + "help" => \$opt->{'help'}, + "man" => \$opt->{'man'} +) || pod2usage(-verbose => 0); + +pod2usage(-verbose => 1) if ($opt->{'help'}); +pod2usage(-verbose => 2) if ($opt->{'man'}); my $nos = new Nos( dsn => 'dbi:Pg:dbname=notices', @@ -71,8 +80,17 @@ my $list_name; +=item --aliases=/full/path/to/aliases + +Optional parametar C<--aliases> can be used to specify aliases file other +than default C. + +=cut + +my $aliases = $opt->{'aliases'} || '/etc/aliases'; + -=item --new=list_name my-list@example.com +=item --create=list_name my-list@example.com Adds new list. You can also feed list name as first line to C. @@ -81,22 +99,42 @@ =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. @@ -117,9 +155,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"; } } @@ -136,9 +174,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; @@ -152,6 +188,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 @@ -216,10 +274,19 @@ } elsif (defined($list_name = $opt->{'send'})) { + 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'}, + verbose => 1, ); @@ -243,7 +310,7 @@ } else { - die "see perldoc $0 for help\n"; + pod2usage(-verbose=>0); } =back @@ -264,7 +331,10 @@ =back +=head1 DESCRIPTION +This command will use notice-sender C module directly to make modifications on lists +or with C<--inbox> option server as incomming mail filter. =head1 AUTHOR