Commit 7a6e0347 authored by Mark Sapiro's avatar Mark Sapiro
parent 066832bb
......@@ -44,6 +44,8 @@ Bugs
* Raw Message text is now coerced to pure ascii before sending, and
https://bugs.python.org/issue27321 is now defended against by overriding
Message.as_string() to cover more cases than before. (Closes #406)
* The override of Message.as_string() has been extended to catch another
observed exception. (Closes #441)
Command line
------------
......
......@@ -48,10 +48,11 @@ class Message(email.message.Message):
self.__dict__ = values
def as_string(self):
# Work around for https://bugs.python.org/issue27321.
# Work around for https://bugs.python.org/issue27321 and
# https://bugs.python.org/issue32330.
try:
value = email.message.Message.as_string(self)
except KeyError:
except (KeyError, UnicodeEncodeError):
value = email.message.Message.as_bytes(self).decode(
'ascii', 'replace')
return value
......
To: <test@example.com>
Subject: Defective email
From: user@example.com
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 8bit
Message-Id: <20160614102505.9OFQ19L1C>
This string contains non-ascii �
......@@ -99,3 +99,12 @@ Test content
fp.seek(0)
text = fp.read().decode('ascii', 'replace')
self.assertEqual(msg.as_string(), text)
def test_as_string_python_bug_32330(self):
email_path = resource_filename(
'mailman.email.tests.data', 'bad_email_2.eml')
with open(email_path, 'rb') as fp:
msg = message_from_binary_file(fp, Message)
fp.seek(0)
text = fp.read().decode('ascii', 'replace')
self.assertEqual(msg.as_string(), text)
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