iDoRecall / email-normalize

Normalize email addresses to their canonical form: a.b+tag@gmail.com -> ab@gmail.com. Works for Google, Microsoft, FastMail, Yahoo!

Home Page:https://atmospherejs.com/idorecall/email-normalize

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

iDoRecall:email-normalize

Build Status Average time to resolve an issue Percentage of issues still open GitHub license

Client/server Meteor package to normalize email addresses to their canonical form:

  • remove dots in GMail or email addresses hosted by similar services (Google Apps for Work, FastMail)
  • remove address tags starting with '+', or '-' for Yahoo!, or '=' as well if desired
  • converts alias domains to the canonical one, e.g. googlemail.com to gmail

This is useful for a variety of reasons:

Works for

Pull requests to factor out the Meteor-independent code to use as a Node package are welcome.

Usage

The most common and general invocation is asynchronous:

let normalizedEmail = Email.normalize('a.b.c+tag@domain.com', {detectProvider: true}, function callback(error, result) {
  // result will be abc@domain.com if they use Google Apps, or unchanged otherwise
});

The general syntax is:

var normalizedEmail = Email.normalize(emailAddress, options, [callback]);  // abc@gmail.com

options is an object with the following keys, all optional:

  • forceRemovePeriods - default false
  • forceRemoveTags - default false; if true, will remove anything between the first '+', '-' or '=' and the '@' sign
  • detectProvider - default false because it makes a DNS lookup request for the MX record of the domain to see if it might be a Google Apps for Business or a Fastmail domain, in which case appropriate rules will apply. If detectProvider is true, a callback is required on the client and optional on the server.
  • callback - only required if detectProvider is true, and the code runs on the client

The email provider detection is done on the client by using the Enclout DNS API. If you run into any rate limits, please file an issue to add support for authentication.

Notes

If you're using this package to canonicalize email addresses for Gravatar, make sure to search (i.e. compute the hash for) the original email address first, since the user might legitimately always use something like first.last@gmail.com. Also, the original email address should always have priority (consider a user who has Gravatars for both user+games@example.com and user+professional@example.com).

When sending email use the original as well - it's respectful to your users to email them at the address they have supplied, since custom filter rules might depend on it.

Prior art

  • normalize-email npm package - doesn't support Yahoo! or FastMail. We started contributing by fixing the naive removal of dots from Microsoft accounts (which was an error), but it quickly became apparent that a more comprehensive approach was needed.
  • djanho-canonical-email - written in Python, doesn't support anything but Gmail
  • soundcloud/normailize - Ruby, not maintained since March 2013

License and copyright

Maintainer: Dan Dascalescu (@dandv)

Copyright (C) 2015 iDoRecall, Inc.

The MIT License (MIT)

About

Normalize email addresses to their canonical form: a.b+tag@gmail.com -> ab@gmail.com. Works for Google, Microsoft, FastMail, Yahoo!

https://atmospherejs.com/idorecall/email-normalize


Languages

Language:JavaScript 100.0%