-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add substitute domains for canonical representation (#6)
- Loading branch information
Showing
2 changed files
with
22 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,7 +107,7 @@ class MXLookupException(Exception): | |
pass | ||
|
||
|
||
def canonical_email(email, lowercase=False, strip_periods=False): | ||
def canonical_email(email, lowercase=False, strip_periods=False, substitute_domains={}): | ||
""" | ||
Return a canonical representation of an email address to facilitate string | ||
comparison:: | ||
|
@@ -132,6 +132,9 @@ def canonical_email(email, lowercase=False, strip_periods=False): | |
mailbox = mailbox.lower() | ||
# Example.com --> example.com | ||
domain = domain.lower() | ||
# googlemail.com --> gmail.com | ||
if domain in substitute_domains: | ||
domain = substitute_domains[domain] | ||
# example, example.com --> [email protected] | ||
return '%s@%s' % (mailbox, domain) | ||
|
||
|
@@ -415,9 +418,9 @@ def main_internal(args, name='mxsniff'): | |
[ | ||
{"canonical": null, "domain": "example.com", "match": ["nomx"], "mx": [], "providers": [], "public": false, "query": "example.com"} | ||
] | ||
>>> main_internal(['Example <exam.ple@gmail.com>', '-v']) # doctest: +ELLIPSIS | ||
>>> main_internal(['Example <exam.ple+extra@googlemail.com>', '-v']) # doctest: +ELLIPSIS | ||
[ | ||
{"canonical": "[email protected]", "domain": "gmail.com", "match": ["google-gmail"], "mx": [...], "providers": [...], "public": true, "query": "Example <exam.ple@gmail.com>"} | ||
{"canonical": "[email protected]", "domain": "googlemail.com", "match": ["google-gmail"], "mx": [...], "providers": [...], "public": true, "query": "Example <exam.ple+extra@googlemail.com>"} | ||
] | ||
""" | ||
import argparse | ||
|
This file contains 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