Commit 879276c5 authored by Barry Warsaw's avatar Barry Warsaw

Closes #144

 * Fix ``UnicodeEncodeError`` in the hold chain when sending the authorization
   email to the mailing list moderators.  (Closes: #144)
parent bd8b1d5f
Pipeline #230999 passed with stage
......@@ -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,
......
To: [email protected]
Subject: =?UTF-8?B?VmnFoWVuYW1qZW5za2kgcGnFoXRvbGogemEgdm9kdSA4LzE=?=
Message-ID: <ant>
From: <[email protected]>
Ignore
......@@ -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 = '[email protected]'
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'], {'[email protected]'})
# 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'],
'[email protected] post from [email protected] requires approval')
......@@ -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
-------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment