]> khamidou — GitHub mirrors - flanker.git/commitdiff
Allow multiple non-consecutive dots in a Hotmail address
authorLance McNearney <lance@mcnearney.net>
Mon, 25 Nov 2013 20:06:55 +0000 (12:06 -0800)
committerLance McNearney <lance@mcnearney.net>
Mon, 25 Nov 2013 20:06:55 +0000 (12:06 -0800)
flanker/addresslib/plugins/hotmail.py
tests/addresslib/plugins/hotmail_test.py

index b3e7a6fab2b690865257835d18142ea52cab9ce9..b81798f9b5f9f03853fb3e78f72a16bcfae182c0 100644 (file)
@@ -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
index f12dd7d360260536a0f8048fed13744253d48895..0fe14e2a85b9b0c5b2578cff7b4bb39f12e38900 100644 (file)
@@ -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)