Skip to content

Instantly share code, notes, and snippets.

@okomarov
Created November 10, 2019 11:25
Show Gist options
  • Save okomarov/0b9c98d259544323a62221729bb2443b to your computer and use it in GitHub Desktop.
Save okomarov/0b9c98d259544323a62221729bb2443b to your computer and use it in GitHub Desktop.
viral queue email normalization
def normalize_email(email):
'''
Reduces an email address to its canonical form:
- strips white space
- transforms to lowercase
- removes the +tag part in the name
- removes dots if a google domain
'''
email = email.strip().lower()
name, domain = email.rsplit('@', 1)
try:
name, _ = name.rsplit('+', 1)
except ValueError:
pass
if domain in ['googlemail.com', 'gmail.com', 'google.com']:
name = name.replace('.', '')
return name + '@' + domain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment