Commit 3ad94d9f authored by Barry Warsaw's avatar Barry Warsaw

Add filtering by delivery mode.

parent 0ea2e10d
......@@ -65,6 +65,18 @@ class Members:
dest='output_filename', metavar='FILENAME',
help=_("""Display output to FILENAME instead of stdout. FILENAME
can be '-' to indicate standard output."""))
command_parser.add_argument(
'-r', '--regular',
default=None, action='store_true',
help=_('Display only regular delivery members.'))
command_parser.add_argument(
'-d', '--digest',
default=None, metavar='KIND',
# BAW 2010-01-23 summary digests are not really supported yet.
choices=('any', 'plaintext', 'mime'),
help=_("""Display only digest members of KIND. 'any' means any
digest type, 'plaintext' means only plain text (RFC 1153) type
digests, 'mime' means MIME type digests."""))
# Required positional argument.
command_parser.add_argument(
'listname', metavar='LISTNAME', nargs=1,
......@@ -98,12 +110,29 @@ class Members:
fp = sys.stdout
else:
fp = codecs.open(args.output_filename, 'w', 'utf-8')
if args.digest == 'any':
digest_types = [DeliveryMode.plaintext_digests,
DeliveryMode.mime_digests,
DeliveryMode.summary_digests]
elif args.digest is not None:
digest_types = [DeliveryMode(args.digest + '_digests')]
else:
# Don't filter on digest type.
pass
try:
addresses = list(mlist.members.addresses)
if len(addresses) == 0:
print >> fp, mlist.fqdn_listname, 'has no members'
return
for address in sorted(addresses, key=attrgetter('address')):
if args.regular:
member = mlist.members.get_member(address.address)
if member.delivery_mode != DeliveryMode.regular:
continue
if args.digest is not None:
member = mlist.members.get_member(address.address)
if member.delivery_mode not in digest_types:
continue
print >> fp, formataddr(
(address.real_name, address.original_address))
finally:
......
......@@ -11,6 +11,8 @@ and remove members from a mailing list.
... input_filename = None
... output_filename = None
... listname = []
... regular = False
... digest = None
>>> args = FakeArgs()
>>> from mailman.commands.cli_members import Members
......@@ -80,6 +82,41 @@ The output file can also be standard out.
Bart Person <bart@example.com>
>>> args.output_filename = None
You can limit output to just the regular non-digest members...
>>> args.regular = True
>>> member = mlist1.members.get_member('anne@example.com')
>>> member.preferences.delivery_mode = DeliveryMode.plaintext_digests
>>> command.process(args)
Anne Person <anne@aaaxample.com>
Bart Person <bart@example.com>
...or just the digest members. Furthermore, you can either display all digest
members...
>>> member = mlist1.members.get_member('anne@aaaxample.com')
>>> member.preferences.delivery_mode = DeliveryMode.mime_digests
>>> args.regular = False
>>> args.digest = 'any'
>>> command.process(args)
Anne Person <anne@aaaxample.com>
Anne Person <anne@example.com>
...just plain text digest members...
>>> args.digest = 'plaintext'
>>> command.process(args)
Anne Person <anne@example.com>
...just MIME digest members.
>>> args.digest = 'mime'
>>> command.process(args)
Anne Person <anne@aaaxample.com>
# Reset for following tests.
>>> args.digest = None
Adding members
==============
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment