summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/list_members118
1 files changed, 92 insertions, 26 deletions
diff --git a/bin/list_members b/bin/list_members
index c5dab9eee..e3f874f8e 100755
--- a/bin/list_members
+++ b/bin/list_members
@@ -1,6 +1,6 @@
#! @PYTHON@
#
-# Copyright (C) 1998,1999,2000,2001 by the Free Software Foundation, Inc.
+# Copyright (C) 1998,1999,2000,2001,2002 by the Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -18,7 +18,7 @@
"""List all the members of a mailing list.
-Usage: %(PROGRAM)s [-o file] [-r] [-d] [-p] [-h] listname
+Usage: %(PROGRAM)s [options] listname
Where:
@@ -26,13 +26,20 @@ Where:
-o file
Write output to specified file instead of standard out.
- --regular
- -r
+ --regular / -r
Print just the regular (non-digest) members.
- --digest
- -d
- Print just the digest members.
+ --digest[=kind] / -d [kind]
+ Print just the digest members. Optional argument can be "mime" or
+ "plain" which prints just the digest members receiving that kind of
+ digest.
+
+ --nomail[=why] / -n [why]
+ Print the members that have delivery disabled. Optional argument can
+ be "byadmin", "byuser", "bybounce", or "unknown" which prints just the
+ users who have delivery disabled for that reason. It can also be
+ "enabled" which prints just those member for whom delivery is
+ enabled.
--preserve
-p
@@ -48,18 +55,25 @@ Where:
Note that if neither -r or -d is supplied, both regular members are printed
first, followed by digest members, but no indication is given as to address
status.
-
"""
import sys
-import getopt
import paths
+from Mailman import mm_cfg
from Mailman import MailList
from Mailman import Errors
+from Mailman import MemberAdaptor
from Mailman.i18n import _
PROGRAM = sys.argv[0]
+WHYCHOICES = {'enabled' : MemberAdaptor.ENABLED,
+ 'unknown' : MemberAdaptor.UNKNOWN,
+ 'byuser' : MemberAdaptor.BYUSER,
+ 'byadmin' : MemberAdaptor.BYADMIN,
+ 'bybounce': MemberAdaptor.BYBOUNCE,
+ }
+
def usage(code, msg=''):
print >> sys.stderr, _(__doc__)
@@ -69,35 +83,70 @@ def usage(code, msg=''):
-def main():
- try:
- opts, args = getopt.getopt(
- sys.argv[1:],
- 'dpro:h',
- ['digest', 'regular', 'preserve', 'output=', 'help'])
- except getopt.error, msg:
- usage(1, msg)
+def statusp(mlist, addr, why):
+ # Filter out nomails
+ status = mlist.getDeliveryStatus(addr)
+ if why is None:
+ return status <> MemberAdaptor.ENABLED
+ return status == WHYCHOICES[why]
- if len(args) <> 1:
- usage(1)
- listname = args[0].lower().strip()
+
+def main():
+ # Because of the optional arguments, we can't use getopt. :(
outfile = None
regular = None
digest = None
preserve = None
+ nomail = None
+ why = None
+ kind = None
+
+ args = sys.argv[1:]
+ if not args:
+ usage(0)
- for opt, arg in opts:
+ while 1:
+ opt = args.pop(0)
if opt in ('-h', '--help'):
usage(0)
- elif opt in ('-o', '--output'):
- outfile = arg
+ elif opt in ('-p', '--preserve'):
+ preserve = 1
elif opt in ('-r', '--regular'):
regular = 1
- elif opt in ('-d', '--digest'):
+ elif opt in ('-o', '--output'):
+ outfile = args.pop(0)
+ elif opt == '-n':
+ nomail = 1
+ if args and args[0] in WHYCHOICES.keys():
+ why = args.pop(0)
+ elif opt.startswith('--nomail'):
+ nomail = 1
+ i = opt.find('=')
+ if i >= 0:
+ why = opt[i+1:]
+ if why not in WHYCHOICES.keys():
+ usage(1, _('Bad --nomail option: %(why)s'))
+ elif opt == '-d':
digest = 1
- elif opt in ('-p', '--preserve'):
- preserve = 1
+ if args and args[0] in ('mime', 'plain'):
+ kind = args.pop(0)
+ elif opt.startswith('--digest'):
+ digest = 1
+ i = opt.find('=')
+ if i >= 0:
+ kind = opt[i+1:]
+ if kind not in ('mime', 'plain'):
+ usage(1, _('Bad --digest option: %(kind)s'))
+ else:
+ # No more options left, push the last one back on the list
+ args.insert(0, opt)
+ break
+
+ if len(args) <> 1:
+ usage(1)
+
+ listname = args[0].lower().strip()
if regular is None and digest is None:
regular = digest = 1
@@ -127,10 +176,27 @@ def main():
dmembers = mlist.getMemberCPAddresses(dmembers)
if regular:
+ rmembers.sort()
for addr in rmembers:
+ # Filter out nomails
+ if not statusp(mlist, addr, why):
+ continue
print >> fp, addr
if digest:
+ dmembers.sort()
for addr in dmembers:
+ # Filter out nomails
+ if not statusp(mlist, addr, why):
+ continue
+ # Filter out digest kinds
+ if mlist.getMemberOption(addr, mm_cfg.DisableMime):
+ # They're getting plain text digests
+ if kind == 'mime':
+ continue
+ else:
+ # They're getting MIME digests
+ if kind == 'plain':
+ continue
print >> fp, addr