[Commits] (bkirsch) Added email and string validation

commits at osafoundation.org commits at osafoundation.org
Wed Aug 11 16:35:20 PDT 2004


Commit by: bkirsch
Modified files:
chandler/parcels/osaf/mail/message.py 1.4 1.5

Log message:
Added email and string validation

ViewCVS links:
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/mail/message.py.diff?r1=text&tr1=1.4&r2=text&tr2=1.5

Index: chandler/parcels/osaf/mail/message.py
diff -u chandler/parcels/osaf/mail/message.py:1.4 chandler/parcels/osaf/mail/message.py:1.5
--- chandler/parcels/osaf/mail/message.py:1.4	Mon Aug  9 17:46:11 2004
+++ chandler/parcels/osaf/mail/message.py	Wed Aug 11 16:35:19 2004
@@ -1,5 +1,5 @@
-__revision__  = "$Revision: 1.4 $"
-__date__      = "$Date: 2004/08/10 00:46:11 $"
+__revision__  = "$Revision: 1.5 $"
+__date__      = "$Date: 2004/08/11 23:35:19 $"
 __copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -8,7 +8,43 @@
 import email as email
 import email.Message as Message
 import email.Utils as Utils
+import re as re
 
+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 
+    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 
+                         details
+    @type addr: C{String}
+    @return: C{Boolean}
+    """
+
+    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:
+            return True
+    return False
+
+
+def hasValue(value):
+    """
+    This method determines if a String has one or more non-whitespace characters.
+    This is useful in checking that a Subject or To address field was filled in with
+    a useable value
+
+    @param value: The String value to check against. The value can be None
+    @type value: C{String}
+    @return: C{Boolean}
+    """
+    if value is not None:
+        test = value.strip()
+        if len(test) > 0:
+            return True
+
+    return False
 
 # XXX: Relook at this logic
 def format_addr(addr):



More information about the Commits mailing list