gh-80361: Fix TypeError in email.Message.get_payload() (GH-117994)

It was raised when the charset is rfc2231 encoded, e.g.:

   Content-Type: text/plain; charset*=ansi-x3.4-1968''utf-8
This commit is contained in:
Serhiy Storchaka 2024-04-17 19:31:26 +03:00 • committed by GitHub
parent c179c0e6cb
commit deaecb88fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 1 deletions

View file

@ -294,7 +294,7 @@ class Message:
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: