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


Commits:
6ac3834d by Mark Sapiro at 2023-06-25T12:09:54-07:00
Content filtering preserves/forwards the original message.

- - - - -
ba44adeb by Mark Sapiro at 2023-06-25T19:31:12+00:00
Merge branch 'filter' into 'master'

Content filtering preserves/forwards the original message.

Closes #1089

See merge request mailman/mailman!1124

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

Reviewed-by: 
- - - - -


3 changed files:

- src/mailman/docs/NEWS.rst
- src/mailman/handlers/mime_delete.py
- src/mailman/handlers/tests/test_mimedel.py


Changes:

=====================================
src/mailman/docs/NEWS.rst
=====================================
@@ -49,6 +49,8 @@ Bugs fixed
 * The default for max_recipients has been reduced to 10 to avoid possible lost
   mail when a large number of invalid recipients causes the MTA to disconnect.
   (Closes #1083)
+* Messages preserved or forwarded by content filtering are now the original
+  message rather than the content filtered one.  (Closes #1089)
 
 Other
 -----


=====================================
src/mailman/handlers/mime_delete.py
=====================================
@@ -132,12 +132,13 @@ following MIME parts from this message.
     if msg.is_multipart():
         # Recursively filter out any subparts that match the filter list
         prelen = len(msg.get_payload())
+        premsg = copy.deepcopy(msg)
         filter_parts(msg, filtertypes, passtypes, filterexts, passexts)
         # If the outer message is now an empty multipart (and it wasn't
         # before!) then, again it gets discarded.
         postlen = len(msg.get_payload())
         if postlen == 0 and prelen > 0:
-            dispose(mlist, msg, msgdata,
+            dispose(mlist, premsg, msgdata,
                     _("After content filtering, the message was empty"))
     # Now replace all multipart/alternatives with just the first non-empty
     # alternative.  BAW: We have to special case when the outer part is a


=====================================
src/mailman/handlers/tests/test_mimedel.py
=====================================
@@ -197,12 +197,52 @@ message.
         with self.assertRaises(DiscardMessage) as cm:
             mime_delete.dispose(self._mlist, self._msg, {}, 'preserved')
         self.assertEqual(cm.exception.message, 'preserved')
-        # There should be no messages in the 'bad' queue.
+        # There should be a message in the 'bad' queue.
         items = get_queue_messages('bad', expected_count=1)
         message = items[0].msg
         self.assertEqual(message['subject'], 'A disposable message')
         self.assertEqual(message['message-id'], '<ant>')
 
+    @configuration('mailman', filtered_messages_are_preservable='yes')
+    def test_preserved_message_has_content(self):
+        msg = mfs("""\
+From: a...@example.com
+To: t...@example.com
+Subject: Testing preserved message has content
+Message-ID: <ant>
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary="AAAA"
+
+--AAAA
+Content-Type: text/bogus; charset="utf-8"
+Content-Transfer-Encoding: quoted-printable
+
+Let=E2=80=99s also consider
+
+--AAAA
+Content-Type: text/other; charset="utf-8"
+Content-Transfer-Encoding: quoted-printable
+
+Let=E2=80=99s also consider
+
+--AAAA--
+""")
+        self._mlist.filter_content = True
+        self._mlist.filter_action = FilterAction.preserve
+        self._mlist.pass_types = ['multipart', 'text/plain']
+        with self.assertRaises(DiscardMessage) as cm:
+            mime_delete.process(self._mlist, msg, {})
+        self.assertEqual(cm.exception.message,
+                         'After content filtering, the message was empty')
+        # There should be a message in the 'bad' queue.
+        items = get_queue_messages('bad', expected_count=1)
+        message = items[0].msg
+        self.assertEqual(message['subject'],
+                         'Testing preserved message has content')
+        self.assertEqual(message['message-id'], '<ant>')
+        # The message should be multipart with two subparts.
+        self.assertEqual(len(message.get_payload()), 2)
+
     def test_bad_action(self):
         # This should never happen, but what if it does?
         # FilterAction.accept, FilterAction.hold, and FilterAction.defer are



View it on GitLab: 
https://gitlab.com/mailman/mailman/-/compare/7feb018fc0bee91872ef207ffcd80f56988d7a19...ba44adebbeb6b754afd838f3504512d6ef4a482c

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