2 |
|
|
3 |
use strict; |
use strict; |
4 |
use blib; |
use blib; |
5 |
use Nos; |
use Nos 0.7; |
6 |
use Getopt::Long; |
use Getopt::Long; |
7 |
|
use Pod::Usage; |
8 |
|
|
9 |
=head1 NAME |
=head1 NAME |
10 |
|
|
11 |
sender.pl - command line notify sender utility |
sender.pl - command line notify sender utility |
12 |
|
|
13 |
=head1 SYNOPSYS |
=head1 SYNOPSIS |
14 |
|
|
15 |
sender.pl --new=mylist |
sender.pl --create=mylist |
16 |
|
sender.pl --drop=mylist |
17 |
sender.pl --add=mylist members.txt |
sender.pl --add=mylist members.txt |
18 |
sender.pl --delete=mylist members.txt |
sender.pl --delete=mylist members.txt |
19 |
sender.pl --list[=mylist] |
sender.pl --list[=mylist] |
20 |
sender.pl --queue[=mylist message.txt] |
sender.pl --queue[=mylist message.txt] |
21 |
sender.pl --send=mylist |
sender.pl --send=mylist |
22 |
|
sender.pl --help |
23 |
|
sender.pl --man |
24 |
|
|
25 |
In C</etc/aliases> something like: |
=head1 OPTIONS |
|
|
|
|
mylist: "| cd /path/to && ./sender.pl --inbox=mylist" |
|
|
|
|
|
=head2 Command options |
|
26 |
|
|
27 |
=over 20 |
=over 20 |
28 |
|
|
33 |
my $opt; |
my $opt; |
34 |
|
|
35 |
my $result = GetOptions( |
my $result = GetOptions( |
36 |
"new=s" => \$opt->{'new'}, |
"create=s" => \$opt->{'create'}, |
37 |
|
"drop=s" => \$opt->{'drop'}, |
38 |
"list:s" => \$opt->{'list'}, |
"list:s" => \$opt->{'list'}, |
39 |
"add=s" => \$opt->{'add'}, |
"add=s" => \$opt->{'add'}, |
40 |
"delete=s" => \$opt->{'delete'}, |
"delete=s" => \$opt->{'delete'}, |
47 |
"driver=s" => \$opt->{'email_send_driver'}, |
"driver=s" => \$opt->{'email_send_driver'}, |
48 |
"sleep=i" => \$opt->{'sleep'}, |
"sleep=i" => \$opt->{'sleep'}, |
49 |
"aliases=s" => \$opt->{'aliases'}, |
"aliases=s" => \$opt->{'aliases'}, |
50 |
); |
"help" => \$opt->{'help'}, |
51 |
|
"man" => \$opt->{'man'} |
52 |
|
) || pod2usage(-verbose => 0); |
53 |
|
|
54 |
|
pod2usage(-verbose => 1) if ($opt->{'help'}); |
55 |
|
pod2usage(-verbose => 2) if ($opt->{'man'}); |
56 |
|
|
57 |
my $nos = new Nos( |
my $nos = new Nos( |
58 |
dsn => 'dbi:Pg:dbname=notices', |
dsn => 'dbi:Pg:dbname=notices', |
80 |
|
|
81 |
my $list_name; |
my $list_name; |
82 |
|
|
83 |
|
=item --aliases=/full/path/to/aliases |
84 |
|
|
85 |
|
Optional parametar C<--aliases> can be used to specify aliases file other |
86 |
|
than default C</etc/aliases>. |
87 |
|
|
88 |
|
=cut |
89 |
|
|
90 |
=item --new=list_name my-list@example.com |
my $aliases = $opt->{'aliases'} || '/etc/aliases'; |
91 |
|
|
92 |
|
|
93 |
|
=item --create=list_name my-list@example.com |
94 |
|
|
95 |
Adds new list. You can also feed list name as first line to C<STDIN>. |
Adds new list. You can also feed list name as first line to C<STDIN>. |
96 |
|
|
97 |
You can also add C<--from='Full name of list'> to specify full name (comment) |
You can also add C<--from='Full name of list'> to specify full name (comment) |
98 |
in outgoing e-mail. |
in outgoing e-mail. |
99 |
|
|
|
Optional parametar C<--aliases='/full/path/to/aliases'> can be used to |
|
|
specify aliases file other than C</etc/aliases>. |
|
|
|
|
100 |
=cut |
=cut |
101 |
|
|
102 |
if ($list_name = $opt->{'new'}) { |
if ($list_name = $opt->{'create'}) { |
103 |
|
|
104 |
my $email = shift @ARGV || <>; |
my $email = shift @ARGV || <>; |
105 |
chomp($email); |
chomp($email); |
106 |
|
|
107 |
die "need e-mail address for list (as argument or on STDIN)\n" unless ($email); |
die "need e-mail address for list (as argument or on STDIN)\n" unless ($email); |
108 |
|
|
109 |
my $aliases = $opt->{'aliases'} || '/etc/aliases'; |
my $id = $nos->create_list( |
|
|
|
|
my $id = $nos->new_list( |
|
110 |
list => $list_name, |
list => $list_name, |
111 |
from => ($opt->{'from'} || ''), |
from => ($opt->{'from'} || ''), |
112 |
email => $email, |
email => $email, |
116 |
print "added list $list_name with ID $id\n"; |
print "added list $list_name with ID $id\n"; |
117 |
|
|
118 |
|
|
119 |
|
=item --drop=list_name |
120 |
|
|
121 |
|
Remove list. |
122 |
|
|
123 |
|
Optional parametar C<--aliases='/full/path/to/aliases'> can be used to |
124 |
|
specify aliases file other than C</etc/aliases>. |
125 |
|
|
126 |
|
=cut |
127 |
|
|
128 |
|
} elsif ($list_name = $opt->{'drop'}) { |
129 |
|
|
130 |
|
my $id = $nos->drop_list( |
131 |
|
list => $list_name, |
132 |
|
aliases => $aliases, |
133 |
|
) || die "can't remove list $list_name\n"; |
134 |
|
|
135 |
|
print "drop list $list_name with ID $id\n"; |
136 |
|
|
137 |
|
|
138 |
=item --list[=list_name] |
=item --list[=list_name] |
139 |
|
|
140 |
List all available lists and users on them. |
List all available lists and users on them. |
309 |
|
|
310 |
|
|
311 |
} else { |
} else { |
312 |
die "see perldoc $0 for help\n"; |
pod2usage(-verbose=>0); |
313 |
} |
} |
314 |
|
|
315 |
=back |
=back |
330 |
|
|
331 |
=back |
=back |
332 |
|
|
333 |
|
=head1 DESCRIPTION |
334 |
|
|
335 |
|
This command will use notice-sender C<Nos.pm> module directly to make modifications on lists |
336 |
|
or with C<--inbox> option server as incomming mail filter. |
337 |
|
|
338 |
=head1 AUTHOR |
=head1 AUTHOR |
339 |
|
|