summaryrefslogtreecommitdiff
path: root/service/pixelated
diff options
context:
space:
mode:
authorLisa Junger <ljunger@thoughtworks.com>2015-04-02 14:29:44 +0200
committerLisa Junger <ljunger@thoughtworks.com>2015-04-02 17:54:22 +0200
commit98ec21fedd2b27c6f28be993006380446f6b4abe (patch)
tree9fc14286c1a7a2e93cc26e5338a2d558a97dad93 /service/pixelated
parentf11d9b2811373de173f0e02ec334c85e46571172 (diff)
catch invalid data in received header when parsing date.
- Issue #347
Diffstat (limited to 'service/pixelated')
-rw-r--r--service/pixelated/adapter/model/mail.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/service/pixelated/adapter/model/mail.py b/service/pixelated/adapter/model/mail.py
index ff58b330..618b980a 100644
--- a/service/pixelated/adapter/model/mail.py
+++ b/service/pixelated/adapter/model/mail.py
@@ -323,15 +323,19 @@ class PixelatedMail(Mail):
def _get_date(self):
date = self.hdoc.content.get('date', None)
- if not date:
- received = self.hdoc.content.get('received', None)
- if received:
- date = received.split(";")[-1].strip()
- else:
- # we can't get a date for this mail, so lets just use now
- logger.warning('Encountered a mail with missing date and received header fields. Subject %s' % self.hdoc.content.get('subject', None))
- date = pixelated.support.date.iso_now()
- return dateparser.parse(date).isoformat()
+ try:
+ if not date:
+ received = self.hdoc.content.get('received', None)
+ if received:
+ date = received.split(";")[-1].strip()
+ else:
+ # we can't get a date for this mail, so lets just use now
+ logger.warning('Encountered a mail with missing date and received header fields. Subject %s' % self.hdoc.content.get('subject', None))
+ date = pixelated.support.date.iso_now()
+ return dateparser.parse(date).isoformat()
+ except (ValueError, TypeError) as e:
+ date = pixelated.support.date.iso_now()
+ return dateparser.parse(date).isoformat()
@property
def security_casing(self):