gh-134759: fix `UnboundLocalError` in `email.message.Message.get_payl… · python/cpython@25335d2 · GitHub
Skip to content

Commit 25335d2

Browse files
skv0zsnegpicnixz
andauthored
gh-134759: fix UnboundLocalError in email.message.Message.get_payload (#136071)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
1 parent 5a20e79 commit 25335d2

4 files changed

Lines changed: 14 additions & 0 deletions

File tree

Lib/email/message.py

Lines changed: 2 additions & 0 deletions

Lib/test/test_email/test_message.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,15 @@ def test_get_body_malformed(self):
10551055
# AttributeError: 'str' object has no attribute 'is_attachment'
10561056
m.get_body()
10571057

1058+
def test_get_bytes_payload_with_quoted_printable_encoding(self):
1059+
# We use a memoryview to avoid directly changing the private payload
1060+
# and to prevent using the dedicated paths for string or bytes objects.
1061+
payload = memoryview(b'Some payload')
1062+
m = self._make_message()
1063+
m.add_header('Content-Transfer-Encoding', 'quoted-printable')
1064+
m.set_payload(payload)
1065+
self.assertEqual(m.get_payload(decode=True), payload)
1066+
10581067

10591068
class TestMIMEPart(TestEmailMessageBase, TestEmailBase):
10601069
# Doing the full test run here may seem a bit redundant, since the two

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,7 @@ Alexander Lakeev
10551055
David Lam
10561056
Thomas Lamb
10571057
Valerie Lambert
1058+
Kliment Lamonov
10581059
Peter Lamut
10591060
Jean-Baptiste "Jiba" Lamy
10601061
Ronan Lamy
Lines changed: 2 additions & 0 deletions

0 commit comments

Comments
 (0)