An RFC 5322 email address parser.
v 1.1.1
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.
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
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.
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
Many thanks to Dominic Sayers and his documentation and tests for the is_email function which helped greatly in writing this parser.
Licensed under the MIT License. See the LICENSE file.