basic support for timestamps and other attributes twisty
authorMark Hammond <mhammond@skippinet.com.au>
Mon, 23 Mar 2009 16:50:06 +1100
branchtwisty
changeset 115 20624eb48d8c2516b80c37697e70caba7b248a83
parent 114 652cc177430ece2c1c7e026ea3c539dc301ae45b
child 116 ffb62f887469d4ed1b8944b9439aedf069e5e6ee
push id1
push userroot
push dateWed, 08 Apr 2009 01:46:05 +0000
basic support for timestamps and other attributes
server/python/junius/ext/message/rfc822.py
--- a/server/python/junius/ext/message/rfc822.py
+++ b/server/python/junius/ext/message/rfc822.py
@@ -1,23 +1,34 @@
 # This is an extension which converts a message/raw/rfc822 to a
 # message/raw/rfc822
 from __future__ import absolute_import # stop 'email' import finding our ext
 
 import logging
 from email.parser import HeaderParser
+from email.utils import mktime_tz, parsedate_tz
 from twisted.internet import defer
 
 
 logger = logging.getLogger(__name__)
 
 from ...proc import base
 
 class RFC822Converter(base.ConverterBase):
     def __init__(self, *args, **kw):
         super(RFC822Converter, self).__init__(*args, **kw)
         self.hdr_parser = HeaderParser()
     def convert(self, doc):
-        msg = self.hdr_parser.parsestr(doc['headers'])
+        msg = self.hdr_parser.parsestr(doc['headers'])
         # for now, 'from' etc are all tuples of [identity_type, identity_id]
-        return {'from': ['email', msg['from']],
-                'subject': msg['subject'],
-                'body': doc['body']}
+        ret = {'from': ['email', msg['from']],
+               'subject': msg['subject'],
+               'body': doc['body'],
+               'body_preview': doc['body'][:128],
+        }
+        try:
+            dval = msg['Date']
+        except KeyError:
+            pass
+        else:
+            if dval:
+                ret['timestamp'] = mktime_tz(parsedate_tz(dval))
+        return ret