Skip to content

mogsdad/email-addresses

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

email-addresses.js

An RFC 5322 email address parser.

v 1.1.1

What?

Want to see if something could be an email address? Want to grab the display name or just the address out of a string? Put your regexes down and use this parser!

This library does not validate email addresses - we can't really do that without sending an email. However, it attempts to parse addresses using the (fairly liberal) grammar specified in RFC 5322. You can use this to check if user input looks like an email address.

Why use this?

Use this library because you can be sure it really respects the RFC:

  • The functions in the recursive decent parser match up with the productions in the RFC
  • The productions from the RFC are written above each function for easy verification
  • Tests include all of the test cases from the is_email project, which are extensive

Installation

Add as a library resource to Google Apps Script projects.

  • Publicly available, library key M26NvEFUvGLQadhq7G3OQmgFzUAA6_aCl.
  • Documentation available here.

The only file needed for Google Apps Script is lib/email-addresses.js.

Example

 var result = emailAddresses.parseOneAddress('"Jack Bowman" <[email protected]>');
 // { name: '"Jack Bowman"',
 //   address: '[email protected]',
 //   local: 'jack',
 //   domain: 'fogcreek.com' }
 result = emailAddresses.parseAddressList('[email protected], Bob <[email protected]>');
 // [ { name: null,
 //     address: '[email protected]',
 //     local: 'jack',
 //     domain: 'fogcreek.com' },
 //   { name: 'Bob',
 //     address: '[email protected]',
 //     local: 'bob',
 //     domain: 'example.com' } ]
 result = emailAddresses.parseOneAddress("bogus");
 // null

References

Props

Many thanks to Dominic Sayers and his documentation and tests for the is_email function which helped greatly in writing this parser.

License

Licensed under the MIT License. See the LICENSE file.

About

An RFC 5322 email address parser

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%