from shutil import rmtree
from email import message
from email.errors import MultipartInvariantViolationDefect
-from datetime import datetime as dt
+from datetime import timezone, datetime as dt
from src import mail_utils
+UTC = timezone.utc
EMAIL_TEXT = r"""Return-Path: <autotest-sender@vm1.net.lan>
filename = self.create_mail()
msg, attachment_filenames = \
mail_utils.parse_mail_file(filename, attachment_filenames=True)
+ self.assertIsInstance(msg, message.Message)
if len(msg.defects) == 1:
# msg ContentType is multipart/mixed but with only headers,
# msg.is_multipart is False.
examples = (
('Fri, 15 May 2009 17:58:28 +0000', dt(2009, 5, 15, 17, 58, 28)),
- ('Thu, 10 Sep 2015 14:45:23 +0200', dt(2015, 9, 10, 16, 45, 23)),
+ ('Thu, 10 Sep 2015 14:45:23 +0200', dt(2015, 9, 10, 12, 45, 23)),
('Wed, 26 Jun 2018 20:29:36 -0700 (PDT)',
- dt(2018, 6, 26, 13, 29, 36)))
+ dt(2018, 6, 27, 3, 29, 36)))
for to_parse, result in examples:
msg = message.Message()
msg['Date'] = to_parse
msg.set_unixfrom('Autotest-Sender@localhost')
- self.assertEqual(mail_utils.parse_mail_date(msg), result)
+ self.assertEqual(mail_utils.parse_mail_date(msg).astimezone(UTC),
+ result.replace(tzinfo=UTC))
def test_latin1_mail(self):
"""Check reading mail with non-ascii chars not encoded with utf8"""