==============
Adding members
==============

You can add members to a mailing list from the command line.

    >>> from mailman.app.lifecycle import create_list
    >>> mlist = create_list('test@example.com')

    >>> class FakeArgs:
    ...     filename = None
    ...     listname = None
    >>> args = FakeArgs()

    >>> from mailman.commands.cli_members import Members
    >>> command = Members()

To do so, you need a file containing email addresses and full names that can
be parsed by email.utils.parseaddr().

    >>> addresses = [
    ...     ]

    >>> import os
    >>> path = os.path.join(config.VAR_DIR, 'addresses.txt')
    >>> with open(path, 'w') as fp:
    ...     for address in ('aperson@example.com',
    ...                     'Bart Person <bperson@example.com>',
    ...                     'cperson@example.com (Cate Person)',
    ...                     ):
    ...         print >> fp, address

    >>> args.filename = path
    >>> args.listname = [mlist.fqdn_listname]
    >>> command.process(args)

    >>> sorted(address.address for address in mlist.members.addresses)
    [u'aperson@example.com', u'bperson@example.com', u'cperson@example.com']

You can also specify '-' as the filename, in which case the addresses are
taken from standard input.

    >>> from StringIO import StringIO
    >>> fp = StringIO()
    >>> for address in ('dperson@example.com',
    ...                 'Elly Person <eperson@example.com>',
    ...                 'fperson@example.com (Fred Person)',
    ...                 ):
    ...         print >> fp, address
    >>> fp.seek(0)
    >>> import sys
    >>> sys.stdin = fp

    >>> args.filename = '-'
    >>> command.process(args)
    >>> sys.stdin = sys.__stdin__

    >>> sorted(address.address for address in mlist.members.addresses)
    [u'aperson@example.com', u'bperson@example.com', u'cperson@example.com',
     u'dperson@example.com', u'eperson@example.com', u'fperson@example.com']
