Aurélien Bompard has proposed merging lp:~abompard/mailman/bug-1158721 into 
lp:mailman.

Requested reviews:
  Mailman Coders (mailman-coders)
Related bugs:
  Bug #1158721 in GNU Mailman: "Emails without a text/plain part crash the 
Approved rule"
  https://bugs.launchpad.net/mailman/+bug/1158721

For more details, see:
https://code.launchpad.net/~abompard/mailman/bug-1158721/+merge/243229

Emails without a text/plain part crash the Approved rule, this branch contains 
the fix for bug #1158721.
-- 
Your team Mailman Coders is requested to review the proposed merge of 
lp:~abompard/mailman/bug-1158721 into lp:mailman.
=== modified file 'src/mailman/rules/approved.py'
--- src/mailman/rules/approved.py	2014-01-01 14:59:42 +0000
+++ src/mailman/rules/approved.py	2014-11-30 10:25:19 +0000
@@ -73,7 +73,10 @@
             stripped = False
             for part in typed_subpart_iterator(msg, 'text', 'plain'):
                 break
-            payload = part.get_payload(decode=True)
+            if part is None:
+                payload = None
+            else:
+                payload = part.get_payload(decode=True)
             if payload is not None:
                 charset = part.get_content_charset('us-ascii')
                 payload = payload.decode(charset, 'replace')

=== modified file 'src/mailman/rules/tests/test_approved.py'
--- src/mailman/rules/tests/test_approved.py	2014-01-01 14:59:42 +0000
+++ src/mailman/rules/tests/test_approved.py	2014-11-30 10:25:19 +0000
@@ -491,3 +491,34 @@
             self.assertFalse(result)
         self.assertEqual(self._mlist.moderator_password,
                          b'{plaintext}super secret')
+
+
+class TestApprovedNoPlainText(unittest.TestCase):
+    """Test the approved handler with HTML-only messages."""
+
+    layer = ConfigLayer
+
+    def setUp(self):
+        self._mlist = create_list('t...@example.com')
+        self._rule = approved.Approved()
+
+    def test_noplaintext(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: a...@example.com
+To: t...@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)

_______________________________________________
Mailman-coders mailing list
Mailman-coders@python.org
https://mail.python.org/mailman/listinfo/mailman-coders

Reply via email to