/[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 14 by dpavlin, Sun May 15 14:20:08 2005 UTC revision 22 by dpavlin, Sun May 15 21:52:56 2005 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2    
3  use strict;  use strict;
4  use Class::DBI::Loader::Pg;  use blib;
5    use Nos;
6  use Getopt::Long;  use Getopt::Long;
 use Mail::CheckUser qw(check_email);  
 use Email::Valid;  
 use Email::Send;  
7    
8  =head1 NAME  =head1 NAME
9    
# Line 18  sender.pl - command line notify sender u Line 16  sender.pl - command line notify sender u
16   sender.pl --queue[=mylist message.txt]   sender.pl --queue[=mylist message.txt]
17   sender.pl --send=mylist   sender.pl --send=mylist
18    
19  =head2 All options  =head2 Command options
20    
21  =over 20  =over 20
22    
 =item --debug  
   
 Turn on debugging output from C<Class::DBI>  
   
23  =cut  =cut
24    
25  my $debug = 0;  my $debug = 0;
26    my $verbose = 0;
27  my $list_opt;  my $list_opt;
28  my $add_opt;  my $add_opt;
29  my $queue_opt;  my $queue_opt;
30  my $send_opt;  my $send_opt;
31    my $email_opt;
32    
33  my $result = GetOptions(  my $result = GetOptions(
34          "list:s" => \$list_opt,          "list:s" => \$list_opt,
# Line 40  my $result = GetOptions( Line 36  my $result = GetOptions(
36          "queue:s" => \$queue_opt,          "queue:s" => \$queue_opt,
37          "send:s" => \$send_opt,          "send:s" => \$send_opt,
38          "debug" => \$debug,          "debug" => \$debug,
39            "verbose" => \$verbose,
40            "email=s" => \$email_opt,
41  );  );
42    
43    my $nos = new Nos(
44  my $loader = Class::DBI::Loader::Pg->new(          dsn => 'dbi:Pg:dbname=notices',
45          debug           => $debug,          user => 'dpavlin',
46          dsn             => "dbi:Pg:dbname=notices",          passwd => '',
47          user            => "dpavlin",          debug => $debug,
48          password        => "",          verbose => $verbose,
         namespace       => "Noticer",  
 #       additional_classes      => qw/Class::DBI::AbstractSearch/,  
 #       additional_base_classes => qw/My::Stuff/,  
         relationships   => 1,  
49  );  );
50    
51    my $loader = $nos->{'loader'} || die "can't find loader?";
52    
53  my $lists = $loader->find_class('lists');  my $lists = $loader->find_class('lists');
54  my $users = $loader->find_class('users');  my $users = $loader->find_class('users');
55  my $user_list = $loader->find_class('user_list');  my $user_list = $loader->find_class('user_list');
56  my $messages = $loader->find_class('messages');  my $messages = $loader->find_class('messages');
57  my $queue = $loader->find_class('queue');  my $queue = $loader->find_class('queue');
58    my $sent = $loader->find_class('sent');
59    
60  $queue->set_sql( list_queue => qq{  $queue->set_sql( list_queue => qq{
61          SELECT messages.message, messages.date AS message_date, lists.name AS list          SELECT messages.message, messages.date AS date, lists.name AS list
62          FROM queue          FROM queue
63          JOIN messages on message_id = messages.id          JOIN messages on message_id = messages.id
64          JOIN lists on list_id = lists.id          JOIN lists on list_id = lists.id
# Line 86  if (defined($list_opt)) { Line 83  if (defined($list_opt)) {
83          }          }
84    
85          foreach my $list (@lists) {          foreach my $list (@lists) {
86                  print $list->name,"\n";                  print $list->name," <",$list->email,">\n";
87                  foreach my $user_on_list ($user_list->search(list_id => $list->id)) {                  foreach my $user_on_list ($user_list->search(list_id => $list->id)) {
88                          my $user = $users->retrieve( id => $user_on_list->user_id );                          my $user = $users->retrieve( id => $user_on_list->user_id );
89                          print "\t",$user->full_name," <", $user->email, ">\n";                          print "\t",$user->full_name," <", $user->email, ">\n";
# Line 101  argument) or read from C<STDIN>. List sh Line 98  argument) or read from C<STDIN>. List sh
98   email@example.com      Optional full name of person   email@example.com      Optional full name of person
99   dpavlin@rot13.org      Dobrica Pavlinusic   dpavlin@rot13.org      Dobrica Pavlinusic
100    
101    You may use C<--email> parametar at any time to set From: e-mail address for list.
102    B<This seems somewhat cludgy, and it will probably change in future>.
103    
104  =cut  =cut
105    
106  } elsif ($add_opt) {  } elsif ($add_opt) {
         #my $noticer = $loader->find_class('Noticer') || die "can't find my class!";  
107          my $list = $lists->find_or_create({          my $list = $lists->find_or_create({
108                  name => $add_opt,                  name => $add_opt,
109          }) || die "can't add list $add_opt\n";          }) || die "can't add list $add_opt\n";
110    
111            if ($email_opt && $list->email ne $email_opt) {
112                    $list->email($email_opt);
113                    $list->update;
114                    $list->dbi_commit;
115            }
116    
117          my $added = 0;          my $added = 0;
118    
119          while(<>) {          while(<>) {
120                  chomp;                  chomp;
121                  next if (/^#/ || /^\s*$/);                  next if (/^#/ || /^\s*$/);
122                  my ($email, $name) = split(/\s+/,$_, 2);                  my ($email, $name) = split(/\s+/,$_, 2);
123                    $name ||= '';
124                  if (! Email::Valid->address($email)) {                  if (! Email::Valid->address($email)) {
125                          print "SKIPPING $name <$email>\n";                          print "SKIPPING $name <$email>\n";
126                          next;                          next;
# Line 143  argument) or read from C<STDIN>. List sh Line 149  argument) or read from C<STDIN>. List sh
149  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
150  argument) or read from C<STDIN>.  argument) or read from C<STDIN>.
151    
152  This options without optional parametars it will display current queue.  This option without optional parametar will display pending queue. If you
153    add C<--verbose> flag, it will display all messages in queue.
154    
155  =cut  =cut
156    
# Line 182  This options without optional parametars Line 189  This options without optional parametars
189                  # list messages in queue                          # list messages in queue        
190    
191                  foreach my $m ($queue->retrieve_all) {                  foreach my $m ($queue->retrieve_all) {
192                          my $l = sprintf("%-10s %15s : ", $m->list_id->name, $m->message_id->date);                          next if ($m->all_sent && ! $verbose);
193                          $l .= substr($m->message_id->message, 0, 79 - length($l));  
194                          $l =~ s/[\n\r]/ /gs;                          my $l = $m->all_sent ? 'S' : 'Q';
195    
196                            my $date = $m->message_id->date;
197                            $date =~ s/\..+$//;
198                            my $msg = $m->message_id->message;
199                            $msg =~ s/\s+/ /gs;
200    
201                            $l .= sprintf(" %-10s %15s : ", $m->list_id->name, $date);
202                            $l .= substr($msg, 0, 79 - length($l));
203    
204                          print "$l\n";                          print "$l\n";
205                  }                  }
206    
# Line 192  This options without optional parametars Line 208  This options without optional parametars
208    
209  =item --send[=list_name]  =item --send[=list_name]
210    
211  Send e-mail waiting in queue for all lists, or with optional argument for  Send e-mails waiting in queue, or with optional argument, just send messages
212  just single list.  for single list.
213    
214  =cut  =cut
215    
216  } elsif (defined($send_opt)) {  } elsif (defined($send_opt)) {
217    
218            $nos->send_queued_messages($send_opt);
         die "send option not yet implemented";  
   
         my @q;  
         if ($send_opt ne '') {  
 #               @q => $queue->search( name => 'foo' );  
         }  
         foreach my $q (@q) {  
                   
         }  
219    
220  } else  {  } else  {
221          die "see perldoc $0 for help";          die "see perldoc $0 for help";
# Line 216  just single list. Line 223  just single list.
223    
224  =back  =back
225    
226    
227    
228    =head2 Helper options
229    
230    =over 20
231    
232    =item --debug
233    
234    Turn on debugging output from C<Class::DBI>
235    
236    =item --verbose
237    
238    Dump more info on screen.
239    
240    =item --email
241    
242    Used to specify e-mail address where needed.
243    
244    =back
245    
246    
247    
248  =head1 AUTHOR  =head1 AUTHOR
249    
250  Dobrica Pavlinusic <dpavlin@rot13.org>  Dobrica Pavlinusic <dpavlin@rot13.org>

Legend:
Removed from v.14  
changed lines
  Added in v.22

  ViewVC Help
Powered by ViewVC 1.1.26