diff options
| author | Barry Warsaw | 2014-12-22 13:40:30 -0500 |
|---|---|---|
| committer | Barry Warsaw | 2014-12-22 13:40:30 -0500 |
| commit | 7d996dfa54e35053fb3518f29cd5368f88c085b8 (patch) | |
| tree | b4111954c2cd95578f92240686b8b23cd243a1a7 /src/mailman/rules | |
| parent | 10b4557d9b0de2cb0ce40032e5b633165d6b9139 (diff) | |
| parent | 4173e7219271fa6ffc336c6a6d16b041cc62df12 (diff) | |
| download | mailman-7d996dfa54e35053fb3518f29cd5368f88c085b8.tar.gz mailman-7d996dfa54e35053fb3518f29cd5368f88c085b8.tar.zst mailman-7d996dfa54e35053fb3518f29cd5368f88c085b8.zip | |
Trunk merge.
Diffstat (limited to 'src/mailman/rules')
| -rw-r--r-- | src/mailman/rules/approved.py | 3 | ||||
| -rw-r--r-- | src/mailman/rules/implicit_dest.py | 2 | ||||
| -rw-r--r-- | src/mailman/rules/tests/test_approved.py | 33 |
3 files changed, 37 insertions, 1 deletions
diff --git a/src/mailman/rules/approved.py b/src/mailman/rules/approved.py index c5d099001..054bb1e3d 100644 --- a/src/mailman/rules/approved.py +++ b/src/mailman/rules/approved.py @@ -71,9 +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'): + payload = part.get_payload(decode=True) break - payload = part.get_payload(decode=True) if payload is not None: charset = part.get_content_charset('us-ascii') payload = payload.decode(charset, 'replace') diff --git a/src/mailman/rules/implicit_dest.py b/src/mailman/rules/implicit_dest.py index 8bfb0d2e0..0bc229b15 100644 --- a/src/mailman/rules/implicit_dest.py +++ b/src/mailman/rules/implicit_dest.py @@ -73,6 +73,8 @@ class ImplicitDestination: recipients = set() for header in ('to', 'cc', 'resent-to', 'resent-cc'): for fullname, address in getaddresses(msg.get_all(header, [])): + if isinstance(address, bytes): + address = address.decode('ascii') address = address.lower() if address in aliases: return False diff --git a/src/mailman/rules/tests/test_approved.py b/src/mailman/rules/tests/test_approved.py index ec8e861af..00c556069 100644 --- a/src/mailman/rules/tests/test_approved.py +++ b/src/mailman/rules/tests/test_approved.py @@ -491,3 +491,36 @@ deprecated = roundup_plaintext self.assertFalse(result) self.assertEqual(self._mlist.moderator_password, '{plaintext}super secret') + + + +class TestApprovedNoTextPlainPart(unittest.TestCase): + """Test the approved handler with HTML-only messages.""" + + layer = ConfigLayer + + def setUp(self): + self._mlist = create_list('test@example.com') + self._rule = approved.Approved() + + 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 + msg = mfs("""\ +From: anne@example.com +To: test@example.com +Subject: HTML only email +Message-ID: <ant> +MIME-Version: 1.0 +Content-Type: text/html; charset="Windows-1251" +Content-Transfer-Encoding: 7bit + +<HTML> +<BODY> +<P>This message contains only HTML, no plain/text part</P> +</BODY> +</HTML> +""") + result = self._rule.check(self._mlist, msg, {}) + self.assertFalse(result) |
