diff --git a/CHANGES.rst b/CHANGES.rst index 711718c..4ef5691 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,12 @@ Changelog 5.2 (unreleased) ---------------- +- Use SMTP compatible line separators in generated messages. + +- Remove doc string from the MailHost ``sendTemplate`` method + to prevent publishing. + + 5.1 (2024-02-07) ---------------- diff --git a/src/Products/MailHost/MailHost.py b/src/Products/MailHost/MailHost.py index db6f316..1f7aef4 100644 --- a/src/Products/MailHost/MailHost.py +++ b/src/Products/MailHost/MailHost.py @@ -183,8 +183,8 @@ def sendTemplate(trueself, immediate=False, charset=None, msg_type=None): - """Render a mail template, then send it... - """ + # Render a mail template, then send it... + # mtemplate = getattr(self, messageTemplate) messageText = mtemplate(self, trueself.REQUEST) trueself.send(messageText, mto=mto, mfrom=mfrom, @@ -224,8 +224,8 @@ def send(self, @security.protected(use_mailhost_services) def simple_send(self, mto, mfrom, subject, body, immediate=False): - body = f'From: {mfrom}\nTo: {mto}\nSubject: {subject}\n\n{body}' - self._send(mfrom, mto, body, immediate) + msg = f'From: {mfrom}\nTo: {mto}\nSubject: {subject}\n\n{body}' + self.send(msg, immediate=immediate) def _makeMailer(self): """ Create a SMTPMailer """ diff --git a/src/Products/MailHost/tests/testMailHost.py b/src/Products/MailHost/tests/testMailHost.py index 301b0f4..87a17fa 100644 --- a/src/Products/MailHost/tests/testMailHost.py +++ b/src/Products/MailHost/tests/testMailHost.py @@ -14,6 +14,7 @@ """ import os.path +import re import shutil import tempfile import unittest @@ -208,11 +209,11 @@ def testSendWithMtoList(self): self.assertEqual(mailhost.sent, outmsg) def testSimpleSend(self): - outmsg = """\ -From: sender@example.com -To: "Name, Nick" , "Foo Bar" -Subject: This is the subject - + outmsg = b"""\ +From: sender@example.com\r +To: "Name, Nick" , "Foo Bar" \r +Subject: This is the subject\r +\r This is the message body.""" mailhost = self._makeOne('MailHost') @@ -221,15 +222,15 @@ def testSimpleSend(self): mfrom='sender@example.com', subject='This is the subject', body='This is the message body.') - self.assertEqual(mailhost.sent, outmsg) + self.assertEqual(_rm_date(mailhost.sent), outmsg) self.assertEqual(mailhost.immediate, False) def testSendImmediate(self): - outmsg = """\ -From: sender@example.com -To: "Name, Nick" , "Foo Bar" -Subject: This is the subject - + outmsg = b"""\ +From: sender@example.com\r +To: "Name, Nick" , "Foo Bar" \r +Subject: This is the subject\r +\r This is the message body.""" mailhost = self._makeOne('MailHost') @@ -239,7 +240,7 @@ def testSendImmediate(self): subject='This is the subject', body='This is the message body.', immediate=True) - self.assertEqual(mailhost.sent, outmsg) + self.assertEqual(_rm_date(mailhost.sent), outmsg) self.assertEqual(mailhost.immediate, True) def testSendBodyWithUrl(self): @@ -745,3 +746,11 @@ def testNotStartQueueProcessorThread(self): self.assertFalse(mh.started_queue_processor_thread) md = zope.sendmail.maildir.Maildir(self.smtp_queue_directory) self.assertEqual(len(list(md)), 1) + + +_date_hdr_re = re.compile(b"^Date:.*\r\n", re.I | re.M) + + +def _rm_date(msg): + """remove a ``Date`` header from *msg* (bytes).""" + return _date_hdr_re.sub(b"", msg)