diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index 5c2229d49bc..ab692879343 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -24,6 +24,7 @@ import base64 import dateutil.parser import email import logging +import pytz import re import time from email.header import decode_header @@ -398,7 +399,15 @@ class mail_message(osv.osv): if 'Date' in fields: date_hdr = decode(msg_txt.get('Date')) - msg['date'] = dateutil.parser.parse(date_hdr).strftime("%Y-%m-%d %H:%M:%S") + parsed_date = dateutil.parser.parse(date_hdr) + if parsed_date.utcoffset() is None: + # naive datetime, so we arbitrarily decide to make it + # UTC, there's no better choice. Should not happen, + # as RFC2822 requires timezone offset in Date headers. + stored_date = parsed_date.replace(tzinfo=pytz.utc) + else: + stored_date = parsed_date.astimezone(pytz.utc) + msg['date'] = stored_date.strftime("%Y-%m-%d %H:%M:%S") if 'Content-Transfer-Encoding' in fields: msg['encoding'] = msg_txt.get('Content-Transfer-Encoding')