Barry Warsaw pushed to branch master at mailman / Mailman
Commits: 879276c5 by Barry Warsaw at 2015-11-08T21:00:17Z 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 @@ -164,7 +164,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 @@ -25,6 +25,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 @@ -34,6 +35,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 @@ -135,3 +137,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 @@ -42,6 +42,8 @@ Bugs * Added Trove classifiers to setup.py. (Closes: #152) * Fix the processing of subscription confirmation messages when the mailing list is set to confirm-then-moderate. (Closes #114) + * Fix ``UnicodeEncodeError`` in the hold chain when sending the authorization + email to the mailing list moderators. (Closes: #144) Configuration ------------- View it on GitLab: https://gitlab.com/mailman/mailman/commit/879276c5594b002227615b46603d48120043703a
_______________________________________________ Mailman-checkins mailing list Mailman-checkins@python.org Unsubscribe: https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org