diff options
| -rw-r--r-- | src/mailman/docs/NEWS.rst | 4 | ||||
| -rw-r--r-- | src/mailman/rules/approved.py | 6 | ||||
| -rw-r--r-- | src/mailman/rules/tests/test_approved.py | 7 |
3 files changed, 9 insertions, 8 deletions
diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst index ac81cd386..0a4b2fb51 100644 --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -16,9 +16,11 @@ Bugs ---- * Fixed Unicode errors in the digest runner and when sending messages to the site owner as a fallback. Given by Aurélien Bompard. (LP: #1130957). - * Fix Unicode errors when a message being added to the digest has non-ascii + * Fixed Unicode errors when a message being added to the digest has non-ascii characters in its payload, but no Content-Type header defining a charset. Given by Aurélien Bompard. (LP: #1170347) + * Fixed messages without a `text/plain` part crashing the `Approved` rule. + Given by Aurélien Bompard. (LP: #1158721) Commands -------- diff --git a/src/mailman/rules/approved.py b/src/mailman/rules/approved.py index 73995c7ee..3b40d5dc9 100644 --- a/src/mailman/rules/approved.py +++ b/src/mailman/rules/approved.py @@ -71,12 +71,10 @@ class Approved: # Find the first text/plain part in the message part = None stripped = False + payload = None for part in typed_subpart_iterator(msg, 'text', 'plain'): - break - if part is None: - payload = None - else: payload = part.get_payload(decode=True) + break if payload is not None: charset = part.get_content_charset('us-ascii') payload = payload.decode(charset, 'replace') diff --git a/src/mailman/rules/tests/test_approved.py b/src/mailman/rules/tests/test_approved.py index e0927bfc9..9976d4eff 100644 --- a/src/mailman/rules/tests/test_approved.py +++ b/src/mailman/rules/tests/test_approved.py @@ -493,7 +493,7 @@ deprecated = roundup_plaintext b'{plaintext}super secret') -class TestApprovedNoPlainText(unittest.TestCase): +class TestApprovedNoTextPlainPart(unittest.TestCase): """Test the approved handler with HTML-only messages.""" layer = ConfigLayer @@ -502,7 +502,7 @@ class TestApprovedNoPlainText(unittest.TestCase): self._mlist = create_list('test@example.com') self._rule = approved.Approved() - def test_noplaintext(self): + def test_no_text_plain_part(self): # When the message body only contains HTML, the rule should not throw # AttributeError: 'NoneType' object has no attribute 'get_payload' # LP: #1158721 @@ -518,7 +518,8 @@ Content-Transfer-Encoding: 7bit <HTML> <BODY> <P>This message contains only HTML, no plain/text part</P> -</BODY></HTML> +</BODY> +</HTML> """) result = self._rule.check(self._mlist, msg, {}) self.assertFalse(result) |
