Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7546ea9

Browse filesBrowse files
committed
patch email.message
1 parent 8da6697 commit 7546ea9
Copy full SHA for 7546ea9

File tree

1 file changed

+32
-7
lines changed
Filter options

1 file changed

+32
-7
lines changed

‎Lib/email/message.py

Copy file name to clipboardExpand all lines: Lib/email/message.py
+32-7Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
__all__ = ['Message', 'EmailMessage']
88

99
import re
10-
import uu
1110
import quopri
1211
from io import BytesIO, StringIO
1312

@@ -101,6 +100,35 @@ def _unquotevalue(value):
101100
return utils.unquote(value)
102101

103102

103+
def _decode_uu(encoded):
104+
"""Decode uuencoded data."""
105+
decoded_lines = []
106+
encoded_lines_iter = iter(encoded.splitlines())
107+
for line in encoded_lines_iter:
108+
if line.startswith(b"begin "):
109+
mode, _, path = line.removeprefix(b"begin ").partition(b" ")
110+
try:
111+
int(mode, base=8)
112+
except ValueError:
113+
continue
114+
else:
115+
break
116+
else:
117+
raise ValueError("`begin` line not found")
118+
for line in encoded_lines_iter:
119+
if not line:
120+
raise ValueError("Truncated input")
121+
elif line.strip(b' \t\r\n\f') == b'end':
122+
break
123+
try:
124+
decoded_line = binascii.a2b_uu(line)
125+
except binascii.Error:
126+
# Workaround for broken uuencoders by /Fredrik Lundh
127+
nbytes = (((line[0]-32) & 63) * 4 + 5) // 3
128+
decoded_line = binascii.a2b_uu(line[:nbytes])
129+
decoded_lines.append(decoded_line)
130+
131+
return b''.join(decoded_lines)
104132

105133
class Message:
106134
"""Basic message object.
@@ -288,13 +316,10 @@ def get_payload(self, i=None, decode=False):
288316
self.policy.handle_defect(self, defect)
289317
return value
290318
elif cte in ('x-uuencode', 'uuencode', 'uue', 'x-uue'):
291-
in_file = BytesIO(bpayload)
292-
out_file = BytesIO()
293319
try:
294-
uu.decode(in_file, out_file, quiet=True)
295-
return out_file.getvalue()
296-
except uu.Error:
297-
# Some decoding problem
320+
return _decode_uu(bpayload)
321+
except ValueError:
322+
# Some decoding problem.
298323
return bpayload
299324
if isinstance(payload, str):
300325
return bpayload

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.