FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.15] gh-159304: Fix AttributeError in email get_body() for nested malformed multipart (GH-159306) by miss-islington · Pull Request #159492 · python/cpython · GitHub

Repository navigation

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion Lib/email/message.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ def _find_body(self, part, preferencelist):
if subtype in preferencelist:
yield (preferencelist.index(subtype), part)
return
if maintype != 'multipart' or not self.is_multipart():
if maintype != 'multipart' or not part.is_multipart():
return
if subtype != 'related':
for subpart in part.iter_parts():
Expand Down
19 changes: 19 additions & 0 deletions Lib/test/test_email/test_message.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,25 @@ def test_get_body_malformed(self):
# AttributeError: 'str' object has no attribute 'is_attachment'
m.get_body()

def test_get_body_malformed_nested_multipart(self):
# gh-159304: a nested multipart part without a boundary has a
# string payload, which get_body() must not iterate over.
msg = textwrap.dedent("""\
From: sender@example.com
To: receiver@example.com
Subject: Malformed
Content-Type: multipart/related; boundary=OUTER

--OUTER
Content-Type: multipart/related

raw body no boundary
--OUTER--
""")
m = self._str_msg(msg)
self.assertIsNone(m.get_body(('plain', 'html')))
self.assertIs(m.get_body(('related',)), m)

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.
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :exc:`AttributeError` in :meth:`email.message.EmailMessage.get_body` when a
nested ``multipart`` part is malformed and its payload is a string.
Loading

Back | FazBrowse Home | New Git URL