==================
Generating aliases
==================

For some mail servers, Mailman must generate a data file that is used to hook
Mailman up to the mail server.  The details of this differ for each mail
server.  Generally these files are automatically kept up-to-date when mailing
lists are created or removed, but you might occasionally need to manually
regenerate the file.  The ``bin/mailman aliases`` command does this.

    >>> class FakeArgs:
    ...     output = None
    ...     format = None
    ...     simple = None
    >>> from mailman.commands.cli_aliases import Aliases
    >>> command = Aliases()

For example, connecting Mailman to Postfix is generally done through the LMTP
protocol.  Mailman starts an LMTP server and Postfix delivers messages to
Mailman as an LMTP client.  By default this is done through Postfix transport
maps.

Selecting Postfix as the source of incoming messages enables transport map
generation.

    >>> config.push('postfix', """
    ... [mta]
    ... incoming: mailman.mta.postfix.LMTP
    ... lmtp_host: lmtp.example.com
    ... lmtp_port: 24
    ... postfix_map_cmd: true
    ... """)

Let's create a mailing list and then display the transport map for it.  We'll
send the output to stdout.
::

    >>> FakeArgs.output = '-'
    >>> mlist = create_list('test@example.com')
    >>> command.process(FakeArgs)
    # AUTOMATICALLY GENERATED BY MAILMAN ON ...
    ...
    test@example.com               lmtp:[lmtp.example.com]:24
    test-bounces@example.com       lmtp:[lmtp.example.com]:24
    test-confirm@example.com       lmtp:[lmtp.example.com]:24
    test-join@example.com          lmtp:[lmtp.example.com]:24
    test-leave@example.com         lmtp:[lmtp.example.com]:24
    test-owner@example.com         lmtp:[lmtp.example.com]:24
    test-request@example.com       lmtp:[lmtp.example.com]:24
    test-subscribe@example.com     lmtp:[lmtp.example.com]:24
    test-unsubscribe@example.com   lmtp:[lmtp.example.com]:24
    <BLANKLINE>

    >>> config.pop('postfix')


Alternative output
==================

By using a command line switch, we can select a different output format.  The
option must point to an alternative implementation of the
``IMailTransportAgentAliases`` interface.

Mailman comes with an alternative implementation that just prints the aliases,
with no adornment.

    >>> FakeArgs.format = 'mailman.commands.cli_aliases.Dummy'
    >>> command.process(FakeArgs)
    test@example.com
    test-bounces@example.com
    test-confirm@example.com
    test-join@example.com
    test-leave@example.com
    test-owner@example.com
    test-request@example.com
    test-subscribe@example.com
    test-unsubscribe@example.com
    <BLANKLINE>

A simpler way of getting the same output is with the ``--simple`` flag.

    >>> FakeArgs.format = None
    >>> FakeArgs.simple = True
    >>> command.process(FakeArgs)
    test@example.com
    test-bounces@example.com
    test-confirm@example.com
    test-join@example.com
    test-leave@example.com
    test-owner@example.com
    test-request@example.com
    test-subscribe@example.com
    test-unsubscribe@example.com
    <BLANKLINE>


Mutually exclusive arguments
============================

You cannot use both ``--simple`` and ``--format``.

    >>> FakeArgs.format = 'mailman.commands.cli_aliases.Dummy'
    >>> FakeArgs.simple = True
    >>> class Parser:
    ...     def error(self, message):
    ...         raise RuntimeError(message)
    >>> command.parser = Parser()
    >>> command.process(FakeArgs)
    Traceback (most recent call last):
    ...
    RuntimeError: Cannot use both -s and -f
