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