Created
November 10, 2019 11:25
-
-
Save okomarov/0b9c98d259544323a62221729bb2443b to your computer and use it in GitHub Desktop.
viral queue email normalization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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