utils.py: separate function extract_email_id from header format XY <xy@abc.com>

This commit is contained in:
Rushabh Mehta 2011-07-18 17:08:02 +05:30
parent 722c78f760
commit 5a9017211e

View file

@ -22,14 +22,21 @@ def getCSVelement(v):
return '"'+v+'"'
else: return v or ''
def validate_email_add(email_str):
def extract_email_id(s):
"""
Validates the email string
Extract email id from email header format
"""
s = email_str
if '<' in s:
s = s.split('<')[1].split('>')[0]
if s: s = s.strip().lower()
if s:
s = s.strip().lower()
return s
def validate_email_add(email_str):
"""
Validates the email string
"""
s = extract_email_id(email_str)
import re
#return re.match("^[a-zA-Z0-9._%-]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", email_str)
return re.match("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", s)