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 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
# Work around for and
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: <>
Subject: Defective email
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
text ='ascii', 'replace')
self.assertEqual(msg.as_string(), text)
def test_as_string_python_bug_32330(self):
email_path = resource_filename(
'', 'bad_email_2.eml')
with open(email_path, 'rb') as fp:
msg = message_from_binary_file(fp, Message)
text ='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