Skip to content

normalize email addresses to their canonical form

Notifications You must be signed in to change notification settings

tokopedia/normalize_email

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

normalize-email

Based on

This repo is a golang port of JS library: https://github.com/iDoRecall/email-normalize

Introduction

normalize-email normalizes 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

Works for

Sample Normalizations

		// Gmail dots
		"a.b.c@gmail.com": "abc@gmail.com",
		"a.b.c@yahoo.com": "a.b.c@yahoo.com",

		// Google domains
		"a.b.c@googlemail.com": "abc@gmail.com",

		// Plus
		"a.b.c+tag@gmail.com": "abc@gmail.com",
		"a.b.c+tag@yahoo.com": "a.b.c+tag@yahoo.com",

		// Non-standard TLDs
		"a.b.c+tag@something.co.uk": "a.b.c+tag@something.co.uk",

		// Yahoo!
		"a.b.c.d+tag@yahoo.com": "a.b.c.d+tag@yahoo.com",
		"a.b.c-tag@yahoo.com":   "a.b.c@yahoo.com",
		"a.b.c-tag@yahoo.co.uk": "a.b.c@yahoo.co.uk",
		"a-b.c-tag@yahoo.ro":    "a@yahoo.ro",

		// Microsoft
		"a.b.c+tag@outlook.com":   "a.b.c@outlook.com",
		"a.b.c-tag@hotmail.com":   "a.b.c-tag@hotmail.com",
		"a.b.c-tag@outlook.co.uk": "a.b.c-tag@outlook.co.uk",
		"a.b.c+d@live.com":        "a.b.c@live.com",

		// Google Apps for Work
		"a.b.c+tag@idorecall.com": "a.b.c+tag@idorecall.com",

Usage

sync version

    ... 
    rawEmail := "john123.thomas123+test123@googlemail.com
    normEmail := normalize_email.Normalize(rawEmail, nil, nil)

    // normEmail == "john123.thomas@gmail.com"
    ...

async version for detect provider

    ... 
    callback = make(chan string)
    ... 
    rawEmail := "john123.thomas123+test123@googlemail.com
    _ := normalize_email.Normalize(rawEmail, &Option{DetectProvider: true}, callback)
    ... 
    normEmail := <- callback

    // normEmail == "john123.thomas@gmail.com"
    ...

Please also refer normalize_test.go for examples.

_

About

normalize email addresses to their canonical form

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%