How to use address-rfc2822 - 8 common examples

To help you get started, we’ve selected a few address-rfc2822 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 / dkim_sign.js View on Github external
// If From has a single address, we're done
    if (addrs.length === 1 && addrs[0].host) {
        let fromHost = addrs[0].host();
        if (fromHost) {
            // don't attempt to lower a null or undefined value #1575
            fromHost = fromHost.toLowerCase();
        }
        return fromHost;
    }

    // If From has multiple-addresses, we must parse and
    // use the domain in the Sender header.
    const sender = txn.header.get_decoded('Sender');
    if (sender) {
        try {
            domain = (addrparser.parse(sender))[0].host().toLowerCase();
        }
        catch (e) {
            connection.logerror(plugin, e);
        }
    }
    return domain;
}
github haraka / Haraka / plugins / dkim_sign.js View on Github external
connection.logerror(plugin, e);
        }
    }

    if (!txn.header) return domain;

    // the DKIM signing key should be aligned with the domain in the From
    // header (see DMARC). Try to parse the domain from there.
    const from_hdr = txn.header.get_decoded('From');
    if (!from_hdr) return domain;

    // The From header can contain multiple addresses and should be
    // parsed as described in RFC 2822 3.6.2.
    let addrs;
    try {
        addrs = addrparser.parse(from_hdr);
    }
    catch (e) {
        connection.logerror(plugin, `address-rfc2822 failed to parse From header: ${from_hdr}`)
        return domain;
    }
    if (!addrs || ! addrs.length) return domain;

    // If From has a single address, we're done
    if (addrs.length === 1 && addrs[0].host) {
        let fromHost = addrs[0].host();
        if (fromHost) {
            // don't attempt to lower a null or undefined value #1575
            fromHost = fromHost.toLowerCase();
        }
        return fromHost;
    }
github haraka / Haraka / plugins / access.js View on Github external
exports.data_any = function (next, connection) {
    var plugin = this;
    if (!plugin.cfg.check.data && !plugin.cfg.check.any) {
        connection.transaction.results.add(plugin, {skip: 'data(disabled)'});
        return next();
    }

    var hdr_from = connection.transaction.header.get('From');
    if (!hdr_from) {
        connection.transaction.results.add(plugin, {
            fail: 'data(missing_from)'});
        return next();
    }

    var hdr_addr = haddr.parse(hdr_from)[0];
    if (!hdr_addr) {
        connection.transaction.results.add(plugin, {
            fail: 'data(unparsable_from)'
        });
        return next();
    }
    var hdr_dom = tlds.get_organizational_domain(hdr_addr.host());

    var file = plugin.cfg.domain.any;
    if (plugin.in_list('domain', 'any', '!'+hdr_dom)) {
        connection.results.add(plugin, {
            pass: file, whitelist: true, emit: true});
        return next();
    }

    if (plugin.in_list('domain', 'any', hdr_dom)) {
github wanglian / workbase-server / imports / model / users.js View on Github external
username() {
    let attrs = addrparser.parse(this.email());
    return attrs.user();
  },
  email() {
github wanglian / workbase-server / imports / model / server / email-address-parser.js View on Github external
export const parseEmailAddress = (emails) => {
  emails = purgeEmails(emails);
  let result;
  try {
    result = emailParser.parse(emails);
  } catch (e) {
    emails = formatAddress(emails);
    result = emailParser.parse(emails);
  }
  return result;
};
github byteclubfr / mailbot / helpers.js View on Github external
const _parseAddressValue = (value, quiet = false) => {
	let parsed
	try {
		parsed = address.parse(value)[0]
	} catch (err) {
		debug('Error parsing address', value, err)
		if (quiet) {
			parsed = {}
		} else {
			throw err
		}
	}
	parsed.raw = value
	return parsed
}
github wanglian / workbase-server / imports / model / server / email-address-parser.js View on Github external
export const parseEmailAddress = (emails) => {
  emails = purgeEmails(emails);
  let result;
  try {
    result = emailParser.parse(emails);
  } catch (e) {
    emails = formatAddress(emails);
    result = emailParser.parse(emails);
  }
  return result;
};

address-rfc2822

RFC 2822 & 5322 (Header) email address parser

MIT
Latest version published 2 days ago

Package Health Score

73 / 100
Full package analysis

Popular address-rfc2822 functions