Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions authheaders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,8 @@

def get_domain_part(address):
'''Return domain part of an email address'''
if sys.version_info < (3, 0) and isinstance(address, str):
address = bytes(address)
elif isinstance(address, str):
address = bytes(address, 'utf8')
res = re.findall(b'@([a-z0-9.]+)', address, re.IGNORECASE)
return res[0].lower().decode('ascii')
res = re.findall(r'@([-a-z0-9.]+)', address, re.IGNORECASE)
return res[-1].lower()


def check_psddmarc_list(psdname, dnsfunc=dns_query):
Expand Down
9 changes: 8 additions & 1 deletion authheaders/test/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,14 @@ def test_prev(self):
self.assertEqual(res, "Authentication-Results: example.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=example.com header.i=@example.com")

def test_get_domain_part(self):
froms_to_test = [['test@example.com', 'example.com'], [""""Test, User" <test@example.com>""", 'example.com'], ["""Test User <test@sub2.example.biz>""", 'sub2.example.biz'], ["""=?UTF-8?B?QmVkIEJhdGggJiBCZXlvbmQ=?=<BdBth&Byond@example.com>""", 'example.com'], ]
froms_to_test = [
['test@example.com', 'example.com'],
['test@UPPER.hyphen-minus.example.com', 'upper.hyphen-minus.example.com'],
[""""Test, User" <test@example.com>""", 'example.com'],
[""""Test@User display name" <test@example.com>""", 'example.com'],
["""Test User <test@sub2.example.biz>""", 'sub2.example.biz'],
["""=?UTF-8?B?QmVkIEJhdGggJiBCZXlvbmQ=?=<BdBth&Byond@example.com>""", 'example.com'],
]
for body_from in froms_to_test:
res = get_domain_part(body_from[0])
self.assertEqual(res, body_from[1])
Expand Down