--- trunk/sender.pl 2005/05/15 16:25:01 15 +++ trunk/sender.pl 2005/05/15 21:35:15 21 @@ -1,11 +1,9 @@ #!/usr/bin/perl -w use strict; -use Class::DBI::Loader::Pg; +use blib; +use Nos; use Getopt::Long; -use Mail::CheckUser qw(check_email); -use Email::Valid; -use Email::Send; =head1 NAME @@ -30,6 +28,7 @@ my $add_opt; my $queue_opt; my $send_opt; +my $email_opt; my $result = GetOptions( "list:s" => \$list_opt, @@ -38,20 +37,19 @@ "send:s" => \$send_opt, "debug" => \$debug, "verbose" => \$verbose, + "email=s" => \$email_opt, ); - -my $loader = Class::DBI::Loader::Pg->new( - debug => $debug, - dsn => "dbi:Pg:dbname=notices", - user => "dpavlin", - password => "", - namespace => "Noticer", -# additional_classes => qw/Class::DBI::AbstractSearch/, -# additional_base_classes => qw/My::Stuff/, - relationships => 1, +my $nos = new Nos( + dsn => 'dbi:Pg:dbname=notices', + user => 'dpavlin', + passwd => '', + debug => $debug, + verbose => $verbose, ); +my $loader = $nos->{'loader'} || die "can't find loader?"; + my $lists = $loader->find_class('lists'); my $users = $loader->find_class('users'); my $user_list = $loader->find_class('user_list'); @@ -85,7 +83,7 @@ } foreach my $list (@lists) { - print $list->name,"\n"; + print $list->name," <",$list->email,">\n"; foreach my $user_on_list ($user_list->search(list_id => $list->id)) { my $user = $users->retrieve( id => $user_on_list->user_id ); print "\t",$user->full_name," <", $user->email, ">\n"; @@ -100,14 +98,22 @@ email@example.com Optional full name of person dpavlin@rot13.org Dobrica Pavlinusic +You may use C<--email> parametar at any time to set From: e-mail address for list. +B. + =cut } elsif ($add_opt) { - #my $noticer = $loader->find_class('Noticer') || die "can't find my class!"; my $list = $lists->find_or_create({ name => $add_opt, }) || die "can't add list $add_opt\n"; + if ($email_opt && $list->email ne $email_opt) { + $list->email($email_opt); + $list->update; + $list->dbi_commit; + } + my $added = 0; while(<>) { @@ -143,7 +149,8 @@ Queue message for later delivery. Message can be read from file (specified as argument) or read from C. -This options without optional parametars it will display current queue. +This option without optional parametar will display pending queue. If you +add C<--verbose> flag, it will display all messages in queue. =cut @@ -201,8 +208,8 @@ =item --send[=list_name] -Send e-mail waiting in queue for all lists, or with optional argument for -just single list. +Send e-mails waiting in queue, or with optional argument, just send messages +for single list. =cut @@ -226,13 +233,17 @@ foreach my $u ($user_list->search(list_id => $m->list_id)) { - my $hdr = "To: ".$u->user_id->full_name." <". $u->user_id->email. ">\n"; - if ($sent->search( message_id => $m->message_id, user_id => $u->user_id )) { print "SKIP ",$u->user_id->email," message allready sent\n"; } else { print "\t",$u->user_id->email,"\n"; - send IO => "$hdr\n$msg"; + + my $hdr = "From: " . $u->list_id->name . " <" . $u->list_id->email . ">\n" . + "To: " . $u->user_id->full_name . " <". $u->user_id->email. ">\n"; + + # FIXME do real sending :-) + $nos->send_email("$hdr\n$msg"); + $sent->create({ message_id => $m->message_id, user_id => $u->user_id, @@ -265,6 +276,10 @@ Dump more info on screen. +=item --email + +Used to specify e-mail address where needed. + =back