Manage IP list for SMTP relay connections.

    Due to the unusual way that Windows stores the relay IPs, it is advisable to retrieve
    the existing list you wish to set from a pre-configured server.

    For example, setting '127.0.0.1' as an allowed relay IP through the GUI would generate
    an actual relay IP list similar to the following:

    .. code-block:: cfg

        ['24.0.0.128', '32.0.0.128', '60.0.0.128', '68.0.0.128', '1.0.0.0', '76.0.0.0',
          '0.0.0.0', '0.0.0.0', '1.0.0.0', '1.0.0.0', '2.0.0.0', '2.0.0.0', '4.0.0.0',
          '0.0.0.0', '76.0.0.128', '0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0',
          '255.255.255.255', '127.0.0.1']

    .. note::

        Setting the list to None corresponds to the restrictive 'Only the list below' GUI parameter
        with an empty access list configured, and setting an empty list/tuple corresponds to the
        more permissive 'All except the list below' GUI parameter.

    :param str addresses: A list of the relay IPs. The order of the list is important.
    :param str server: The SMTP server name.

    Example of usage:

    .. code-block:: yaml

        smtp-relay-list:
          win_smtp_server.relay_ip_list:
            - addresses:
                - 24.0.0.128
                - 32.0.0.128
                - 60.0.0.128
                - 1.0.0.0
                - 76.0.0.0
                - 0.0.0.0
                - 0.0.0.0
                - 1.0.0.0
                - 1.0.0.0
                - 2.0.0.0
                - 2.0.0.0
                - 4.0.0.0
                - 0.0.0.0
                - 76.0.0.128
                - 0.0.0.0
                - 0.0.0.0
                - 0.0.0.0
                - 0.0.0.0
                - 255.255.255.255
                - 127.0.0.1

    Example of usage for disabling relaying:

    .. code-block:: yaml

        smtp-relay-list:
            win_smtp_server.relay_ip_list:
                - addresses: None

    Example of usage for allowing relaying from any source:

    .. code-block:: yaml

        smtp-relay-list:
            win_smtp_server.relay_ip_list:
                - addresses: []

def relay_ip_list(name, addresses=None, server=_DEFAULT_SERVER):
    '''
    Manage IP list for SMTP relay connections.

    Due to the unusual way that Windows stores the relay IPs, it is advisable to retrieve
    the existing list you wish to set from a pre-configured server.

    For example, setting '127.0.0.1' as an allowed relay IP through the GUI would generate
    an actual relay IP list similar to the following:

    .. code-block:: cfg

        ['24.0.0.128', '32.0.0.128', '60.0.0.128', '68.0.0.128', '1.0.0.0', '76.0.0.0',
          '0.0.0.0', '0.0.0.0', '1.0.0.0', '1.0.0.0', '2.0.0.0', '2.0.0.0', '4.0.0.0',
          '0.0.0.0', '76.0.0.128', '0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0',
          '255.255.255.255', '127.0.0.1']

    .. note::

        Setting the list to None corresponds to the restrictive 'Only the list below' GUI parameter
        with an empty access list configured, and setting an empty list/tuple corresponds to the
        more permissive 'All except the list below' GUI parameter.

    :param str addresses: A list of the relay IPs. The order of the list is important.
    :param str server: The SMTP server name.

    Example of usage:

    .. code-block:: yaml

        smtp-relay-list:
          win_smtp_server.relay_ip_list:
            - addresses:
                - 24.0.0.128
                - 32.0.0.128
                - 60.0.0.128
                - 1.0.0.0
                - 76.0.0.0
                - 0.0.0.0
                - 0.0.0.0
                - 1.0.0.0
                - 1.0.0.0
                - 2.0.0.0
                - 2.0.0.0
                - 4.0.0.0
                - 0.0.0.0
                - 76.0.0.128
                - 0.0.0.0
                - 0.0.0.0
                - 0.0.0.0
                - 0.0.0.0
                - 255.255.255.255
                - 127.0.0.1

    Example of usage for disabling relaying:

    .. code-block:: yaml

        smtp-relay-list:
            win_smtp_server.relay_ip_list:
                - addresses: None

    Example of usage for allowing relaying from any source:

    .. code-block:: yaml

        smtp-relay-list:
            win_smtp_server.relay_ip_list:
                - addresses: []
    '''
    ret = {'name': name,
           'changes': {},
           'comment': six.text_type(),
           'result': None}
    current_addresses = __salt__['win_smtp_server.get_relay_ip_list'](server=server)

    # Fix if we were passed None as a string.
    if addresses:
        if addresses[0] == 'None':
            addresses[0] = None
    elif addresses is None:
        addresses = [None]

    if addresses == current_addresses:
        ret['comment'] = 'RelayIpList already contains the provided addresses.'
        ret['result'] = True
    elif __opts__['test']:
        ret['comment'] = 'RelayIpList will be changed.'
        ret['changes'] = {'old': current_addresses,
                          'new': addresses}
    else:
        ret['comment'] = 'Set RelayIpList to contain the provided addresses.'
        ret['changes'] = {'old': current_addresses,
                          'new': addresses}
        ret['result'] = __salt__['win_smtp_server.set_relay_ip_list'](addresses=addresses, server=server)
    return ret