Mark Sapiro pushed to branch master at GNU Mailman / Mailman Core
Commits: fff04761 by Mark Sapiro at 2022-02-18T21:12:32-08:00 Override Message.as_bytes() to workaround https://bugs.python.org/issue41307. - - - - - 5837c620 by Mark Sapiro at 2022-02-19T05:44:12+00:00 Merge branch 'bytes' into 'master' Override Message.as_bytes() to workaround https://bugs.python.org/issue41307. Closes #980 and #979 See merge request mailman/mailman!964 - - - - - 3 changed files: - src/mailman/docs/NEWS.rst - src/mailman/email/message.py - src/mailman/email/tests/test_message.py Changes: ===================================== src/mailman/docs/NEWS.rst ===================================== @@ -41,6 +41,8 @@ Bugs fixed testing the legacy ``*_these_nonmembers`` settings. (Closes #978) * Invalid regexps in ``*_these_nonmembers`` are properly logged and can't be set via REST. (Closes #974) +* Override the as_bytes() method in the mailman.email.message.Message class to + workaround https://bugs.python.org/issue41307. (Closes #979 and #980) REST ==== ===================================== src/mailman/email/message.py ===================================== @@ -59,6 +59,14 @@ class Message(email.message.Message): # Also ensure no unicode surrogates in the returned string. return email.utils._sanitize(value) + def as_bytes(self): + # Workaround for https://bugs.python.org/issue41307. + try: + value = email.message.Message.as_bytes(self) + except UnicodeEncodeError: + value = email.message.Message.as_string(self).encode('utf-8') + return value + @property def sender(self): """The address considered to be the author of the email. ===================================== src/mailman/email/tests/test_message.py ===================================== @@ -27,7 +27,8 @@ from email.utils import _has_surrogates from importlib_resources import path from mailman.app.lifecycle import create_list from mailman.email.message import Message, UserNotification -from mailman.testing.helpers import get_queue_messages +from mailman.testing.helpers import ( + get_queue_messages, specialized_message_from_string as mfs) from mailman.testing.layers import ConfigLayer @@ -161,6 +162,19 @@ IM3F1M/EwSDQz8nTy8Egy8zJxc7Uz9c/Cg== msg = message_from_binary_file(fp, Message) self.assertFalse(_has_surrogates(msg.as_string())) + def test_as_bytes_python_bug_41307(self): + msgstr = """\ +To: l...@example.com +From: u...@example.com +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 8bit + +Message with \u201cNon-ascii\u201d. +""" + msg = mfs(msgstr) + self.assertEqual(msg.as_bytes(), msgstr.encode('utf-8')) + def test_bogus_content_charset(self): with path('mailman.email.tests.data', 'bad_email_3.eml') as email_path: with open(str(email_path), 'rb') as fp: View it on GitLab: https://gitlab.com/mailman/mailman/-/compare/69785aaaf127a60415707aa7552d3e1c433034f9...5837c620c376c0158e5d0679abd53e3d0a77acf9 -- View it on GitLab: https://gitlab.com/mailman/mailman/-/compare/69785aaaf127a60415707aa7552d3e1c433034f9...5837c620c376c0158e5d0679abd53e3d0a77acf9 You're receiving this email because of your account on gitlab.com.
_______________________________________________ Mailman-checkins mailing list -- mailman-checkins@python.org To unsubscribe send an email to mailman-checkins-le...@python.org https://mail.python.org/mailman3/lists/mailman-checkins.python.org/ Member address: arch...@jab.org