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


Commits:
a68be9ef by Mark Sapiro at 2023-02-04T18:55:50+00:00
Fix observed bogus Message-ID headers.

Fixes #1065

* Fix observed bogus Message-ID headers.

- - - - -
36d75fbb by Mark Sapiro at 2023-02-04T18:55:51+00:00
Merge branch 'mid' into 'master'

Fix observed bogus Message-ID headers.

Closes #1065

See merge request mailman/mailman!1099

Merged-by: Mark Sapiro <m...@msapiro.net>

Reviewed-by: 
- - - - -


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
=====================================
@@ -32,6 +32,8 @@ Bugs fixed
   reset so it will be zero if delivery is enabled.  (Closes #1061)
 * The ``mailman shell`` command now works and displays the banner with
   ``use_ipython: yes``.  (Closes #1062)
+* Bogus Message-ID headers that have been observed in the wild are now fixed.
+  (Closes #1065)
 
 .. _news-3.3.8:
 


=====================================
src/mailman/runners/lmtp.py
=====================================
@@ -34,6 +34,7 @@ so that the peer mail server can provide better diagnostics.
     http://www.faqs.org/rfcs/rfc2033.html
 """
 
+import re
 import email
 import logging
 
@@ -198,6 +199,10 @@ class LMTPHandler:
             # and https://gitlab.com/mailman/mailman/-/issues/490.
             message_id = email.utils.make_msgid()
             msg['Message-ID'] = message_id
+        # Workaround for bogus Message-IDs. See #1065.
+        new_mid = re.sub(r'^<?\[(.*)\]>?', r'<\1>', message_id)
+        if new_mid != message_id:
+            msg.replace_header('Message-ID', new_mid)
         if msg.defects:
             return ERR_501
         msg.original_size = len(envelope.content)


=====================================
src/mailman/runners/tests/test_lmtp.py
=====================================
@@ -66,6 +66,30 @@ Subject: This has no Message-ID header
         items = get_queue_messages('in', expected_count=1)
         self.assertIsNotNone(items[0].msg.get('message-id'))
 
+    def test_bogus_message_id_is_fixed(self):
+        # fix bogus Message-ID with []
+        self._lmtp.sendmail('a...@example.com', ['t...@example.com'], """\
+From: a...@example.com
+To: t...@example.com
+Subject: Bogus [] Message-ID
+Message-ID: [bo...@example.com]
+
+""")
+        items = get_queue_messages('in', expected_count=1)
+        self.assertEqual('<bo...@example.com>', items[0].msg.get('message-id'))
+
+    def test_other_bogus_message_id_is_fixed(self):
+        # fix bogus Message-ID with <[]>
+        self._lmtp.sendmail('a...@example.com', ['t...@example.com'], """\
+From: a...@example.com
+To: t...@example.com
+Subject: Bogus <[]> Message-ID
+Message-ID: <[bo...@example.com]>
+
+""")
+        items = get_queue_messages('in', expected_count=1)
+        self.assertEqual('<bo...@example.com>', items[0].msg.get('message-id'))
+
     def test_message_id_hash_is_added(self):
         self._lmtp.sendmail('a...@example.com', ['t...@example.com'], """\
 From: a...@example.com



View it on GitLab: 
https://gitlab.com/mailman/mailman/-/compare/ef7616d17a63fd33f65e9c8cf1991b0a2f92848c...36d75fbbed7c3bac3db8a82242b85954b0c1d814

-- 
View it on GitLab: 
https://gitlab.com/mailman/mailman/-/compare/ef7616d17a63fd33f65e9c8cf1991b0a2f92848c...36d75fbbed7c3bac3db8a82242b85954b0c1d814
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