root/bin/pl-unsubscribe

Revision 303:6f57b7328cb8, 3.5 KB (checked in by Anselm Lingnau <anselm@…>, 9 months ago)

The Great Renaming: Change all command names to 'pl-*' and directory to '.pl'.
The idea behind this is to emphasise that the software is called ?*Project*
Lancelot? as opposed to plain ?Lancelot?. There is apparently a KDE tool that
goes by the name of ?Lancelot?, and we want to make clear that this is separate
and different. Also, Project Lancelot has been around for a lot longer!

  • Property exe set to *
Line 
1#!/usr/bin/perl
2
3=head1 NAME
4
5pl-unsubscribe - Remove addresses from a Lancelot list's subscriber database
6
7=head1 SYNOPSIS
8
9  pl-unsubscribe [-gv?] [--[no]goodbye] [--verbose] list@domain
10      [address ...]
11
12=head1 OVERVIEW
13
14The B<pl-unsubscribe> command allows a list owner to remove addresses
15from a list's subscriber database manually.  Addresses may be listed
16on the command line or fed to the command on its standard input.
17
18=head1 DESCRIPTION
19
20The B<pl-unsubscribe> command takes addresses from the command line or,
21alternatively, standard input (if none are specified on the command
22line) and removes them from the given list's subscriber database.
23
24=head1 OPTIONS
25
26=over 4
27
28=item B<--goodbye>, B<-g>
29
30A copy of the list's "goodbye message" is sent to the addresses after they
31have been unsubscribed. This option is ignored if the B<--confirm> option
32was also specified.
33
34=item B<--help>, B<-?>
35
36Causes the program to output a brief usage explanation and exit.
37
38=item B<--nogoodbye>
39
40No "goodbye message" will be sent to the addresses.
41
42=item B<--verbose>, B<-v>
43
44Causes the program to output messages about its progress to the
45standard error channel.
46
47=back
48
49=head1 SEE ALSO
50
51pl-conf(1), pl-init(1),  pl-list(1), pl-subchange(1), pl-subscribe(1)
52
53=head1 AUTHOR
54
55Anselm Lingnau <anselm@anselms.net>
56
57=head1 COPYRIGHT AND LICENSE
58
59Copyright 2004 by Anselm Lingnau. This program is free software; you
60may redistribute it and/or modify it under the terms of the GNU
61General Public License as published by the Free Software Foundation;
62either version 2 of the License, or (at your option) any later version.
63
64This program is distributed in the hope that it will be useful, but
65WITHOUT ANY WARRANTY; without even the implied warranty of
66MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
67General Public License for more details.
68
69You should have received a copy of the GNU General Public License
70along with this program; if not, refer to
71<URL:http://www.gnu.org/copyleft/gpl.html>. You may also obtain it by
72writing to the Free Software Foundation, Inc., 59 Temple Place - Suite
73330, Boston, MA 02111-1307, USA.
74
75=cut
76
77use strict;
78
79# Make Binary find it's libraries for non standard installations ...
80use Config;
81use File::Basename;
82use vars qw($g_base_dir);
83BEGIN {
84    use FindBin qw($Bin);
85    $g_base_dir = dirname ($Bin);
86}
87use lib "$g_base_dir/lib";
88use lib "$g_base_dir/lib/perl5/$Config{version}";
89use lib "$g_base_dir/lib/perl5/site_perl/$Config{version}";
90
91use Lancelot::GetOpt qw/GetOptions/;
92
93use Lancelot::DB;
94use Lancelot::Send;
95use Lancelot::Module::unsubscribe_user; # for goodbye-message
96use Lancelot::Log qw/log/;
97
98my %opts;
99
100GetOptions(\%opts, -defaults => 1, -argvmin => 1, "no list address specified",
101           "goodbye|g!");
102
103my $listaddr = shift;
104
105my $db = new Lancelot::DB $listaddr
106    or die "$0: error accessing list $listaddr\n";
107
108my $conf_goodbye = $db->get_config("unsubscribe.goodbye");
109$opts{goodbye} = $opts{goodbye} != -1 ? $opts{goodbye}
110                          : (defined $conf_goodbye ? $conf_goodbye : 1);
111
112my (@addrs) = @ARGV;
113if (@ARGV == 0) {
114    @addrs = grep { chomp; !/^\s*$/ && !/^\#/ } <STDIN>;
115}
116
117foreach my $a (@addrs) {
118    if ($db->set_address_options($a, { status => 'DELETE' })) {
119        &send_goodbye($a) if $opts{goodbye};
120        print STDERR "$a unsubscribed\n" if $::verbose;
121    } else {
122        warn "$0: error unsubscribing $a\n";
123    }
124}
125
126sub send_goodbye {
127    my ($address) = @_;
128    print STDERR "Sending goodbye message to $address\n" if $::verbose;
129    Lancelot::Send::sendtemplate("goodbye-message", $db, undef,
130                                 { "subscriber" => $address });
131}
Note: See TracBrowser for help on using the browser.