Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Lib/email/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,10 @@ def get_payload(self, i=None, decode=False):
payload = bpayload.decode('ascii', 'replace')
elif decode:
try:
bpayload = payload.encode('ascii')
if cte == '8bit':
bpayload = payload.encode('utf-8')
else:
bpayload = payload.encode('ascii')
except UnicodeError:
# This won't happen for RFC compliant messages (messages
# containing only ASCII code points in the unicode input).
Expand Down
11 changes: 10 additions & 1 deletion Lib/test/test_email/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ def test_broken_unicode_payload(self):
x = 'this is a br\xf6ken thing to do'
msg = Message()
msg['content-type'] = 'text/plain'
msg['content-transfer-encoding'] = '8bit'
msg['content-transfer-encoding'] = '7bit'
msg.set_payload(x)
self.assertEqual(msg.get_payload(decode=True),
bytes(x, 'raw-unicode-escape'))
Expand Down Expand Up @@ -733,6 +733,15 @@ def test_binary_base64_payload(self):
b'foo\xe6\x96\x87bar',
'get_payload returns wrong result with charset %s.' % charset)

def test_8bit_utf8_payload(self):
x = 'this is the hötel'
msg = Message()
msg['content-type'] = 'text/plain'
msg['content-transfer-encoding'] = '8bit'
msg.set_payload(x)
self.assertEqual(msg.get_payload(decode=True),
bytes(x, 'utf-8'))

def test_binary_uuencode_payload(self):
for charset in ('latin-1', 'ascii'):
for encoding in ('x-uuencode', 'uuencode', 'uue', 'x-uue'):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Attempt to decode emails with UTF-8 when the CTE is ``8bit``.