Barry Warsaw pushed to branch release-3.0 at mailman / Mailman
Commits: 3727f9da by Barry Warsaw at 2015-11-08T20:57:50Z Closes #144 * Fix ``UnicodeEncodeError`` in the hold chain when sending the authorization email to the mailing list moderators. (Closes: #144) - - - - - 4 changed files: - src/mailman/chains/hold.py - + src/mailman/chains/tests/issue144.eml - src/mailman/chains/tests/test_hold.py - src/mailman/docs/NEWS.rst Changes: ===================================== src/mailman/chains/hold.py ===================================== --- a/src/mailman/chains/hold.py +++ b/src/mailman/chains/hold.py @@ -165,7 +165,12 @@ class HoldChain(TerminalChainBase): if original_subject is None: original_subject = _('(no subject)') else: - original_subject = oneline(original_subject, in_unicode=True) + # This must be encoded to the mailing list's perferred charset, + # ignoring incompatible characters, otherwise when creating the + # notification messages, we could get a Unicode error. + oneline_subject = oneline(original_subject, in_unicode=True) + bytes_subject = oneline_subject.encode(charset, 'replace') + original_subject = bytes_subject.decode(charset) substitutions = dict( listname = mlist.fqdn_listname, subject = original_subject, ===================================== src/mailman/chains/tests/issue144.eml ===================================== --- /dev/null +++ b/src/mailman/chains/tests/issue144.eml @@ -0,0 +1,6 @@ +To: infrastruct...@lists.example.org +Subject: =?UTF-8?B?VmnFoWVuYW1qZW5za2kgcGnFoXRvbGogemEgdm9kdSA4LzE=?= +Message-ID: <ant> +From: <a...@example.com> + +Ignore ===================================== src/mailman/chains/tests/test_hold.py ===================================== --- a/src/mailman/chains/tests/test_hold.py +++ b/src/mailman/chains/tests/test_hold.py @@ -24,6 +24,7 @@ __all__ = [ import unittest +from email import message_from_bytes as mfb from mailman.app.lifecycle import create_list from mailman.chains.hold import autorespond_to_sender from mailman.core.chains import process as process_chain @@ -33,6 +34,7 @@ from mailman.testing.helpers import ( LogFileMark, configuration, get_queue_messages, specialized_message_from_string as mfs) from mailman.testing.layers import ConfigLayer +from pkg_resources import resource_filename from zope.component import getUtility @@ -134,3 +136,31 @@ A message body. logged = logfile.read() self.assertIn('TEST-REASON-1', logged) self.assertIn('TEST-REASON-2', logged) + + def test_hold_chain_charset(self): + # Issue #144 - UnicodeEncodeError in the hold chain. + self._mlist.admin_immed_notify = True + self._mlist.respond_to_post_requests = False + path = resource_filename('mailman.chains.tests', 'issue144.eml') + with open(path, 'rb') as fp: + msg = mfb(fp.read()) + msg.sender = 'a...@example.com' + process_chain(self._mlist, msg, {}, start_chain='hold') + # The postauth.txt message is now in the virgin queue awaiting + # delivery to the moderators. + items = get_queue_messages('virgin') + self.assertEqual(len(items), 1) + msgdata = items[0].msgdata + self.assertTrue(msgdata['tomoderators']) + self.assertEqual(msgdata['recipients'], {'test-ow...@example.com'}) + # Ensure that the subject looks correct in the postauth.txt. + msg = items[0].msg + value = None + for line in msg.get_payload(0).get_payload().splitlines(): + if line.strip().startswith('Subject:'): + header, colon, value = line.partition(':') + break + self.assertEqual(value.lstrip(), 'Vi?enamjenski pi?tolj za vodu 8/1') + self.assertEqual( + msg['Subject'], + 't...@example.com post from a...@example.com requires approval') ===================================== src/mailman/docs/NEWS.rst ===================================== --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -51,7 +51,8 @@ Bugs list is set to confirm-then-moderate. (Closes #114) * Fix pagination values `start` and `total_size` in the REST API. Given by Aurélien Bompard. (Closes: #154) - + * Fix ``UnicodeEncodeError`` in the hold chain when sending the authorization + email to the mailing list moderators. (Closes: #144) 3.0.0 -- "Show Don't Tell" ========================== View it on GitLab: https://gitlab.com/mailman/mailman/commit/3727f9da9da7b857d50b4bac7822077abd651ffd
_______________________________________________ Mailman-checkins mailing list Mailman-checkins@python.org Unsubscribe: https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org