From 05ce6569227ecfc24a6efca89f8cda59f8e08d12 Mon Sep 17 00:00:00 2001 From: Lance McNearney Date: Mon, 25 Nov 2013 12:06:55 -0800 Subject: [PATCH] Allow multiple non-consecutive dots in a Hotmail address --- flanker/addresslib/plugins/hotmail.py | 15 +++++++++------ tests/addresslib/plugins/hotmail_test.py | 13 +++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/flanker/addresslib/plugins/hotmail.py b/flanker/addresslib/plugins/hotmail.py index b3e7a6f..b81798f 100644 --- a/flanker/addresslib/plugins/hotmail.py +++ b/flanker/addresslib/plugins/hotmail.py @@ -10,7 +10,6 @@ must end with letter, number, hyphen (-), or underscore (_) must use letters, numbers, periods (.), hypens (-), or underscores (_) only one plus (+) is allowed - only one dot (.) is allowed case is ignored Grammar: @@ -25,7 +24,7 @@ Other limitations: - 1. No more than a single dot (.) is allowed in the local-part + 1. Only one consecutive period (.) is allowed in the local-part 2. Length of local-part must be no more than 64 characters, and no less than 1 characters. @@ -49,6 +48,10 @@ PLUS = re.compile(r''' \+ ''', re.MULTILINE | re.VERBOSE) +PERIODS = re.compile(r''' + \.{2,} + ''', re.MULTILINE | re.VERBOSE) + def validate(localpart): # check string exists and not empty @@ -72,14 +75,14 @@ def validate(localpart): if HOTMAIL_SUFFIX.match(real_localpart[-1]) is None: return False - # no more than one dot (.) - if localpart.count('.') > 1: - return False - # no more than one plus (+) if localpart.count('+') > 1: return False + # no consecutive periods (..) + if PERIODS.search(localpart): + return False + # grammar check retval= _validate(real_localpart) return retval diff --git a/tests/addresslib/plugins/hotmail_test.py b/tests/addresslib/plugins/hotmail_test.py index f12dd7d..0fe14e2 100644 --- a/tests/addresslib/plugins/hotmail_test.py +++ b/tests/addresslib/plugins/hotmail_test.py @@ -64,16 +64,17 @@ def test_hotmail_pass(): addr = address.validate_address(localpart + DOMAIN) assert_not_equal(addr, None) - # only zero or one dot (.) or plus allowed + # only zero or one plus allowed for i in range(0, 2): - localpart = 'aa' + '.'*i + '00' - addr = address.validate_address(localpart + DOMAIN) - assert_not_equal(addr, None) - localpart = 'aa' + '+'*i + '00' addr = address.validate_address(localpart + DOMAIN) assert_not_equal(addr, None) + # allow multiple periods + localpart = 'aa.bb.00' + addr = address.validate_address(localpart + DOMAIN) + assert_not_equal(addr, None) + def test_hotmail_fail(): with patch.object(validate, 'mail_exchanger_lookup') as mock_method: @@ -112,7 +113,7 @@ def test_hotmail_fail(): addr = address.validate_address(localpart + DOMAIN) assert_equal(addr, None) - # no more than 1 dot (.) or plus (+) allowed + # no more than 1 consecutive dot (.) or plus (+) allowed for i in range(2, 4): localpart = 'aa' + '.'*i + '00' addr = address.validate_address(localpart + DOMAIN) -- 2.43.0