summaryrefslogtreecommitdiff
path: root/service/pixelated
diff options
context:
space:
mode:
authorDuda Dornelles <ddornell@thoughtworks.com>2014-09-03 16:11:44 -0300
committerDuda Dornelles <ddornell@thoughtworks.com>2014-09-03 16:11:44 -0300
commite71ff5d379a5d764df60d0675a1f130d46f4318a (patch)
tree1a88f3289f0b5d3e970d0378fb2bb0f2040cd141 /service/pixelated
parent3bd6b15a18d5fc89506fb40becd7ad7b7449d7da (diff)
falling back to received header for date if email doesnt have date header
Diffstat (limited to 'service/pixelated')
-rw-r--r--service/pixelated/adapter/pixelated_mail.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/service/pixelated/adapter/pixelated_mail.py b/service/pixelated/adapter/pixelated_mail.py
index d20a93f4..7d34ac4f 100644
--- a/service/pixelated/adapter/pixelated_mail.py
+++ b/service/pixelated/adapter/pixelated_mail.py
@@ -31,7 +31,7 @@ class PixelatedMail:
mail.leap_mail = leap_mail
mail.body = leap_mail.bdoc.content['raw']
mail.headers = mail._extract_headers()
- mail.date = dateparser.parse(mail.headers['date'])
+ mail.date = PixelatedMail._get_date(mail.headers)
mail.ident = leap_mail.getUID()
mail.status = mail._extract_status()
mail.security_casing = {}
@@ -76,8 +76,10 @@ class PixelatedMail:
def as_dict(self):
tags = [tag.name for tag in self.tags]
statuses = [status.name for status in self.status]
+ _headers = self.headers.copy()
+ _headers['date'] = self.date
return {
- 'header': self.headers,
+ 'header': _headers,
'ident': self.ident,
'tags': tags,
'status': statuses,
@@ -103,6 +105,13 @@ class PixelatedMail:
def from_dict(mail_dict):
return from_dict(mail_dict)
+ @classmethod
+ def _get_date(cls, headers):
+ date = headers.get('date', None)
+ if not date:
+ date = headers['received'].split(";")[-1].strip()
+ return dateparser.parse(date).isoformat()
+
def from_dict(mail_dict):
mail = PixelatedMail()