From fda8cd1fd38a12e17b1db1775d54ff0fa4d886b8 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Wed, 17 Apr 2024 18:59:35 +0200 Subject: [PATCH] [3.12] gh-80361: Fix TypeError in email.Message.get_payload() (GH-117994) (GH-117998) It was raised when the charset is rfc2231 encoded, e.g.: Content-Type: text/plain; charset*=ansi-x3.4-1968''utf-8 (cherry picked from commit deaecb88fa5da68cbffca413c63af95fd99578dd) Co-authored-by: Serhiy Storchaka --- Lib/email/message.py | 2 +- Lib/test/test_email/test_email.py | 15 +++++++++++++++ .../2024-04-17-18-00-30.gh-issue-80361.RstWg-.rst | 2 ++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2024-04-17-18-00-30.gh-issue-80361.RstWg-.rst diff --git a/Lib/email/message.py b/Lib/email/message.py index a14cca56b3745a..46bb8c21942af8 100644 --- a/Lib/email/message.py +++ b/Lib/email/message.py @@ -294,7 +294,7 @@ def get_payload(self, i=None, decode=False): try: bpayload = payload.encode('ascii', 'surrogateescape') try: - payload = bpayload.decode(self.get_param('charset', 'ascii'), 'replace') + payload = bpayload.decode(self.get_content_charset('ascii'), 'replace') except LookupError: payload = bpayload.decode('ascii', 'replace') except UnicodeEncodeError: diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py index a373c53c7c798c..fc8d87974e6a4c 100644 --- a/Lib/test/test_email/test_email.py +++ b/Lib/test/test_email/test_email.py @@ -4010,6 +4010,21 @@ def test_8bit_in_uuencode_body(self): self.assertEqual(msg.get_payload(decode=True), '<,.V