diff options
| author | Mark Sapiro | 2016-10-22 18:18:16 -0700 |
|---|---|---|
| committer | Mark Sapiro | 2016-10-22 18:18:16 -0700 |
| commit | 3a198afcaadab0632aa4762e669438b950218275 (patch) | |
| tree | e97e982d5c2406b0eec412c6675361728379833e /src/mailman | |
| parent | 2e1bc9aa297d108315fe588f2c1831d38a8963e5 (diff) | |
| parent | 4cd3c3f309bb91d46a7ce55a32216db2321804c1 (diff) | |
| download | mailman-3a198afcaadab0632aa4762e669438b950218275.tar.gz mailman-3a198afcaadab0632aa4762e669438b950218275.tar.zst mailman-3a198afcaadab0632aa4762e669438b950218275.zip | |
Diffstat (limited to 'src/mailman')
| -rw-r--r-- | src/mailman/chains/headers.py | 6 | ||||
| -rw-r--r-- | src/mailman/chains/tests/test_headers.py | 40 | ||||
| -rw-r--r-- | src/mailman/docs/NEWS.rst | 1 |
3 files changed, 46 insertions, 1 deletions
diff --git a/src/mailman/chains/headers.py b/src/mailman/chains/headers.py index 70f1da587..5698740d3 100644 --- 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 diff --git a/src/mailman/chains/tests/test_headers.py b/src/mailman/chains/tests/test_headers.py index e21fa452d..7e7219118 100644 --- 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: anne@example.com +To: test@example.com +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') diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst index ea75e0f4d..919a1ef5a 100644 --- 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) * Allow REST API to PATCH some domain attributes. Enables Postorius domain edit to work. (Closes: #290) |
