Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

address-rfc2822

haraka20kMIT2.2.3

RFC 2822 & 5322 (Header) email address parser

email, address, rfc822, rfc2822, rfc5322, mail, from

readme

Build Status Code Climate Coverage Status

address-rfc2822

Parser for RFC 2822 & 5322 (Header) format email addresses.

This module parses RFC 2822 headers containing addresses such as From, To, CC, and BCC headers.

It is almost a direct port of the perl module Mail::Address and I'm grateful to the original authors of that module for the clean code and the tests.

Installation

npm install address-rfc2822

Usage

const addrparser = require('address-rfc2822')

const addresses = addrparser.parse('Matt Sergeant <helpme+npm@gmail.com>')
const address = addresses[0]

console.log(`Email address: ${address.address}`) // helpme+npm@gmail.com
console.log(`Email name: ${address.name()}`)     // Matt Sergeant
console.log(`Reformatted: ${address.format()}`)  // Matt Sergeant <helpme+npm@gmail.com>
console.log(`User part: ${address.user()}`)      // helpme+npm
console.log(`Host part: ${address.host()}`)      // gmail.com

More Info

License

This module is MIT licensed.

changelog

Changelog

The format is based on Keep a Changelog.

Unreleased

2.2.3 - 2025-01-13

  • dep(eslint): upgrade to v9

2.2.2 - 2024-04-29

  • doc(CONTRIBUTORS): added
  • dep(eslint-config): bumped to 1.1.5
  • chore: prettier

2.2.1 - 2024-04-08

  • dep: eslint-plugin-haraka -> @haraka/eslint-config
  • populate [files] in package.json. Delete .npmignore.
  • updated scripts{} in package.json
  • lint: remove duplicate / stale rules from .eslintrc
  • prettier (except index)

2.2.0 - 2024-02-23

  • feat: option to allow comma in display name #52
  • dep(email-addresses): bump from 4.0.0 to 5.0.0 #58
  • chore: replace a couple regex with slice (perf & sec) #63
  • test: a few more tests to boost coverage #63
  • test: drop node 10, add node 16 #61
  • ci: restore GH workflow for PRs #57
  • ci: add dependabot.yml #55
  • doc: add inline documentation for parse #60
  • doc(Changes): make PR #s into links #54
  • doc(README): add result of console.logs #56
  • doc(README): add links to RFC 2822, 5322 #53
  • doc(README): enabled syntax highlighting with code fences #51

2.1.0 - 2021-02-26

  • make parse accept an options object as second argument
  • allow comma (,) in display name, default off #52

2.0.6 - 2020-11-17

  • replace travis/appveyor CI tests with Github Actions #48
  • test: when splitting lines, use os.EOL
  • allow @ symbol in display name #47

2.0.5 - 2020-06-02

  • update email-addresses to 3.1.0 #46
  • test framework: nodeunit -> mocha

2.0.4 - 2018-06-29

  • throw a proper error object, not a string.

2.0.3 - 2018-03-01

  • use es6 classes
  • export the Address class #29

2.0.2 - 2018-02-24

  • Fix a possible regexp backtracking DoS #28

2.0.1 - 2017-06-26

  • trim the line in parse() #24

1.0.2 - 2016-06-16

  • updated for eslint 4 compat #23
  • use email-addresses for parser #20

1.0.1 - 2016-09-23

  • use native to[lower|upper]Case functions vs regex
  • remove node 0.12 testing
  • remove node 0.10, 5, add node 6
  • throw error on nothing to parse

1.0.0 - 2016-02-23

  • Initial implementation