Manage IP list for SMTP connections.

    :param str addresses: A dictionary of IP + subnet pairs.
    :param bool grant_by_default: Whether the addresses should be a blacklist or whitelist.
    :param str server: The SMTP server name.

    Example of usage for creating a whitelist:

    .. code-block:: yaml

        smtp-connection-whitelist:
            win_smtp_server.connection_ip_list:
                - addresses:
                    127.0.0.1: 255.255.255.255
                    172.16.1.98: 255.255.255.255
                    172.16.1.99: 255.255.255.255
                - grant_by_default: False

    Example of usage for creating a blacklist:

    .. code-block:: yaml

        smtp-connection-blacklist:
            win_smtp_server.connection_ip_list:
                - addresses:
                    172.16.1.100: 255.255.255.255
                    172.16.1.101: 255.255.255.255
                - grant_by_default: True

    Example of usage for allowing any source to connect:

    .. code-block:: yaml

        smtp-connection-blacklist:
            win_smtp_server.connection_ip_list:
                - addresses: {}
                - grant_by_default: True

def connection_ip_list(name, addresses=None, grant_by_default=False, server=_DEFAULT_SERVER):
    '''
    Manage IP list for SMTP connections.

    :param str addresses: A dictionary of IP + subnet pairs.
    :param bool grant_by_default: Whether the addresses should be a blacklist or whitelist.
    :param str server: The SMTP server name.

    Example of usage for creating a whitelist:

    .. code-block:: yaml

        smtp-connection-whitelist:
            win_smtp_server.connection_ip_list:
                - addresses:
                    127.0.0.1: 255.255.255.255
                    172.16.1.98: 255.255.255.255
                    172.16.1.99: 255.255.255.255
                - grant_by_default: False

    Example of usage for creating a blacklist:

    .. code-block:: yaml

        smtp-connection-blacklist:
            win_smtp_server.connection_ip_list:
                - addresses:
                    172.16.1.100: 255.255.255.255
                    172.16.1.101: 255.255.255.255
                - grant_by_default: True

    Example of usage for allowing any source to connect:

    .. code-block:: yaml

        smtp-connection-blacklist:
            win_smtp_server.connection_ip_list:
                - addresses: {}
                - grant_by_default: True
    '''
    ret = {'name': name,
           'changes': {},
           'comment': six.text_type(),
           'result': None}
    if not addresses:
        addresses = dict()

    current_addresses = __salt__['win_smtp_server.get_connection_ip_list'](server=server)

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