Mark Sapiro pushed to branch master at GNU Mailman / Mailman Core


Commits:
4207d38d by Mark Sapiro at 2020-09-12T17:21:05-07:00
Generate a missing Message-ID: in LMTP runner.

- - - - -
2a3a6ac9 by Mark Sapiro at 2020-09-13T00:44:17+00:00
Merge branch 'msgid' into 'master'

Generate a missing Message-ID: in LMTP runner.

Closes #490 and #448

See merge request mailman/mailman!701
- - - - -


3 changed files:

- src/mailman/docs/NEWS.rst
- src/mailman/runners/lmtp.py
- src/mailman/runners/tests/test_lmtp.py


Changes:

=====================================
src/mailman/docs/NEWS.rst
=====================================
@@ -41,6 +41,8 @@ Bugs
 * VERPed list welcome messages now have a correct envelope sender.
   (Closes #757)
 * Messages in digests now contain a ``Message: N`` header.  (Closes #764)
+* The LMTP runner will now add a ``Message-ID:`` header if missing.
+  (Closes #448 and #490)
 
 Command line
 ------------


=====================================
src/mailman/runners/lmtp.py
=====================================
@@ -91,7 +91,6 @@ ERR_451 = '451 Requested action aborted: error in processing'
 ERR_501 = '501 Message has defects'
 ERR_502 = '502 Error: command HELO not implemented'
 ERR_550 = '550 Requested action not taken: mailbox unavailable'
-ERR_550_MID = '550 No Message-ID header provided'
 
 
 def split_recipient(address):
@@ -145,7 +144,13 @@ class LMTPHandler:
         # other missing information.
         message_id = msg.get('message-id')
         if message_id is None:
-            return ERR_550_MID
+            # We have observed cases in the wild where bounce DSNs have no
+            # Message-ID; header.  Also, there are brain dead phone clients
+            # that don't include a Message-ID: header.  Thus, we cave and
+            # generate one. See https://gitlab.com/mailman/mailman/-/issues/448
+            # and https://gitlab.com/mailman/mailman/-/issues/490.
+            message_id = email.utils.make_msgid()
+            msg['Message-ID'] = message_id
         if msg.defects:
             return ERR_501
         msg.original_size = len(envelope.content)


=====================================
src/mailman/runners/tests/test_lmtp.py
=====================================
@@ -43,21 +43,16 @@ class TestLMTP(unittest.TestCase):
         self._lmtp.lhlo('remote.example.org')
         self.addCleanup(self._lmtp.close)
 
-    def test_message_id_required(self):
-        # The message is rejected if it does not have a Message-ID header.
-        with self.assertRaises(smtplib.SMTPDataError) as cm:
-            self._lmtp.sendmail('a...@example.com', ['t...@example.com'], """\
+    def test_message_id_supplied_if_missing(self):
+        # A Message-ID header is generated if the message doesn't have one.
+        self._lmtp.sendmail('a...@example.com', ['t...@example.com'], """\
 From: a...@example.com
 To: t...@example.com
 Subject: This has no Message-ID header
 
 """)
-        # LMTP returns a 550: Requested action not taken: mailbox unavailable
-        # (e.g., mailmailman.runners.tests.test_lmtp.TestLMTPbox not found, no
-        # access, or command rejected for policy reasons)
-        self.assertEqual(cm.exception.smtp_code, 550)
-        self.assertEqual(cm.exception.smtp_error,
-                         b'No Message-ID header provided')
+        items = get_queue_messages('in', expected_count=1)
+        self.assertIsNotNone(items[0].msg.get('message-id'))
 
     def test_message_id_hash_is_added(self):
         self._lmtp.sendmail('a...@example.com', ['t...@example.com'], """\



View it on GitLab: 
https://gitlab.com/mailman/mailman/-/compare/fb6c2b44de7cd73bdb31f170e85e1d07710a686b...2a3a6ac912f2844194d95f4627b5b09eff9d24f0

-- 
View it on GitLab: 
https://gitlab.com/mailman/mailman/-/compare/fb6c2b44de7cd73bdb31f170e85e1d07710a686b...2a3a6ac912f2844194d95f4627b5b09eff9d24f0
You're receiving this email because of your account on gitlab.com.


_______________________________________________
Mailman-checkins mailing list -- mailman-checkins@python.org
To unsubscribe send an email to mailman-checkins-le...@python.org
https://mail.python.org/mailman3/lists/mailman-checkins.python.org/
Member address: arch...@jab.org

Reply via email to