/[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 17 by dpavlin, Sun May 15 16:32:36 2005 UTC revision 20 by dpavlin, Sun May 15 21:19:26 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 30  my $list_opt; Line 28  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 38  my $result = GetOptions( Line 37  my $result = GetOptions(
37          "send:s" => \$send_opt,          "send:s" => \$send_opt,
38          "debug" => \$debug,          "debug" => \$debug,
39          "verbose" => \$verbose,          "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');
# Line 100  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) {
# Line 107  argument) or read from C<STDIN>. List sh Line 108  argument) or read from C<STDIN>. List sh
108          my $list = $lists->find_or_create({          my $list = $lists->find_or_create({
109                  name => $add_opt,                  name => $add_opt,
110          }) || die "can't add list $add_opt\n";          }) || die "can't add list $add_opt\n";
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    
# Line 227  for single list. Line 233  for single list.
233    
234                  foreach my $u ($user_list->search(list_id => $m->list_id)) {                  foreach my $u ($user_list->search(list_id => $m->list_id)) {
235    
                         my $hdr = "To: ".$u->user_id->full_name." <". $u->user_id->email. ">\n";  
   
236                          if ($sent->search( message_id => $m->message_id, user_id => $u->user_id )) {                          if ($sent->search( message_id => $m->message_id, user_id => $u->user_id )) {
237                                  print "SKIP ",$u->user_id->email," message allready sent\n";                                  print "SKIP ",$u->user_id->email," message allready sent\n";
238                          } else {                          } else {
239                                  print "\t",$u->user_id->email,"\n";                                  print "\t",$u->user_id->email,"\n";
240                                  send IO => "$hdr\n$msg";  
241                                    my $hdr = "From: " . $u->list_id->name . " <" . $u->list_id->email . ">\n" .
242                                            "To: " . $u->user_id->full_name . " <". $u->user_id->email. ">\n";
243    
244                                    # FIXME do real sending :-)
245                                    $nos->send_email("$hdr\n$msg");
246    
247                                  $sent->create({                                  $sent->create({
248                                          message_id => $m->message_id,                                          message_id => $m->message_id,
249                                          user_id => $u->user_id,                                          user_id => $u->user_id,
# Line 266  Turn on debugging output from C<Class::D Line 276  Turn on debugging output from C<Class::D
276    
277  Dump more info on screen.  Dump more info on screen.
278    
279    =item --email
280    
281    Used to specify e-mail address where needed.
282    
283  =back  =back
284    
285    

Legend:
Removed from v.17  
changed lines
  Added in v.20

  ViewVC Help
Powered by ViewVC 1.1.26