[mail] include Date header in generated mails (closes #5271058)
Mails without Date gets flagged as spam. Plus it's wrong anyway.
--- a/mail.py Wed Apr 01 15:06:45 2015 +0200
+++ b/mail.py Tue Apr 21 17:12:36 2015 +0200
@@ -25,6 +25,7 @@
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.header import Header
+from email.utils import formatdate
from socket import gethostname
def header(ustring):
@@ -110,6 +111,7 @@
msg['Message-id'] = msgid
if references:
msg['References'] = ', '.join(references)
+ msg['Date'] = formatdate()
return msg
--- a/test/unittest_mail.py Wed Apr 01 15:06:45 2015 +0200
+++ b/test/unittest_mail.py Tue Apr 21 17:12:36 2015 +0200
@@ -21,6 +21,7 @@
"""
import os
+import re
import sys
from logilab.common.testlib import unittest_main
@@ -51,7 +52,9 @@
mail = format_mail({'name': 'oim', 'email': 'oim@logilab.fr'},
['test@logilab.fr'], u'un petit cöucou', u'bïjour',
config=self.config)
- self.assertMultiLineEqual(mail.as_string(), """\
+ result = mail.as_string()
+ result = re.sub('^Date: .*$', 'Date: now', result, flags=re.MULTILINE)
+ self.assertMultiLineEqual(result, """\
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64
@@ -60,6 +63,7 @@
Reply-to: =?utf-8?q?oim?= <oim@logilab.fr>, =?utf-8?q?BimBam?= <bim@boum.fr>
X-CW: data
To: test@logilab.fr
+Date: now
dW4gcGV0aXQgY8O2dWNvdQ==
""")
@@ -74,7 +78,9 @@
def test_format_mail_euro(self):
mail = format_mail({'name': u'oîm', 'email': u'oim@logilab.fr'},
['test@logilab.fr'], u'un petit cöucou €', u'bïjour €')
- self.assertMultiLineEqual(mail.as_string(), """\
+ result = mail.as_string()
+ result = re.sub('^Date: .*$', 'Date: now', result, flags=re.MULTILINE)
+ self.assertMultiLineEqual(result, """\
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64
@@ -82,6 +88,7 @@
From: =?utf-8?q?o=C3=AEm?= <oim@logilab.fr>
Reply-to: =?utf-8?q?o=C3=AEm?= <oim@logilab.fr>
To: test@logilab.fr
+Date: now
dW4gcGV0aXQgY8O2dWNvdSDigqw=
""")