From: Barış Metin <Talip-Baris.Metin@sophia.inria.fr>
Date: Fri, 11 Dec 2009 14:17:17 +0000 (+0000)
Subject: use regex to validate email address.
X-Git-Tag: PLCAPI-4.3-31~6
X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=f8f4dd18ee4895d2941b14a65c51d87ceed802fe;p=plcapi.git

use regex to validate email address.
was there a specific reason to try parsing the address manually? if so please let me know and I'll revert this.
---

diff --git a/PLC/Persons.py b/PLC/Persons.py
index 678697d2..8aa638ed 100644
--- a/PLC/Persons.py
+++ b/PLC/Persons.py
@@ -80,26 +80,12 @@ class Person(Row):
         """
 
         invalid_email = PLCInvalidArgument("Invalid e-mail address")
-        email_badchars = r'[][()<>|;^,\200-\377]'
 
-        # Pretty minimal, cheesy check.  We could do better...
-        if not email or email.count(' ') > 0:
+        if not email:
             raise invalid_email
-        if re.search(email_badchars, email) or email[0] == '-':
-            raise invalid_email
-
-        email = email.lower()
-        at_sign = email.find('@')
-        if at_sign < 1:
-            raise invalid_email
-        user = email[:at_sign]
-        rest = email[at_sign+1:]
-        domain = rest.split('.')
 
-        # This means local, unqualified addresses, are not allowed
-        if not domain:
-            raise invalid_email
-        if len(domain) < 2:
+        email_re = re.compile('[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-_]+\.[a-zA-Z]+')
+        if not email_re.match(email):
             raise invalid_email
 
        	# check only against users on the same peer