/[notice-sender]/trunk/sender.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/sender.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 30 by dpavlin, Mon May 16 21:54:41 2005 UTC revision 69 by dpavlin, Tue Aug 2 18:28:57 2005 UTC
# Line 13  sender.pl - command line notify sender u Line 13  sender.pl - command line notify sender u
13    
14   sender.pl --new=mylist   sender.pl --new=mylist
15   sender.pl --add=mylist members.txt   sender.pl --add=mylist members.txt
16     sender.pl --delete=mylist members.txt
17   sender.pl --list[=mylist]   sender.pl --list[=mylist]
18   sender.pl --queue[=mylist message.txt]   sender.pl --queue[=mylist message.txt]
19   sender.pl --send=mylist   sender.pl --send=mylist
20    
21  In C</etc/aliases> something like:  In C</etc/aliases> something like:
22    
23   mylist: "| /path/to/sender.pl --inbox=mylist"   mylist: "| cd /path/to && ./sender.pl --inbox=mylist"
24    
25  =head2 Command options  =head2 Command options
26    
# Line 35  my $result = GetOptions( Line 36  my $result = GetOptions(
36          "new=s" => \$opt->{'new'},          "new=s" => \$opt->{'new'},
37          "list:s" => \$opt->{'list'},          "list:s" => \$opt->{'list'},
38          "add=s" => \$opt->{'add'},          "add=s" => \$opt->{'add'},
39            "delete=s" => \$opt->{'delete'},
40          "queue:s" => \$opt->{'queue'},          "queue:s" => \$opt->{'queue'},
41          "send:s" => \$opt->{'send'},          "send:s" => \$opt->{'send'},
42          "inbox=s" => \$opt->{'inbox'},          "inbox=s" => \$opt->{'inbox'},
43          "debug" => \$debug,          "debug" => \$debug,
44          "verbose" => \$verbose,          "verbose" => \$verbose,
45          "email=s" => \$opt->{'email'},          "from=s" => \$opt->{'from'},
46            "driver=s" => \$opt->{'email_send_driver'},
47            "sleep=i" => \$opt->{'sleep'},
48            "aliases=s" => \$opt->{'aliases'},
49  );  );
50    
51  my $nos = new Nos(  my $nos = new Nos(
# Line 74  my $list_name; Line 79  my $list_name;
79    
80  Adds new list. You can also feed list name as first line to C<STDIN>.  Adds new list. You can also feed list name as first line to C<STDIN>.
81    
82    You can also add C<--from='Full name of list'> to specify full name (comment)
83    in outgoing e-mail.
84    
85    Optional parametar C<--aliases='/full/path/to/aliases'> can be used to
86    specify aliases file other than C</etc/aliases>.
87    
88  =cut  =cut
89    
90  if ($list_name = $opt->{'new'}) {  if ($list_name = $opt->{'new'}) {
# Line 83  if ($list_name = $opt->{'new'}) { Line 94  if ($list_name = $opt->{'new'}) {
94    
95          die "need e-mail address for list (as argument or on STDIN)\n" unless ($email);          die "need e-mail address for list (as argument or on STDIN)\n" unless ($email);
96    
97          my $l = $nos->_get_list($list_name) || $nos->_add_list(          my $aliases = $opt->{'aliases'} || '/etc/aliases';
98    
99            my $id = $nos->new_list(
100                  list => $list_name,                  list => $list_name,
101                    from => ($opt->{'from'} || ''),
102                  email => $email,                  email => $email,
103                    aliases => $aliases,
104          ) || die "can't add list $list_name\n";          ) || die "can't add list $list_name\n";
105    
106          print "added list $list_name with ID ",$l->id,"\n";          print "added list $list_name with ID $id\n";
107    
108    
109  =item --list[=list_name]  =item --list[=list_name]
# Line 111  on that list. Line 126  on that list.
126          }          }
127    
128          foreach my $list (@lists) {          foreach my $list (@lists) {
129                  print $list->name," <",$list->email,">\n";                  print $list->name,": ",$list->from_addr," <",$list->email,">\n";
130                  foreach my $user_on_list ($user_list->search(list_id => $list->id)) {                  foreach my $u ($nos->list_members( list => $list->name )) {
131                          my $user = $users->retrieve( id => $user_on_list->user_id );                          print "\t",$u->{'name'}, " <", $u->{'email'}, ">",( $u->{'ext_id'} ? ' ['.$u->{'ext_id'}.']' : '' ),"\n";
                         print "\t",$user->full_name," <", $user->email, ">\n";  
132                  }                  }
133          }          }
134    
# Line 127  argument) or read from C<STDIN>. List sh Line 141  argument) or read from C<STDIN>. List sh
141   email@example.com      Optional full name of person   email@example.com      Optional full name of person
142   dpavlin@rot13.org      Dobrica Pavlinusic   dpavlin@rot13.org      Dobrica Pavlinusic
143    
 You may use C<--email> parametar at any time to set From: e-mail address for list.  
 B<This seems somewhat cludgy, and it will probably change in future>.  
   
144  =cut  =cut
145    
146  } elsif ($list_name = $opt->{'add'}) {  } elsif ($list_name = $opt->{'add'}) {
147    
148          my $list = $lists->find_or_create({          my $list = $nos->_get_list($list_name) || die "can't find list $list_name\n";
                 name => $list_name,  
         }) || die "can't add list $list_name\n";  
149    
150          my $added = 0;          my $added = 0;
151    
# Line 150  B<This seems somewhat cludgy, and it wil Line 159  B<This seems somewhat cludgy, and it wil
159          print "list ",$list->name," has $added users\n";          print "list ",$list->name," has $added users\n";
160    
161    
162    =item --delete=list_name
163    
164    Delete users from list. User e-mails can be stored in file (which can be
165    supplied as argument) or read from C<STDIN>.
166    
167    =cut
168    } elsif ($list_name = $opt->{'delete'}) {
169    
170            my $list = $nos->_get_list($list_name) || die "can't find list $list_name\n";
171    
172            my $deleted = 0;
173    
174            while(<>) {
175                    chomp;
176                    next if (/^#/ || /^\s*$/);
177                    my $email = $_;
178                    $deleted++ if ($nos->delete_member_from_list( email => $email, list => $list_name ));
179            }
180    
181            print "list ",$list->name," lost $deleted users\n";
182    
183    
184  =item --queue[=list_name]  =item --queue[=list_name]
185    
186  Queue message for later delivery. Message can be read from file (specified as  Queue message for later delivery. Message can be read from file (specified as
# Line 173  add C<--verbose> flag, it will display a Line 204  add C<--verbose> flag, it will display a
204                  my $id = $nos->add_message_to_list(                  my $id = $nos->add_message_to_list(
205                          list => $list_name,                          list => $list_name,
206                          message => $message_text,                          message => $message_text,
207                  );                  ) || die "can't add message to list $list_name\n";
208    
209                  print "added message $id to list $list_name\n";                  print "added message $id to list $list_name\n";
210    
# Line 190  add C<--verbose> flag, it will display a Line 221  add C<--verbose> flag, it will display a
221                          my $msg = $m->message_id->message;                          my $msg = $m->message_id->message;
222                          $msg =~ s/\s+/ /gs;                          $msg =~ s/\s+/ /gs;
223    
224                          $l .= sprintf(" %-10s %15s : ", $m->list_id->name, $date);                          $l .= sprintf(" %-15s %15s : ", $m->list_id->name, $date);
225                          $l .= substr($msg, 0, 79 - length($l));                          $l .= substr($msg, 0, 79 - length($l));
226    
227                          print "$l\n";                          print "$l\n";
# Line 204  add C<--verbose> flag, it will display a Line 235  add C<--verbose> flag, it will display a
235  Send e-mails waiting in queue, or with optional argument, just send messages  Send e-mails waiting in queue, or with optional argument, just send messages
236  for single list.  for single list.
237    
238    Optional argument C<--driver=smtp> forces sending using SMTP server at
239    localhost (127.0.0.1).
240    
241    Optional argument C<--sleep=42> defines that sender will sleep 42 seconds
242    between sending e-mail.
243    
244  =cut  =cut
245    
246  } elsif (defined($list_name = $opt->{'send'})) {  } elsif (defined($list_name = $opt->{'send'})) {
247    
248          $nos->send_queued_messages($list_name);          unless ($opt->{'email_send_driver'}) {
249                    print "WARNING: this will dump debugging output to STDERR\n";
250                    print "enter alternative driver (e.g. smtp): ";
251                    my $d = <STDIN>;
252                    chomp($d);
253                    $opt->{'email_send_driver'} = $d;
254            }
255    
256            $nos->send_queued_messages(
257                    list => $list_name,
258                    driver => $opt->{'email_send_driver'},
259                    sleep => $opt->{'sleep'},
260            );
261    
262    
263  =item --inbox=list_name  =item --inbox=list_name
# Line 217  Feed incomming message back into notice Line 266  Feed incomming message back into notice
266    
267  =cut  =cut
268    
269  } elsif ($opt->{'inbox'}) {  } elsif ($list_name = $opt->{'inbox'}) {
270    
271            my $message;
272            while(<>) {
273                    $message .= $_;
274            }
275    
276            $nos->inbox_message(
277                    list => $list_name,
278                    message => $message,
279            ) || die "can't receive message for list $list_name";
280    
         warn "inbox option is not implemented";  
281    
282  } else  {  } else  {
283          die "see perldoc $0 for help\n";          die "see perldoc $0 for help\n";
# Line 241  Turn on debugging output from C<Class::D Line 299  Turn on debugging output from C<Class::D
299    
300  Dump more info on screen.  Dump more info on screen.
301    
 =item --email  
   
 Used to specify e-mail address where needed.  
   
302  =back  =back
303    
304    

Legend:
Removed from v.30  
changed lines
  Added in v.69

  ViewVC Help
Powered by ViewVC 1.1.26