mirror of
https://github.com/python/cpython.git
synced 2025-08-12 04:49:01 +00:00
[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 deaecb88fa
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
e95a535ea2
commit
fda8cd1fd3
3 changed files with 18 additions and 1 deletions
|
@ -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:
|
||||
|
|
|
@ -4010,6 +4010,21 @@ class Test8BitBytesHandling(TestEmailBase):
|
|||
self.assertEqual(msg.get_payload(decode=True),
|
||||
'<,.V<W1A; á \n'.encode('utf-8'))
|
||||
|
||||
def test_rfc2231_charset_8bit_CTE(self):
|
||||
m = textwrap.dedent("""\
|
||||
From: foo@bar.com
|
||||
To: baz
|
||||
Mime-Version: 1.0
|
||||
Content-Type: text/plain; charset*=ansi-x3.4-1968''utf-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
pöstal
|
||||
""").encode('utf-8')
|
||||
msg = email.message_from_bytes(m)
|
||||
self.assertEqual(msg.get_payload(), "pöstal\n")
|
||||
self.assertEqual(msg.get_payload(decode=True),
|
||||
"pöstal\n".encode('utf-8'))
|
||||
|
||||
|
||||
headertest_headers = (
|
||||
('From: foo@bar.com', ('From', 'foo@bar.com')),
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Fix TypeError in :func:`email.Message.get_payload` when the charset is :rfc:`2231`
|
||||
encoded.
|
Loading…
Add table
Add a link
Reference in a new issue