root/bin/pl-list

Revision 321:6e4120f3a110, 6.2 KB (checked in by Anselm Lingnau <anselm@…>, 9 months ago)

Handle UNCONFIRMED addresses properly in pl-list.
This includes a ?--unconfirmed? option that will add UNCONFIRMED addresses
to the output of pl-list. There is currently no way to list *only* UNCONFIRMED
addresses. ?pl-list -a? will also list UNCONFIRMED addresses along with all
the others.

  • Property exe set to *
Line 
1#!/usr/bin/perl
2
3=head1 NAME
4
5pl-list - Enumerate subscribers of a Lancelot list
6
7=head1 SYNOPSIS
8
9  pl-list [-adlnrv?] [-s SEPARATOR] [--all] [--[no]digest] [--full]
10            [--[no]mail] [--name] [--[no]regular] [--separator=SEPARATOR]
11            [--verbose] list@domain [pattern]
12
13=head1 OVERVIEW
14
15The B<pl-list> command outputs a list of addresses from a Lancelot
16list's subscriber database. It can optionally include names and/or
17subscription options, and select only those addresses matching a given
18pattern.
19
20=head1 DESCRIPTION
21
22The B<pl-list> command displays either all addresses from
23I<list@domain>'s subscriber database, or those matching the optional
24shepl-style "glob" I<pattern>, which may contain "*", "?", and similar
25wild cards.
26
27It supports three different output styles: address-only,
28name-and-address, or full, like
29
30  alfred@example.com
31  "Alfred E. Newman" <alfred@example.com>
32  SMdnm alfred@example.com Alfred E. Newman
33
34The first is the default; the second is used if the B<--name> option is
35given and the address is associated with a name in the database (otherwise
36it defaults to the first); the third is used if the B<--full> option is
37given. If there is no name associated with the address, the "full" output
38line will end after the address.
39
40If both B<--name> and B<--full> are specified, the output looks like
41
42  SMdnm "Alfred E. Newman" <alfred@example.com>
43
44With "full" output, the six characters at the beginning of the line
45signify the status and subscription options of the address. The first
46character gives the status, where B<S> is SUBSCRIBED, B<B> is BOUNCING,
47and B<X> is BLACKLIST. The next five characters, respectively, refer to the
48subscription options B<admin>, B<moderator>, B<digest>, B<nomail>, and
49B<moderated>; a letter implies that the option in question is set,
50while a dash ("-") signifies that it is not set.
51
52With "full" output, the fields are normally separated by spaces; for easier
53processing with programs like B<cut> or B<sort> an alternative separator may
54be defined using the B<--separator> (or B<-s>) option.
55
56=head1 OPTIONS
57
58=over 4
59
60=item B<--all>, B<-a>
61
62Outputs all subscribers (regular, digest, and nomail).
63
64=item B<--digest>, B<-d>
65
66Includes "digest" subscribers in the output. (Default.)
67
68=item B<--full>, B<-l>
69
70Produces "full" output including subscriber state and options.
71
72=item B<--help>, B<-?>
73
74Causes the program to output a brief usage explanation and exit.
75
76=item B<--name>, B<-n>
77
78Includes subscriber names in the output where available.
79
80=item B<--nomail>
81
82Includes "non-receiving" subscribers in the output.
83
84=item B<--nodigest>
85
86Excludes "digest" subscribers from the output.
87
88=item B<--nonomail>
89
90Excludes "non-receiving" subscribers from the output. (Default.)
91
92=item B<--noregular>
93
94Excludes "regular" subscribers from the output.
95
96=item B<--regular>, B<-r>
97
98Includes "regular" subscribers in the output. (Default.)
99
100=item B<--separator>=I<separator>, B<-s> I<separator>
101
102Uses I<separator> to delimit columns in "full" output instead of a space.
103
104=item B<--verbose>, B<-v>
105
106Causes the program to output messages about its progress to the
107standard error channel.
108
109=back
110
111=head1 SEE ALSO
112
113pl-conf(1), pl-init(1), pl-subchange(1), pl-subscribe(1), pl-unsubscribe(1)
114
115=head1 AUTHOR
116
117Anselm Lingnau <anselm@anselms.net>
118
119=head1 COPYRIGHT AND LICENSE
120
121Copyright 2004 by Anselm Lingnau. This program is free software; you
122may redistribute it and/or modify it under the terms of the GNU
123General Public License as published by the Free Software Foundation;
124either version 2 of the License, or (at your option) any later version.
125
126This program is distributed in the hope that it will be useful, but
127WITHOUT ANY WARRANTY; without even the implied warranty of
128MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
129General Public License for more details.
130
131You should have received a copy of the GNU General Public License
132along with this program; if not, refer to
133<URL:http://www.gnu.org/copyleft/gpl.html>. You may also obtain it by
134writing to the Free Software Foundation, Inc., 59 Temple Place - Suite
135330, Boston, MA 02111-1307, USA.
136
137=cut
138
139use strict;
140
141# Make Binary find it's libraries for non standard installations ...
142use Config;
143use File::Basename;
144use vars qw($g_base_dir);
145BEGIN {
146    use FindBin qw($Bin);
147    $g_base_dir = dirname ($Bin);
148}
149use lib "$g_base_dir/lib";
150use lib "$g_base_dir/lib/perl5/$Config{version}";
151use lib "$g_base_dir/lib/perl5/site_perl/$Config{version}";
152
153use Lancelot::GetOpt qw/GetOptions/;
154use Lancelot::DB;
155use Lancelot::Log qw/log/;
156
157my (%status) = qw/SUBSCRIBED S BOUNCING B BLACKLIST X UNCONFIRMED U/;
158
159my (%opts) = ( regular => 1, unconfirmed => 0 );
160
161GetOptions(\%opts,
162           -argvmin => 1, "no list address specified",
163           -argvmax => 2, "too many arguments",
164           "all|a!",
165           "digest|d!", "regular|r!", "nomail!",
166           "unconfirmed|u!",
167           "name|n?", "full|l?",
168           "order|O=",
169           "separator|s=");
170
171$opts{digest} = $opts{regular} = $opts{nomail}
172    = $opts{unconfirmed} = 1 if $opts{all};
173
174my $listaddr = shift;
175my $pattern = shift || "*";
176
177my $db = new Lancelot::DB $listaddr
178    or die "$0: error accessing list $listaddr\n";
179
180my $optspec = {};
181$optspec->{order} = $opts{order} if $opts{order};
182
183foreach my $a ($db->get_addresses($pattern, $optspec)) {
184    log "debug", $a;
185    my $optref = $db->get_address_options($a);
186    next if $optref->{status} eq "UNCONFIRMED" && !$opts{unconfirmed};
187    next if $optref->{digest} == 1 && !$opts{digest};
188    next if $optref->{digest} == 0 && !$opts{regular};
189    next if $optref->{nomail} == 1 && !$opts{nomail};
190    delete $optref->{name} if $optref->{name} eq $a;
191    if ($opts{full}) {
192        # Full output
193        print $status{$optref->{status}};
194        print ($optref->{admin} ? "A" : "-");
195        print ($optref->{moderator} ? "M" : "-");
196        print ($optref->{digest} ? "d" : "-");
197        print ($optref->{nomail} ? "n" : "-");
198        print ($optref->{moderated} ? "m" : "-");
199        my $s = $opts{separator} || ' ';
200        if ($opts{name}) {
201            if ($optref->{name}) {
202                print qq|$s"$optref->{name}" <$a>|;
203            } else {
204                print "$s$a";
205            }
206        } else {
207            print "$s$a";
208            print "$s$optref->{name}" if $optref->{name};
209        }
210    } elsif ($opts{name}) {
211        # Address and name
212        if ($optref->{name}) {
213            print qq|"$optref->{name}" <$a>|;
214        } else {
215            print $a;
216        }
217    } else {
218        # Just the address
219        print $a;
220    }
221    print "\n";
222}
Note: See TracBrowser for help on using the browser.