| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1026,7 +1026,7 @@ def _find_body(self, part, preferencelist): | |||
| 1026 | 1026 | if subtype in preferencelist: | |
| 1027 | 1027 | yield (preferencelist.index(subtype), part) | |
| 1028 | 1028 | return | |
| 1029 | - if maintype != 'multipart' or not self.is_multipart(): | ||
| 1029 | + if maintype != 'multipart' or not part.is_multipart(): | ||
| 1030 | 1030 | return | |
| 1031 | 1031 | if subtype != 'related': | |
| 1032 | 1032 | for subpart in part.iter_parts(): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1081,6 +1081,25 @@ def test_get_body_malformed(self): | |||
| 1081 | 1081 | # AttributeError: 'str' object has no attribute 'is_attachment' | |
| 1082 | 1082 | m.get_body() | |
| 1083 | 1083 | ||
| 1084 | + def test_get_body_malformed_nested_multipart(self): | ||
| 1085 | + # gh-159304: a nested multipart part without a boundary has a | ||
| 1086 | + # string payload, which get_body() must not iterate over. | ||
| 1087 | + msg = textwrap.dedent("""\ | ||
| 1088 | + From: sender@example.com | ||
| 1089 | + To: receiver@example.com | ||
| 1090 | + Subject: Malformed | ||
| 1091 | + Content-Type: multipart/related; boundary=OUTER | ||
| 1092 | + | ||
| 1093 | + --OUTER | ||
| 1094 | + Content-Type: multipart/related | ||
| 1095 | + | ||
| 1096 | + raw body no boundary | ||
| 1097 | + --OUTER-- | ||
| 1098 | + """) | ||
| 1099 | + m = self._str_msg(msg) | ||
| 1100 | + self.assertIsNone(m.get_body(('plain', 'html'))) | ||
| 1101 | + self.assertIs(m.get_body(('related',)), m) | ||
| 1102 | + | ||
| 1084 | 1103 | def test_get_bytes_payload_with_quoted_printable_encoding(self): | |
| 1085 | 1104 | # We use a memoryview to avoid directly changing the private payload | |
| 1086 | 1105 | # and to prevent using the dedicated paths for string or bytes objects. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Fix :exc:`AttributeError` in :meth:`email.message.EmailMessage.get_body` when a | ||
| 2 | + nested ``multipart`` part is malformed and its payload is a string. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments