diff --git a/authheaders/__init__.py b/authheaders/__init__.py index 37a2c00..4dd0330 100644 --- a/authheaders/__init__.py +++ b/authheaders/__init__.py @@ -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): diff --git a/authheaders/test/test_authentication.py b/authheaders/test/test_authentication.py index 486b4c6..c981a8f 100755 --- a/authheaders/test/test_authentication.py +++ b/authheaders/test/test_authentication.py @@ -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" """, 'example.com'], ["""Test User """, 'sub2.example.biz'], ["""=?UTF-8?B?QmVkIEJhdGggJiBCZXlvbmQ=?=""", 'example.com'], ] + froms_to_test = [ + ['test@example.com', 'example.com'], + ['test@UPPER.hyphen-minus.example.com', 'upper.hyphen-minus.example.com'], + [""""Test, User" """, 'example.com'], + [""""Test@User display name" """, 'example.com'], + ["""Test User """, 'sub2.example.biz'], + ["""=?UTF-8?B?QmVkIEJhdGggJiBCZXlvbmQ=?=""", 'example.com'], + ] for body_from in froms_to_test: res = get_domain_part(body_from[0]) self.assertEqual(res, body_from[1])