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