From 5a9017211e8e207b63d35f8945eb43c65dceae8a Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 18 Jul 2011 17:08:02 +0530 Subject: [PATCH] utils.py: separate function extract_email_id from header format XY --- cgi-bin/webnotes/utils/__init__.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/cgi-bin/webnotes/utils/__init__.py b/cgi-bin/webnotes/utils/__init__.py index 80f7f5af1a..22c854faf1 100644 --- a/cgi-bin/webnotes/utils/__init__.py +++ b/cgi-bin/webnotes/utils/__init__.py @@ -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)