Mark Sapiro pushed to branch master at GNU Mailman / Mailman Core
Commits: 7a6e0347 by Mark Sapiro at 2017-12-14T16:52:43-08:00 Defend against https://bugs.python.org/issue32330. - - - - - af91900c by Mark Sapiro at 2017-12-15T21:02:07+00:00 Merge branch 'issue_441' into 'master' Defend against https://bugs.python.org/issue32330. Closes #441 See merge request mailman/mailman!350 - - - - - 4 changed files: - src/mailman/docs/NEWS.rst - src/mailman/email/message.py - + src/mailman/email/tests/data/bad_email_2.eml - src/mailman/email/tests/test_message.py Changes: ===================================== src/mailman/docs/NEWS.rst ===================================== --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -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 ------------ ===================================== src/mailman/email/message.py ===================================== --- a/src/mailman/email/message.py +++ b/src/mailman/email/message.py @@ -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 ===================================== src/mailman/email/tests/data/bad_email_2.eml ===================================== --- /dev/null +++ b/src/mailman/email/tests/data/bad_email_2.eml @@ -0,0 +1,8 @@ +To: <t...@example.com> +Subject: Defective email +From: u...@example.com +Content-Type: text/plain; charset=us-ascii +Content-Transfer-Encoding: 8bit +Message-Id: <20160614102505.9OFQ19L1C> + +This string contains non-ascii � ===================================== src/mailman/email/tests/test_message.py ===================================== --- a/src/mailman/email/tests/test_message.py +++ b/src/mailman/email/tests/test_message.py @@ -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) View it on GitLab: https://gitlab.com/mailman/mailman/compare/066832bb23b744d84710aa35c33908e36021f7ce...af91900c20302dfda9e967d050386264a3cd59ff --- View it on GitLab: https://gitlab.com/mailman/mailman/compare/066832bb23b744d84710aa35c33908e36021f7ce...af91900c20302dfda9e967d050386264a3cd59ff You're receiving this email because of your account on gitlab.com.
_______________________________________________ Mailman-checkins mailing list Mailman-checkins@python.org Unsubscribe: https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org