Barry Warsaw pushed to branch master at mailman / Mailman
Commits:
b4e20758 by Mark Sapiro at 2016-10-22T18:22:15-04:00
Fixes for #280.
- - - - -
4cd3c3f3 by Barry Warsaw at 2016-10-22T18:24:39-04:00
Tweaks.
- - - - -
3 changed files:
- src/mailman/chains/headers.py
- src/mailman/chains/tests/test_headers.py
- src/mailman/docs/NEWS.rst
Changes:
=====================================
src/mailman/chains/headers.py
=====================================
--- a/src/mailman/chains/headers.py
+++ b/src/mailman/chains/headers.py
@@ -96,7 +96,11 @@ class HeaderMatchRule:
def check(self, mlist, msg, msgdata):
"""See `IRule`."""
- for value in msg.get_all(self.header, []):
+ # Collect all the headers in all subparts.
+ headers = []
+ for p in msg.walk():
+ headers.extend(p.get_all(self.header, []))
+ for value in headers:
if re.search(self.pattern, value, re.IGNORECASE):
return True
return False
=====================================
src/mailman/chains/tests/test_headers.py
=====================================
--- a/src/mailman/chains/tests/test_headers.py
+++ b/src/mailman/chains/tests/test_headers.py
@@ -169,6 +169,46 @@ class TestHeaderChain(unittest.TestCase):
('baz', 'z+', LinkAction.jump, 'accept'),
]) # noqa: E124
+ def test_header_in_subpart(self):
+ # Test that headers in sub-parts are also matched.
+ msg = mfs("""\
+From: [email protected]
+To: [email protected]
+Subject: A message
+Message-ID: <ant>
+Foo: foo
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary="================12345=="
+
+--================12345==
+Content-Type: text/plain; charset="us-ascii"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+
+A message body.
+
+--================12345==
+Content-Type: application/junk
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+
+This is junk
+
+--================12345==--
+""")
+ msgdata = {}
+ header_matches = IHeaderMatchList(self._mlist)
+ header_matches.append('Content-Type', 'application/junk', 'hold')
+ # This event subscriber records the event that occurs when the message
+ # is processed by the owner chain.
+ events = []
+ with event_subscribers(events.append):
+ process(self._mlist, msg, msgdata, start_chain='header-match')
+ self.assertEqual(len(events), 1)
+ event = events[0]
+ self.assertIsInstance(event, HoldEvent)
+ self.assertEqual(event.chain, config.chains['hold'])
+
@configuration('antispam', header_checks="""
Foo: foo
""", jump_chain='hold')
=====================================
src/mailman/docs/NEWS.rst
=====================================
--- a/src/mailman/docs/NEWS.rst
+++ b/src/mailman/docs/NEWS.rst
@@ -90,6 +90,7 @@ Bugs
Aurélien Bompard. (Closes: #273)
* Allow MailingList.info to be set using the REST API. Given by Aurélien
Bompard.
+ * Extend header filters to also check sub-part headers. (Closes #280)
Configuration
-------------
View it on GitLab:
https://gitlab.com/mailman/mailman/compare/3cf613f56e44bed4bc45f533e6f6263288e66460...4cd3c3f309bb91d46a7ce55a32216db2321804c1
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe:
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org