Barry Warsaw pushed to branch master at mailman / Mailman Core

Commits:
057bc070 by Barry Warsaw at 2017-08-29T22:51:58-04:00
Squashed commit of the following:

commit 3c6500c2292869f94667520f16c8d6c6f1d2c530
Author: Barry Warsaw <ba...@python.org>
Date:   Tue Aug 29 22:51:18 2017 -0400

    Close #383

    Messages with badly encoded ``Subject`` headers no longer crash the message
    moderation REST API.

commit f6040ec139bcccd48cfa9acc734cd528a8ede35c
Author: Aurélien Bompard <aurel...@bompard.org>
Date:   Thu Jul 27 00:52:05 2017 +0200

    Fix #383: email encoding errors can crash the REST API

- - - - -


3 changed files:

- src/mailman/docs/NEWS.rst
- src/mailman/rest/post_moderation.py
- src/mailman/rest/tests/test_moderation.py


Changes:

=====================================
src/mailman/docs/NEWS.rst
=====================================
--- a/src/mailman/docs/NEWS.rst
+++ b/src/mailman/docs/NEWS.rst
@@ -24,6 +24,8 @@ Bugs
 * Various message holds and rejects that gave 'N/A' as a reason now give an
   appropriate reason.  (Closes #368)
 * Bounce messages are now composed for proper translations.
+* Messages with badly encoded ``Subject`` headers no longer crash the message
+  moderation REST API.  (Closes #383)
 
 Command line
 ------------


=====================================
src/mailman/rest/post_moderation.py
=====================================
--- a/src/mailman/rest/post_moderation.py
+++ b/src/mailman/rest/post_moderation.py
@@ -95,7 +95,7 @@ class _HeldMessageBase(_ModerationBase):
         # Store the original header and then try decoding it.
         resource['original_subject'] = resource['subject']
         # If we can't decode the header, leave the subject unchanged.
-        with suppress(LookupError, MessageError):
+        with suppress(LookupError, MessageError, UnicodeDecodeError):
             resource['subject'] = str(
                 make_header(decode_header(resource['subject'])))
         # Also, held message resources will always be this type, so ignore


=====================================
src/mailman/rest/tests/test_moderation.py
=====================================
--- a/src/mailman/rest/tests/test_moderation.py
+++ b/src/mailman/rest/tests/test_moderation.py
@@ -144,6 +144,25 @@ Something else.
                      dict(action='discard'))
         self.assertEqual(cm.exception.code, 404)
 
+    def test_subject_encoding_error(self):
+        # GL#383: messages with badly encoded Subject headers crash the REST
+        # server.
+        self._msg = mfs("""\
+From: a...@example.com
+To: a...@example.com
+Subject: =?GB2312?B?saa9o7fmtNPEpbVaQ2h1o6zDt7uoz+PX1L/guq7AtKGj?=
+Message-ID: <alpha>
+
+Something else.
+""")
+        with transaction():
+            held_id = hold_message(self._mlist, self._msg)
+        json, response = call_api(
+            'http://localhost:9001/3.0/lists/a...@example.com/held')
+        self.assertEqual(response.status_code, 200)
+        self.assertEqual(json['total_size'], 1)
+        self.assertEqual(json['entries'][0]['request_id'], held_id)
+
 
 class TestSubscriptionModeration(unittest.TestCase):
     layer = RESTLayer



View it on GitLab: 
https://gitlab.com/mailman/mailman/commit/057bc0704ab6d975e327c11cac204decfb478c4d

---
View it on GitLab: 
https://gitlab.com/mailman/mailman/commit/057bc0704ab6d975e327c11cac204decfb478c4d
You're receiving this email because of your account on gitlab.com.
_______________________________________________
Mailman-checkins mailing list
Mailman-checkins@python.org
Unsubscribe: 
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to