from os.path import isdir, join
from tempfile import mkdtemp
from shutil import rmtree
+from email import message
from email.errors import MultipartInvariantViolationDefect
+from datetime import datetime as dt
from src import mail_utils
self.assertIn('Subject', msg)
self.assertTrue(msg['Subject'].startswith(
r"Emailfilter test 7b25f7a3-115: b'2018\xe5\xb9\xb4\xe5\xba"))
+
+ def test_parse_mail_date(self):
+ """Test function parse_mail_date"""
+
+ 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)),
+ ('Wed, 26 Jun 2018 20:29:36 -0700 (PDT)',
+ dt(2018, 6, 26, 13, 29, 36)))
+
+ for to_parse, result in examples:
+ msg = message.Message()
+ msg['From'] = 'Autotest-Sender@localhost'
+ msg['To'] = 'Autotest-Recipient@localhost'
+ msg['Subject'] = 'Testing parse_mail_date'
+ msg['Date'] = to_parse
+ msg.set_unixfrom('Autotest-Sender@localhost')
+
+ self.assertEqual(mail_utils.parse_mail_date(msg), result)