diff options
| author | Barry Warsaw | 2015-11-06 20:54:31 -0600 |
|---|---|---|
| committer | Barry Warsaw | 2015-11-08 21:00:17 -0500 |
| commit | 879276c5594b002227615b46603d48120043703a (patch) | |
| tree | d76dd421252270c9d15c2b448afe6f97a94e5d5f | |
| parent | bd8b1d5f0e7c9d89ab7e68cd361450dd18a24ae3 (diff) | |
| download | mailman-879276c5594b002227615b46603d48120043703a.tar.gz mailman-879276c5594b002227615b46603d48120043703a.tar.zst mailman-879276c5594b002227615b46603d48120043703a.zip | |
| -rw-r--r-- | src/mailman/chains/hold.py | 7 | ||||
| -rw-r--r-- | src/mailman/chains/tests/issue144.eml | 6 | ||||
| -rw-r--r-- | src/mailman/chains/tests/test_hold.py | 30 | ||||
| -rw-r--r-- | src/mailman/docs/NEWS.rst | 2 |
4 files changed, 44 insertions, 1 deletions
diff --git a/src/mailman/chains/hold.py b/src/mailman/chains/hold.py index 70f6873f6..15219c8ec 100644 --- 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, diff --git a/src/mailman/chains/tests/issue144.eml b/src/mailman/chains/tests/issue144.eml new file mode 100644 index 000000000..888d4a09b --- /dev/null +++ b/src/mailman/chains/tests/issue144.eml @@ -0,0 +1,6 @@ +To: infrastructure@lists.example.org +Subject: =?UTF-8?B?VmnFoWVuYW1qZW5za2kgcGnFoXRvbGogemEgdm9kdSA4LzE=?= +Message-ID: <ant> +From: <anne@example.com> + +Ignore diff --git a/src/mailman/chains/tests/test_hold.py b/src/mailman/chains/tests/test_hold.py index da87c8d15..3e0b4b9fa 100644 --- 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 = 'anne@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-owner@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'], + 'test@example.com post from anne@example.com requires approval') diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst index 0b2ef0d41..dddbfd1e1 100644 --- 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 ------------- |
