Barry Warsaw pushed to branch release-3.0 at mailman / Mailman
Commits:
12679706 by Aurélien Bompard at 2016-03-10T18:18:45-05:00
Protect the approved rule against unknown charsets
Fixes #203
- - - - -
b5818647 by Aurélien Bompard at 2016-03-10T18:18:45-05:00
Implement review suggestions
- - - - -
019b7328 by Barry Warsaw at 2016-03-10T18:19:36-05:00
Back port the fix for issue 203.
- - - - -
3 changed files:
- src/mailman/docs/NEWS.rst
- src/mailman/rules/approved.py
- src/mailman/rules/tests/test_approved.py
Changes:
=====================================
src/mailman/docs/NEWS.rst
=====================================
--- a/src/mailman/docs/NEWS.rst
+++ b/src/mailman/docs/NEWS.rst
@@ -21,6 +21,8 @@ Bugs
which is already subscribed with that role produces a server error.
Originally given by Anirudh Dahiya. (Closes #198)
* Cross-posting messages held on both lists no longer fails. (Closes #176)
+ * Don't let unknown charsets crash the "approved" rule. Given by Aurélien
+ Bompard. (Closes #203)
3.0.2 -- "Show Don't Tell"
=====================================
src/mailman/rules/approved.py
=====================================
--- a/src/mailman/rules/approved.py
+++ b/src/mailman/rules/approved.py
@@ -75,7 +75,13 @@ class Approved:
break
if payload is not None:
charset = part.get_content_charset('us-ascii')
- payload = payload.decode(charset, 'replace')
+ try:
+ # Do the decoding inside the try/except so that if the
+ # charset is unknown, we'll just drop back to ascii.
+ payload = payload.decode(charset, 'replace')
+ except LookupError:
+ # Unknown or empty charset.
+ payload = payload.decode('us-ascii', 'replace')
line = ''
lines = payload.splitlines(True)
for lineno, line in enumerate(lines):
=====================================
src/mailman/rules/tests/test_approved.py
=====================================
--- a/src/mailman/rules/tests/test_approved.py
+++ b/src/mailman/rules/tests/test_approved.py
@@ -400,8 +400,14 @@ class TestApprovedNonASCII(unittest.TestCase):
def setUp(self):
self._mlist = create_list('[email protected]')
+ self._mlist.moderator_password = config.password_context.encrypt(
+ 'super secret')
self._rule = approved.Approved()
- self._msg = mfs("""\
+
+ def test_nonascii_body_missing_header(self):
+ # When the message body contains non-ascii, the rule should not throw
+ # unicode errors. LP: #949924.
+ msg = mfs("""\
From: [email protected]
To: [email protected]
Subject: A Message with non-ascii body
@@ -412,11 +418,24 @@ Content-Transfer-Encoding: quoted-printable
This is a message body with a non-ascii character =E4
""")
+ result = self._rule.check(self._mlist, msg, {})
+ self.assertFalse(result)
- def test_nonascii_body_missing_header(self):
- # When the message body contains non-ascii, the rule should not throw
- # unicode errors. LP: #949924.
- result = self._rule.check(self._mlist, self._msg, {})
+ def test_unknown_charset(self):
+ # When the charset is unknown, the rule should not crash. GL: #203
+ msg = mfs("""\
+From: [email protected]
+To: [email protected]
+Subject: A Message with non-ascii body
+Message-ID: <ant>
+MIME-Version: 1.0
+Content-Type: text/plain; charset=unknown-8bit
+Content-Disposition: inline
+Content-Transfer-Encoding: quoted-printable
+
+This is a message body with a non-ascii character =E4
+""")
+ result = self._rule.check(self._mlist, msg, {})
self.assertFalse(result)
View it on GitLab:
https://gitlab.com/mailman/mailman/compare/cdc89932bbe4a5b318abfd146a68c1ca9fe3fe72...019b7328e19902d566f0b49c48b6ed2f9f96e495
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe:
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org