mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
[3.14] gh-134759: fix UnboundLocalError
in email.message.Message.get_payload
(GH-136071) (#136579)
gh-134759: fix `UnboundLocalError` in `email.message.Message.get_payload` (GH-136071)
(cherry picked from commit 25335d297b
)
Co-authored-by: Kliment Lamonov <klimentlamonov@yandex.ru>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
parent
33f561d7be
commit
c71ecd1418
4 changed files with 14 additions and 0 deletions
|
@ -313,6 +313,8 @@ class Message:
|
|||
# If it does happen, turn the string into bytes in a way
|
||||
# guaranteed not to fail.
|
||||
bpayload = payload.encode('raw-unicode-escape')
|
||||
else:
|
||||
bpayload = payload
|
||||
if cte == 'quoted-printable':
|
||||
return quopri.decodestring(bpayload)
|
||||
elif cte == 'base64':
|
||||
|
|
|
@ -1055,6 +1055,15 @@ class TestEmailMessage(TestEmailMessageBase, TestEmailBase):
|
|||
# AttributeError: 'str' object has no attribute 'is_attachment'
|
||||
m.get_body()
|
||||
|
||||
def test_get_bytes_payload_with_quoted_printable_encoding(self):
|
||||
# We use a memoryview to avoid directly changing the private payload
|
||||
# and to prevent using the dedicated paths for string or bytes objects.
|
||||
payload = memoryview(b'Some payload')
|
||||
m = self._make_message()
|
||||
m.add_header('Content-Transfer-Encoding', 'quoted-printable')
|
||||
m.set_payload(payload)
|
||||
self.assertEqual(m.get_payload(decode=True), payload)
|
||||
|
||||
|
||||
class TestMIMEPart(TestEmailMessageBase, TestEmailBase):
|
||||
# Doing the full test run here may seem a bit redundant, since the two
|
||||
|
|
|
@ -1054,6 +1054,7 @@ Alexander Lakeev
|
|||
David Lam
|
||||
Thomas Lamb
|
||||
Valerie Lambert
|
||||
Kliment Lamonov
|
||||
Peter Lamut
|
||||
Jean-Baptiste "Jiba" Lamy
|
||||
Ronan Lamy
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Fix :exc:`UnboundLocalError` in :func:`email.message.Message.get_payload` when
|
||||
the payload to decode is a :class:`bytes` object. Patch by Kliment Lamonov.
|
Loading…
Add table
Add a link
Reference in a new issue