Skip to content

Commit

Permalink
Add substitute domains for canonical representation (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed Mar 5, 2018
1 parent a773c02 commit f85fcb0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
9 changes: 6 additions & 3 deletions mxsniff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down
18 changes: 16 additions & 2 deletions mxsniff/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,13 @@
'url': 'https://gmail.com/',
'domains': ['gmail.com', 'googlemail.com'],
'public': True,
'canonical_flags': {'lowercase': True, 'strip_periods': True},
'canonical_flags': {
'lowercase': True,
'strip_periods': True,
'substitute_domains': {
'googlemail.com': 'gmail.com'
}
},
},
'google-apps': {'mx': [
'aspmx.l.google.com',
Expand Down Expand Up @@ -433,7 +439,15 @@
'title': "Yahoo Mail",
'domains': ['rocketmail.com', 'yahoo.com', 'yahoo.co.uk', 'yahoo.co.in', 'ymail.com'],
'public': True,
'canonical_flags': {'lowercase': True},
'canonical_flags': {
'lowercase': True,
'substitute_domains': {
'rocketmail.com': 'yahoo.com',
'yahoo.co.uk': 'yahoo.com',
'yahoo.co.in': 'yahoo.com',
'ymail.com': 'yahoo.com',
},
},
},
'yandex': {'mx': [
'mx.yandex.net',
Expand Down

0 comments on commit f85fcb0

Please sign in to comment.