Commits

Jason S committed 2cef0b1

parsing of date from messageSubmissionId if present

  • Participants
  • Parent commits bd4504f

Comments (0)

Files changed (1)

bookcasedb/msgmetadata.py

 @author: jmsachs
 '''
 
+import datetime
 import collections
 import re
 import OleFileIO_PL as ole
         
 substgre = re.compile('__substg1.0_([0-9A-Fa-f]{8})')
 recipre = re.compile('__recip_version1.0_#([0-9A-Fa-f]{8})')
+msgdatere = re.compile(r';l=[A-Za-z0-9-]+-(\d{12})Z-\d{4}')
 
 '''
 Sources:
 FMT_ASCII = 0x1e
 FMT_BINARY = 0x0102
 
+def readStream(olef, itempath, f=None):
+    st_type = olef.get_type(itempath)
+    if st_type == ole.STGTY_STREAM:
+        obj = olef.openstream(itempath)
+        data = obj.read()
+        return data if f is None else f(data)
+    return None    
+
 def getProperty(olef, itempath):
     name = itempath[-1]
     m = substgre.match(name)
         if prid in mailProperties:
             (prname, relevant) = mailProperties[prid]
             if fmt == FMT_UNICODE:
-                st_type = olef.get_type(itempath)
-                if st_type == ole.STGTY_STREAM:
-                    obj = olef.openstream(itempath)
-                    value = unicode(obj.read(), 'utf16')
+                value = readStream(olef, itempath, lambda s: unicode(s,'utf16'))
+                if value is not None:
                     return (prname, value)
+            elif prid == 0x0047:
+                return (prname, readStream(olef, itempath))
         elif prid < 0x8000:
             print "unknown property %04x format %04x" % (prid, fmt)
     return None
 
+def getDerivedMessageData(msgdata):
+    if 'messageSubmissionId' in msgdata:
+        m = msgdatere.search(msgdata['messageSubmissionId'])
+        if m:
+            msgdata['messageTime'] = datetime.datetime.strptime(m.group(1),'%y%m%d%H%M%S').isoformat()+'Z'
+    return msgdata        
+
+
 def readMetadataFromMsg(filepath):
     recipients = []
     msgdata = {'recipients': recipients} 
             else:
                 (k,v) = m
                 msgdata[k] = v
-
+    msgdata = getDerivedMessageData(msgdata)
     return {'user': {'msg': msgdata}}