3 |
use strict; |
use strict; |
4 |
use Class::DBI::Loader::Pg; |
use Class::DBI::Loader::Pg; |
5 |
use Getopt::Long; |
use Getopt::Long; |
|
use Mail::CheckUser qw(check_email); |
|
6 |
use Email::Valid; |
use Email::Valid; |
7 |
use Email::Send; |
use Email::Send; |
8 |
|
|
29 |
my $add_opt; |
my $add_opt; |
30 |
my $queue_opt; |
my $queue_opt; |
31 |
my $send_opt; |
my $send_opt; |
32 |
|
my $email_opt; |
33 |
|
|
34 |
my $result = GetOptions( |
my $result = GetOptions( |
35 |
"list:s" => \$list_opt, |
"list:s" => \$list_opt, |
38 |
"send:s" => \$send_opt, |
"send:s" => \$send_opt, |
39 |
"debug" => \$debug, |
"debug" => \$debug, |
40 |
"verbose" => \$verbose, |
"verbose" => \$verbose, |
41 |
|
"email=s" => \$email_opt, |
42 |
); |
); |
43 |
|
|
44 |
|
|
86 |
} |
} |
87 |
|
|
88 |
foreach my $list (@lists) { |
foreach my $list (@lists) { |
89 |
print $list->name,"\n"; |
print $list->name," <",$list->email,">\n"; |
90 |
foreach my $user_on_list ($user_list->search(list_id => $list->id)) { |
foreach my $user_on_list ($user_list->search(list_id => $list->id)) { |
91 |
my $user = $users->retrieve( id => $user_on_list->user_id ); |
my $user = $users->retrieve( id => $user_on_list->user_id ); |
92 |
print "\t",$user->full_name," <", $user->email, ">\n"; |
print "\t",$user->full_name," <", $user->email, ">\n"; |
101 |
email@example.com Optional full name of person |
email@example.com Optional full name of person |
102 |
dpavlin@rot13.org Dobrica Pavlinusic |
dpavlin@rot13.org Dobrica Pavlinusic |
103 |
|
|
104 |
|
You may use C<--email> parametar at any time to set From: e-mail address for list. |
105 |
|
B<This seems somewhat cludgy, and it will probably change in future>. |
106 |
|
|
107 |
=cut |
=cut |
108 |
|
|
109 |
} elsif ($add_opt) { |
} elsif ($add_opt) { |
111 |
my $list = $lists->find_or_create({ |
my $list = $lists->find_or_create({ |
112 |
name => $add_opt, |
name => $add_opt, |
113 |
}) || die "can't add list $add_opt\n"; |
}) || die "can't add list $add_opt\n"; |
114 |
|
if ($email_opt && $list->email ne $email_opt) { |
115 |
|
$list->email($email_opt); |
116 |
|
$list->update; |
117 |
|
$list->dbi_commit; |
118 |
|
} |
119 |
|
|
120 |
my $added = 0; |
my $added = 0; |
121 |
|
|
152 |
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 |
153 |
argument) or read from C<STDIN>. |
argument) or read from C<STDIN>. |
154 |
|
|
155 |
This options without optional parametars it will display current queue. |
This option without optional parametar will display pending queue. If you |
156 |
|
add C<--verbose> flag, it will display all messages in queue. |
157 |
|
|
158 |
=cut |
=cut |
159 |
|
|
211 |
|
|
212 |
=item --send[=list_name] |
=item --send[=list_name] |
213 |
|
|
214 |
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 |
215 |
just single list. |
for single list. |
216 |
|
|
217 |
=cut |
=cut |
218 |
|
|
236 |
|
|
237 |
foreach my $u ($user_list->search(list_id => $m->list_id)) { |
foreach my $u ($user_list->search(list_id => $m->list_id)) { |
238 |
|
|
|
my $hdr = "To: ".$u->user_id->full_name." <". $u->user_id->email. ">\n"; |
|
|
|
|
239 |
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 )) { |
240 |
print "SKIP ",$u->user_id->email," message allready sent\n"; |
print "SKIP ",$u->user_id->email," message allready sent\n"; |
241 |
} else { |
} else { |
242 |
print "\t",$u->user_id->email,"\n"; |
print "\t",$u->user_id->email,"\n"; |
243 |
|
|
244 |
|
my $hdr = "From: " . $u->list_id->name . " <" . $u->list_id->email . ">\n" . |
245 |
|
"To: " . $u->user_id->full_name . " <". $u->user_id->email. ">\n"; |
246 |
|
|
247 |
|
# FIXME do real sending :-) |
248 |
send IO => "$hdr\n$msg"; |
send IO => "$hdr\n$msg"; |
249 |
|
|
250 |
$sent->create({ |
$sent->create({ |
251 |
message_id => $m->message_id, |
message_id => $m->message_id, |
252 |
user_id => $u->user_id, |
user_id => $u->user_id, |
279 |
|
|
280 |
Dump more info on screen. |
Dump more info on screen. |
281 |
|
|
282 |
|
=item --email |
283 |
|
|
284 |
|
Used to specify e-mail address where needed. |
285 |
|
|
286 |
=back |
=back |
287 |
|
|
288 |
|
|