--- trunk/sender.pl 2005/05/15 16:29:44 16 +++ trunk/sender.pl 2005/05/15 22:12:31 23 @@ -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,40 +98,29 @@ 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(<>) { chomp; next if (/^#/ || /^\s*$/); my ($email, $name) = split(/\s+/,$_, 2); - $name ||= ''; - if (! Email::Valid->address($email)) { - print "SKIPPING $name <$email>\n"; - next; - } - print "# $name <$email>\n"; - my $this_user = $users->find_or_create({ - email => $email, - full_name => $name, - }) || die "can't find or create member\n"; - my $user_on_list = $user_list->find_or_create({ - user_id => $this_user->id, - list_id => $list->id, - }) || die "can't add user to list"; - $added++; - } - - foreach my $c_name ($loader->tables) { - my $c = $loader->find_class($c_name)|| die "can't find $c_name"; - $c->dbi_commit(); + $added++ if ($nos->add_member_to_list( email => $email, name => $name, list => $add_opt )); } print "list ",$list->name," has $added users\n"; @@ -209,42 +196,7 @@ } elsif (defined($send_opt)) { - my $my_q; - if ($send_opt ne '') { - my $l_id = $lists->search_like( name => $send_opt )->first || - die "can't find list $send_opt"; - $my_q = $queue->search_like( list_id => $l_id ) || - die "can't find list $send_opt"; - } else { - $my_q = $queue->retrieve_all; - } - - while (my $m = $my_q->next) { - next if ($m->all_sent); - - print "sending message ",$m->message_id," enqueued on ",$m->date," to list ",$m->list_id->name,"\n"; - my $msg = $m->message_id->message; - - 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"; - $sent->create({ - message_id => $m->message_id, - user_id => $u->user_id, - }); - $sent->dbi_commit; - } - } - $m->all_sent(1); - $m->update; - $m->dbi_commit; - } + $nos->send_queued_messages($send_opt); } else { die "see perldoc $0 for help"; @@ -266,6 +218,10 @@ Dump more info on screen. +=item --email + +Used to specify e-mail address where needed. + =back