root/bin/pl-subscribe

Revision 326:6fe792e6c8f1, 6.3 KB (checked in by Anselm Lingnau <anselm@…>, 9 months ago)

Big get_config() cleanup to get rid of hard_coded defaults.
We're now getting parameter defaults from a central list instead of putting
them near the get_config() calls themselves, to avoid possible inconsistencies.
If for whatever reasons parameters end up with obviously invalid values, we
still try to do the Right Thing(TM).

  • Property exe set to *
Line 
1#!/usr/bin/perl
2
3=head1 NAME
4
5pl-subscribe - Add addresses to a Lancelot list's subscriber database
6
7=head1 SYNOPSIS
8
9  pl-subscribe [-dwv?] [--[no]digest] [--[no]mail] [--[no]moderated]
10             [--[no]welcome] [--verbose] list@domain [address ...]
11
12=head1 OVERVIEW
13
14The B<pl-subscribe> command allows a list owner to add addresses to a
15list's subscriber database manually. Addresses may be listed on the command
16line or fed to the command on its standard input.
17
18=head1 DESCRIPTION
19
20The B<pl-subscribe> command takes addresses from the command line or,
21alternatively, standard input (if none are specified on the command
22line) and adds them to the given list's subscriber database. Various
23parameters may be used to control the subscribers' delivery options.
24
25Addresses on the command line may take either of the forms
26
27  alfred@example.com
28  Alfred Newman <alfred@example.com>
29  "Alfred E. Newman" <alfred@example.com>
30
31(note that address specifications containing blanks, like the last
32two, must be quoted on the command line).
33
34If a name is given with the address, it is also stored in the
35database.
36
37Addresses passed on standard input may take the same forms. In addition,
38blank lines and lines starting with the comment symbol, "#", are ignored.
39
40For newly added addresses, the B<digest>, B<nomail>, and B<moderated>
41options in the subscriber database take their default from the list
42configuration parameters B<subscribe.digestdefault>,
43B<subscribe.nomaildefault>, and B<subscribe.moderateddefault>,
44respectively, if they are not set explicity (one way or the other) on
45the command line.
46
47Similarly, if neither B<--welcome> nor B<--nowelcome> is given, the
48value of the B<subscribe.welcomedefault> list configuration parameter
49determines whether the "welcome message" will be sent.
50
51=head1 OPTIONS
52
53=over 4
54
55=item B<--digest>, B<-d>
56
57The new addresses are added as "digest" subscribers; they will receive
58aggregated copies of all messages submitted over a period of
59time. (Digests are planned for Lancelot 0.3; until then, this option
60is effectively equivalent to B<--nomail>, and digest subscribers will
61not receive anything at all.)
62
63=item B<--help>, B<-?>
64
65Causes the program to output a brief usage explanation and exit.
66
67=item B<--mail>
68
69The new addresses are added as "receiving" subscribers; they will receive
70either individual copies of all messages or digests depending on the
71value of their B<digest> option.
72
73=item B<--moderated>
74
75The new addresses are added as "moderated" subscribers; anything they
76submit will be placed before a moderator for approval before it is actually
77posted to the list subscribers at large. (Message moderation is planned
78for Lancelot 0.4; until then, this option is effectively ignored.)
79
80=item B<--nodigest>
81
82The new addresses are added as "regular" subscribers; they will receive
83individual copies of all messages as they come in.
84
85=item B<--nomail>
86
87The new addresses are added as "non-receiving" subscribers; they will
88receive no messages but messages sent from them will be accepted for
89distribution.
90
91=item B<--nomoderated>
92
93The new addresses are added as "non-moderated" subscribers; anything they
94submit will be posted to the list subscribers immediately without
95message moderation.
96
97=item B<--nowelcome>
98
99No "welcome message" will be sent to the new addresses.
100
101=item B<--verbose>, B<-v>
102
103Causes the program to output messages about its progress to the
104standard error channel.
105
106=item B<--welcome>, B<-w>
107
108A copy of the list's "welcome message" is sent to the new addresses
109after they have been subscribed.
110
111=back
112
113=head1 SEE ALSO
114
115pl-conf(1), pl-init(1),  pl-list(1), pl-subchange(1), pl-unsubscribe(1)
116
117=head1 AUTHOR
118
119Anselm Lingnau <anselm@anselms.net>
120
121=head1 COPYRIGHT AND LICENSE
122
123Copyright 2004 by Anselm Lingnau. This program is free software; you
124may redistribute it and/or modify it under the terms of the GNU
125General Public License as published by the Free Software Foundation;
126either version 2 of the License, or (at your option) any later version.
127
128This program is distributed in the hope that it will be useful, but
129WITHOUT ANY WARRANTY; without even the implied warranty of
130MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
131General Public License for more details.
132
133You should have received a copy of the GNU General Public License
134along with this program; if not, refer to
135<URL:http://www.gnu.org/copyleft/gpl.html>. You may also obtain it by
136writing to the Free Software Foundation, Inc., 59 Temple Place - Suite
137330, Boston, MA 02111-1307, USA.
138
139=cut
140
141use strict;
142
143# Make Binary find it's libraries for non standard installations ...
144use Config;
145use File::Basename;
146use vars qw($g_base_dir);
147BEGIN {
148    use FindBin qw($Bin);
149    $g_base_dir = dirname ($Bin);
150}
151use lib "$g_base_dir/lib";
152use lib "$g_base_dir/lib/perl5/$Config{version}";
153use lib "$g_base_dir/lib/perl5/site_perl/$Config{version}";
154
155use Lancelot::GetOpt qw/GetOptions/;
156
157use Lancelot::DB;
158use Lancelot::Send;
159use Lancelot::Module::subscribe_user; # for the welcome message
160use Lancelot::Log qw/log/;
161
162my %opts = ( welcome => -1 );
163
164GetOptions(\%opts, -defaults => 1, -argvmin => 1, "no list address specified",
165           "digest|d!", "mail!", "moderated!", "welcome|w!");
166
167my $listaddr = shift;
168
169my $db = new Lancelot::DB $listaddr
170    or die "$0: error accessing list $listaddr\n";
171
172sub opt_or_conf {
173    my ($option, $conf, $default) = @_;
174    $default ||= 0;
175    my ($cvalue) = $db->get_config($conf);
176    return $opts{$option} != -1
177        ? $opts{$option} : (defined $cvalue ? $cvalue : $default);
178}
179
180$opts{welcome} = opt_or_conf("welcome", "subscribe.welcome", 1);
181
182my (%option) = (
183    moderator => 0,
184    digest => opt_or_conf("digest", "subscribe.digestdefault"),
185    nomail => $opts{mail} != -1 ? !$opts{mail}
186                : $db->get_config("subscribe.nomaildefault"),
187    moderated => opt_or_conf("moderated", "subscribe.moderateddefault"),
188);
189
190my (@addrs) = @ARGV;
191if (@ARGV == 0) {
192    @addrs = grep { chomp; !/^\s*$/ && !/^\#/ } <STDIN>;
193}
194
195foreach my $k (sort keys %option) {
196    log "debug", "$k => $option{$k}";
197}
198foreach my $a (@addrs) {
199    if ($db->add_address($a, \%option)) {
200        &send_welcome($a) if $opts{welcome};
201        log "info", "$a subscribed\n";
202    } else {
203        warn "$0: error subscribing $a\n";
204    }
205}
206
207sub send_welcome {
208    my ($address) = @_;
209    log "debug", "Sending welcome message to $address";
210    Lancelot::Send::sendtemplate("welcome-message", $db, undef,
211                                 { "new-subscriber" => $address });
212}
Note: See TracBrowser for help on using the browser.