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