summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mailman/commands/cli_members.py22
-rw-r--r--src/mailman/commands/docs/members.txt11
2 files changed, 16 insertions, 17 deletions
diff --git a/src/mailman/commands/cli_members.py b/src/mailman/commands/cli_members.py
index 8d824c2ca..a69b086d7 100644
--- a/src/mailman/commands/cli_members.py
+++ b/src/mailman/commands/cli_members.py
@@ -54,11 +54,12 @@ class Members:
self.parser = parser
command_parser.add_argument(
'-a', '--add',
- dest='filename',
+ dest='input_filename', metavar='FILENAME',
help=_("""\
Add all member addresses in FILENAME. FILENAME can be '-' to
indicate standard input. Blank lines and lines That start with a
- '#' are ignored."""))
+ '#' are ignored. Without this option, this command displays
+ mailing list members."""))
# Required positional argument.
command_parser.add_argument(
'listname', metavar='LISTNAME', nargs=1,
@@ -70,32 +71,29 @@ class Members:
def process(self, args):
"""See `ICLISubCommand`."""
- assert len(args.listname) == 1, (
- 'Unexpected positional arguments: %s' % args.listname)
+ assert len(args.listname) == 1, 'Missing mailing list name'
fqdn_listname = args.listname[0]
mlist = getUtility(IListManager).get(fqdn_listname)
if mlist is None:
self.parser.error(_('No such list: $fqdn_listname'))
- if args.filename is None:
+ if args.input_filename is None:
for address in sorted(mlist.members.addresses,
key=attrgetter('address')):
print formataddr((address.real_name, address.original_address))
return
- elif args.filename == '-':
+ elif args.input_filename == '-':
fp = sys.stdin
else:
- fp = codecs.open(args.filename, 'r', 'utf-8')
+ fp = codecs.open(args.input_filename, 'r', 'utf-8')
try:
for line in fp:
# Ignore blank lines and lines that start with a '#'.
if line.startswith('#') or len(line.strip()) == 0:
continue
+ # Parse the line and ensure that the values are unicodes.
real_name, email = parseaddr(line)
- # If not given in the input data, parseaddr() will return the
- # empty string, as opposed to the empty unicode. We need a
- # unicode real name here.
- if real_name == '':
- real_name = u''
+ real_name = real_name.decode(fp.encoding)
+ email = email.decode(fp.encoding)
try:
add_member(mlist, email, real_name, None,
DeliveryMode.regular,
diff --git a/src/mailman/commands/docs/members.txt b/src/mailman/commands/docs/members.txt
index e7fbd9c8e..530a5acc2 100644
--- a/src/mailman/commands/docs/members.txt
+++ b/src/mailman/commands/docs/members.txt
@@ -7,7 +7,7 @@ You can add members to a mailing list from the command line.
>>> mlist = create_list('test@example.com')
>>> class FakeArgs:
- ... filename = None
+ ... input_filename = None
... listname = None
>>> args = FakeArgs()
@@ -29,7 +29,7 @@ be parsed by email.utils.parseaddr().
... ):
... print >> fp, address
- >>> args.filename = path
+ >>> args.input_filename = path
>>> args.listname = [mlist.fqdn_listname]
>>> command.process(args)
@@ -41,6 +41,7 @@ taken from standard input.
>>> from StringIO import StringIO
>>> fp = StringIO()
+ >>> fp.encoding = 'us-ascii'
>>> for address in ('dperson@example.com',
... 'Elly Person <eperson@example.com>',
... 'fperson@example.com (Fred Person)',
@@ -50,7 +51,7 @@ taken from standard input.
>>> import sys
>>> sys.stdin = fp
- >>> args.filename = '-'
+ >>> args.input_filename = '-'
>>> command.process(args)
>>> sys.stdin = sys.__stdin__
@@ -69,7 +70,7 @@ Blank lines and lines that begin with '#' are ignored.
... ):
... print >> fp, address
- >>> args.filename = path
+ >>> args.input_filename = path
>>> command.process(args)
>>> sorted(address.address for address in mlist.members.addresses)
[u'aperson@example.com', u'bperson@example.com', u'cperson@example.com',
@@ -101,7 +102,7 @@ Displaying members
With no arguments, the command displays all members of the list.
- >>> args.filename = None
+ >>> args.input_filename = None
>>> command.process(args)
aperson@example.com
Bart Person <bperson@example.com>