Commit 1927e931 authored by Barry Warsaw's avatar Barry Warsaw

Support filtering by delivery status.

parent 3ad94d9f
......@@ -38,7 +38,8 @@ from mailman.config import config
from mailman.core.i18n import _
from mailman.interfaces.command import ICLISubCommand
from mailman.interfaces.listmanager import IListManager
from mailman.interfaces.member import AlreadySubscribedError, DeliveryMode
from mailman.interfaces.member import (
AlreadySubscribedError, DeliveryMode, DeliveryStatus)
......@@ -77,6 +78,19 @@ class Members:
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."""))
command_parser.add_argument(
'-n', '--nomail',
default=None, metavar='WHY',
choices=('enabled', 'any', 'unknown'
'byadmin', 'byuser', 'bybounces'),
help=_("""Display only members with a given delivery
status. 'enabled' means all members whose delivery is enabled,
'any' means members whose delivery is disabled for any reason,
'byuser' means that the member disabled their own delivery,
'bybounces' means that delivery was disabled by the automated
bounce processor, 'byadmin' means delivery was disabled by the
list administrator or moderator, and 'unknown' means that delivery
was disabled for unknown (legacy) reasons."""))
# Required positional argument.
command_parser.add_argument(
'listname', metavar='LISTNAME', nargs=1,
......@@ -119,6 +133,24 @@ class Members:
else:
# Don't filter on digest type.
pass
if args.nomail is None:
# Don't filter on delivery status.
pass
elif args.nomail == 'byadmin':
status_types = [DeliveryStatus.by_moderator]
elif args.nomail.startswith('by'):
status_types = [DeliveryStatus('by_' + args.nomail[2:])]
elif args.nomail == 'enabled':
status_types = [DeliveryStatus.enabled]
elif args.nomail == 'unknown':
status_types = [DeliveryStatus.unknown]
elif args.nomail == 'any':
status_types = [DeliveryStatus.by_user,
DeliveryStatus.by_bounces,
DeliveryStatus.by_moderator,
DeliveryStatus.unknown]
else:
raise AssertionError('Unknown delivery status: %s' % args.nomail)
try:
addresses = list(mlist.members.addresses)
if len(addresses) == 0:
......@@ -133,6 +165,10 @@ class Members:
member = mlist.members.get_member(address.address)
if member.delivery_mode not in digest_types:
continue
if args.nomail is not None:
member = mlist.members.get_member(address.address)
if member.delivery_status not in status_types:
continue
print >> fp, formataddr(
(address.real_name, address.original_address))
finally:
......
......@@ -13,6 +13,7 @@ and remove members from a mailing list.
... listname = []
... regular = False
... digest = None
... nomail = None
>>> args = FakeArgs()
>>> from mailman.commands.cli_members import Members
......@@ -82,6 +83,10 @@ The output file can also be standard out.
Bart Person <bart@example.com>
>>> args.output_filename = None
Filtering on delivery mode
--------------------------
You can limit output to just the regular non-digest members...
>>> args.regular = True
......@@ -118,6 +123,73 @@ members...
>>> args.digest = None
Filtering on delivery status
----------------------------
You can also filter the display on the member's delivery status. By default,
all members are displayed, but you can filter out only those whose delivery
status is enabled...
>>> from mailman.interfaces.member import DeliveryStatus
>>> member = mlist1.members.get_member('anne@aaaxample.com')
>>> member.preferences.delivery_status = DeliveryStatus.by_moderator
>>> member = mlist1.members.get_member('bart@example.com')
>>> member.preferences.delivery_status = DeliveryStatus.by_user
>>> member = add_member(
... mlist1, 'cris@example.com', 'Cris Person', 'xxx',
... DeliveryMode.regular, mlist1.preferred_language.code)
>>> member.preferences.delivery_status = DeliveryStatus.unknown
>>> member = add_member(
... mlist1, 'dave@example.com', 'Dave Person', 'xxx',
... DeliveryMode.regular, mlist1.preferred_language.code)
>>> member.preferences.delivery_status = DeliveryStatus.enabled
>>> member = add_member(
... mlist1, 'elly@example.com', 'Elly Person', 'xxx',
... DeliveryMode.regular, mlist1.preferred_language.code)
>>> member.preferences.delivery_status = DeliveryStatus.by_bounces
>>> args.nomail = 'enabled'
>>> command.process(args)
Anne Person <anne@example.com>
Dave Person <dave@example.com>
...or disabled by the user...
>>> args.nomail = 'byuser'
>>> command.process(args)
Bart Person <bart@example.com>
...or disabled by the list administrator (or moderator)...
>>> args.nomail = 'byadmin'
>>> command.process(args)
Anne Person <anne@aaaxample.com>
...or by the bounce processor...
>>> args.nomail = 'bybounces'
>>> command.process(args)
Elly Person <elly@example.com>
...or for unknown (legacy) reasons.
>>> args.nomail = 'unknown'
>>> command.process(args)
Cris Person <cris@example.com>
You can also display all members who have delivery disabled for any reason.
>>> args.nomail = 'any'
>>> command.process(args)
Anne Person <anne@aaaxample.com>
Bart Person <bart@example.com>
Cris Person <cris@example.com>
Elly Person <elly@example.com>
# Reset for following tests.
>>> args.nomail = 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