How to use the haraka-net-utils.get_public_ip function in haraka-net-utils

To help you get started, we’ve selected a few haraka-net-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github haraka / Haraka / plugins / spf.js View on Github external
});
        plugin.return_results(next, connection, spf, 'mfrom', result, mfrom);
    }

    // typical inbound (!relay)
    if (!connection.relaying) {
        return spf.check_host(connection.remote.ip, host, mfrom, ch_cb);
    }

    // outbound (relaying), context=sender
    if (plugin.cfg.relay.context === 'sender') {
        return spf.check_host(connection.remote.ip, host, mfrom, ch_cb);
    }

    // outbound (relaying), context=myself
    net_utils.get_public_ip((e, my_public_ip) => {
        // We always check the client IP first, because a relay
        // could be sending inbound mail from a non-local domain
        // which could case an incorrect SPF Fail result if we
        // check the public IP first, so we only check the public
        // IP if the client IP returns a result other than 'Pass'.
        spf.check_host(connection.remote.ip, host, mfrom, (err, result) => {
            let spf_result;
            if (result) {
                spf_result = spf.result(result).toLowerCase();
            }
            if (err || (spf_result && spf_result !== 'pass')) {
                if (e) return ch_cb(e);  // Error looking up public IP

                if (!my_public_ip) {
                    return ch_cb(new Error(`failed to discover public IP`));
                }