[Commits] (bkirsch) Fixes bug #1964 by protecting against non-rfc compliant date strings in mail headers

commits at osafoundation.org commits at osafoundation.org
Fri Sep 24 14:29:02 PDT 2004


Commit by: bkirsch
Modified files:
chandler/parcels/osaf/mail/common.py 1.6 1.7
chandler/parcels/osaf/mail/message.py 1.21 1.22

Log message:
Fixes bug #1964 by protecting against non-rfc compliant date strings in mail headers

ViewCVS links:
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/mail/common.py.diff?r1=text&tr1=1.6&r2=text&tr2=1.7
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/mail/message.py.diff?r1=text&tr1=1.21&r2=text&tr2=1.22

Index: chandler/parcels/osaf/mail/common.py
diff -u chandler/parcels/osaf/mail/common.py:1.6 chandler/parcels/osaf/mail/common.py:1.7
--- chandler/parcels/osaf/mail/common.py:1.6	Tue Aug 24 16:19:38 2004
+++ chandler/parcels/osaf/mail/common.py	Fri Sep 24 14:29:01 2004
@@ -1,5 +1,5 @@
-__revision__  = "$Revision: 1.6 $"
-__date__      = "$Date: 2004/08/24 23:19:38 $"
+__revision__  = "$Revision: 1.7 $"
+__date__      = "$Date: 2004/09/24 21:29:01 $"
 __copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -9,6 +9,7 @@
 import email as email
 import email.Message as Message
 import email.Utils as Utils
+import mx.DateTime as DateTime
 
 CHANDLER_USERAGENT = "Chandler/.4B Release"
 CHANDLER_HEADER_PREFIX = "X-Chandler-"
@@ -23,6 +24,8 @@
 MIME_SECURITY = ["encrypted", "signed"]
 MIME_CONTAINER = ["alternative", "parallel", "related", "report", "partial", "digest"]
 
+DATE_IS_EMPTY = -57600
+
 class MailException(Exception):
     pass
 
@@ -38,6 +41,16 @@
     return email.message_from_string(message)
 
 
+def getEmptyDate():
+    return DateTime.DateFromTicks(0)
+
+def dateIsEmpty(date):
+    #XXX: Need to protect this better but having trouble with
+    #     the mx.DateTime API
+    if date is None or date.ticks() == DATE_IS_EMPTY:
+        return True
+
+    return False
 
 def disableTwistedTLS(items):
     """Disables SSL support for debugging so

Index: chandler/parcels/osaf/mail/message.py
diff -u chandler/parcels/osaf/mail/message.py:1.21 chandler/parcels/osaf/mail/message.py:1.22
--- chandler/parcels/osaf/mail/message.py:1.21	Wed Sep 15 11:12:02 2004
+++ chandler/parcels/osaf/mail/message.py	Fri Sep 24 14:29:01 2004
@@ -1,5 +1,5 @@
-__revision__  = "$Revision: 1.21 $"
-__date__      = "$Date: 2004/09/15 18:12:02 $"
+__revision__  = "$Revision: 1.22 $"
+__date__      = "$Date: 2004/09/24 21:29:01 $"
 __copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -14,7 +14,12 @@
 import common as common
 import logging as logging
 
-__exp = "\w+((-\w+)|(\.\w+)|(\_\w+))*\@[A-Za-z2-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]{2,5}"
+"""
+NOTES:
+-------
+1. There will be memory / performance problems with very large emails however emails over 10mb's are
+   rare so can deal with optimization at a later date
+"""
 
 
 def isValidEmailAddress(emailAddress):
@@ -167,13 +172,24 @@
     date = messageObject['Date']
 
     if date is not None:
-        m.dateSent = DateTime.mktime(Utils.parsedate(date))
+        parsed = Utils.parsedate(date)
+
+        """It is a non-rfc date string"""
+        if parsed is None:
+            if __debug__:
+                logging.warn("Message contains a Non-RFC Compliant Date format")
+
+            m.dateSent = common.getEmptyDate() 
+
+        else:
+            m.dateSent = DateTime.mktime(parsed)
+
         m.dateSentString = date
         del messageObject['Date']
 
-    #XXX: Will this fail at the Repository level
     else:
-        m.dateSent = None
+        m.dateSent = common.getEmptyDate() 
+        m.dateSentString = ""
 
     m.dateReceived = DateTime.now()
 
@@ -221,8 +237,6 @@
                 m.body = strToText(m, "body",  mimePart.get_payload())
                 found = True
 
-
-
         if not found:
             m.body = strToText(m, "body", common.ATTACHMENT_BODY_WARNING)
 
@@ -393,7 +407,7 @@
 
             # Use any existing EmailAddress, but don't update them
             #  because that will cause the item to go stale in the UI thread.
-            ea = Mail.EmailAddress.getEmailAddress(addr[1], 
+            ea = Mail.EmailAddress.getEmailAddress(addr[1],
                                                    **keyArgs)
 
             setattr(kindVar, attr, ea)



More information about the Commits mailing list