Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 99147c4

Browse files
committed
Merged revisions 81685 via svnmerge from
svn+ssh://[email protected]/python/branches/py3k ........ r81685 | r.david.murray | 2010-06-04 12:11:08 -0400 (Fri, 04 Jun 2010) | 4 lines #4768: store base64 encoded email body parts as text, not binary. Patch and tests by Forest Bond. ........
1 parent d3f1503 commit 99147c4

4 files changed

Lines changed: 10 additions & 4 deletions

File tree

Lib/email/encoders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def encode_base64(msg):
2929
Also, add an appropriate Content-Transfer-Encoding header.
3030
"""
3131
orig = msg.get_payload()
32-
encdata = _bencode(orig)
32+
encdata = str(_bencode(orig), 'ascii')
3333
msg.set_payload(encdata)
3434
msg['Content-Transfer-Encoding'] = 'base64'
3535

Lib/email/test/test_email.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,8 @@ def test_guess_minor_type(self):
966966

967967
def test_encoding(self):
968968
payload = self._au.get_payload()
969-
self.assertEqual(base64.decodebytes(payload), self._audiodata)
969+
self.assertEqual(base64.decodebytes(bytes(payload, 'ascii')),
970+
self._audiodata)
970971

971972
def test_checkSetMinor(self):
972973
au = MIMEAudio(self._audiodata, 'fish')
@@ -1006,7 +1007,8 @@ def test_guess_minor_type(self):
10061007

10071008
def test_encoding(self):
10081009
payload = self._im.get_payload()
1009-
self.assertEqual(base64.decodebytes(payload), self._imgdata)
1010+
self.assertEqual(base64.decodebytes(bytes(payload, 'ascii')),
1011+
self._imgdata)
10101012

10111013
def test_checkSetMinor(self):
10121014
im = MIMEImage(self._imgdata, 'fish')
@@ -1046,7 +1048,7 @@ def test_body(self):
10461048
eq = self.assertEqual
10471049
bytes = b'\xfa\xfb\xfc\xfd\xfe\xff'
10481050
msg = MIMEApplication(bytes)
1049-
eq(msg.get_payload(), b'+vv8/f7/')
1051+
eq(msg.get_payload(), '+vv8/f7/')
10501052
eq(msg.get_payload(decode=True), bytes)
10511053

10521054

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Finn Bock
8181
Paul Boddie
8282
Matthew Boedicker
8383
David Bolen
84+
Forest Bond
8485
Gregory Bond
8586
Jurjen Bos
8687
Peter Bosch

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ C-API
5454
Library
5555
-------
5656

57+
- Issue #4768: base64 encoded email body parts were incorrectly stored as
58+
binary strings. They are now correctly converted to strings.
59+
5760
- Issue #8833: tarfile created hard link entries with a size field != 0 by
5861
mistake.
5962

0 commit comments

Comments
 (0)