[Commits] (bkirsch) Added improved validation and test for email
address equaility
commits at osafoundation.org
commits at osafoundation.org
Thu Aug 12 16:55:14 PDT 2004
Commit by: bkirsch
Modified files:
chandler/parcels/osaf/mail/message.py 1.5 1.6
Log message:
Added improved validation and test for email address equaility
ViewCVS links:
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/mail/message.py.diff?r1=text&tr1=1.5&r2=text&tr2=1.6
Index: chandler/parcels/osaf/mail/message.py
diff -u chandler/parcels/osaf/mail/message.py:1.5 chandler/parcels/osaf/mail/message.py:1.6
--- chandler/parcels/osaf/mail/message.py:1.5 Wed Aug 11 16:35:19 2004
+++ chandler/parcels/osaf/mail/message.py Thu Aug 12 16:55:13 2004
@@ -1,5 +1,5 @@
-__revision__ = "$Revision: 1.5 $"
-__date__ = "$Date: 2004/08/11 23:35:19 $"
+__revision__ = "$Revision: 1.6 $"
+__date__ = "$Date: 2004/08/12 23:55:13 $"
__copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
__license__ = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
@@ -10,24 +10,58 @@
import email.Utils as Utils
import re as re
+__exp = re.compile("\w+((-\w+)|(\.\w+)|(\_\w+))*\@[A-Za-z2-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]{2,5}")
+
def isValidEmailAddress(emailAddress):
"""
This method tests an email address for valid syntax as defined RFC 822
- ***Warning*** This method will return False if Name and Address is past
+ ***Warning*** This method will return False if Name and Address is past
i.e. John Jones <john at jones.com>. The method only validates against the actual
email address i.e. john at jones.com
- @param emailAddress: A string containing a email address to validate. Please see ***Warning*** for more
+ @param emailAddress: A string containing a email address to validate. Please see ***Warning*** for more
details
@type addr: C{String}
@return: C{Boolean}
"""
+ if type(emailAddress) != str:
+ return False
+
+ emailAddress = emailAddress.strip()
+
+ #XXX: Test id the address is in the form John test <john at test.com and handle it>
+ #emailAddress = Utils.parseaddr(emailAddress)[1]
- if hasValue(emailAddress) and len(emailAddress.strip()) > 3:
- if re.match("\w+((-\w+)|(\.\w+)|(\_\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]{2,5}", emailAddress) is not None:
+ if len(emailAddress) > 3:
+ if __exp.match(emailAddress) is not None:
return True
+
return False
+def emailAddressesAreEqual(emailAddressOne, emailAddressTwo):
+ """
+ This method tests whether two email addresses are the same.
+ Addresses can be in the form john at jones.com or John Jones <john at jones.com>.
+ The method strips off the username and <> brakets if they exist and just compares
+ the actual email addresses for equality. It will not look to see if each
+ address is RFC 822 compliant only that the strings match. Use C{message.isValidEmailAddress}
+ to test for validity.
+
+ @param emailAddressOne: A string containing a email address to compare.
+ @type emailAddressOne: C{String}
+ @param emailAddressTwo: A string containing a email address to compare.
+ @type emailAddressTwo: C{String}
+ @return: C{Boolean}
+ """
+
+ if type(emailAddressOne) != str or type(emailAddressTwo) != str:
+ return False
+
+ emailAddressOne = Utils.parseaddr(emailAddressOne)[1]
+ emailAddressTwo = Utils.parseaddr(emailAddressTwo)[1]
+
+ return emailAddressOne.lower() == emailAddressTwo.lower()
+
def hasValue(value):
"""
More information about the Commits
mailing list