summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2010-06-04 16:11:08 +0000
committerR. David Murray <rdmurray@bitdance.com>2010-06-04 16:11:08 +0000
commit7da8f06df09aff2f45df9ebcda40e9078a6ab92c (patch)
treebb566ef839c79b074df8381c4351d2b95ff26b9d
parentdeda8cb8352e7d240e51d6f261989b4fda767b60 (diff)
downloadcpython-git-7da8f06df09aff2f45df9ebcda40e9078a6ab92c.tar.gz
#4768: store base64 encoded email body parts as text, not binary.
Patch and tests by Forest Bond.
-rw-r--r--Lib/email/encoders.py2
-rw-r--r--Lib/email/test/test_email.py8
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS3
4 files changed, 10 insertions, 4 deletions
diff --git a/Lib/email/encoders.py b/Lib/email/encoders.py
index 20feb026fd..0ea441d963 100644
--- a/Lib/email/encoders.py
+++ b/Lib/email/encoders.py
@@ -29,7 +29,7 @@ def encode_base64(msg):
Also, add an appropriate Content-Transfer-Encoding header.
"""
orig = msg.get_payload()
- encdata = _bencode(orig)
+ encdata = str(_bencode(orig), 'ascii')
msg.set_payload(encdata)
msg['Content-Transfer-Encoding'] = 'base64'
diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py
index 44a47c54fc..79146a3872 100644
--- a/Lib/email/test/test_email.py
+++ b/Lib/email/test/test_email.py
@@ -970,7 +970,8 @@ class TestMIMEAudio(unittest.TestCase):
def test_encoding(self):
payload = self._au.get_payload()
- self.assertEqual(base64.decodebytes(payload), self._audiodata)
+ self.assertEqual(base64.decodebytes(bytes(payload, 'ascii')),
+ self._audiodata)
def test_checkSetMinor(self):
au = MIMEAudio(self._audiodata, 'fish')
@@ -1010,7 +1011,8 @@ class TestMIMEImage(unittest.TestCase):
def test_encoding(self):
payload = self._im.get_payload()
- self.assertEqual(base64.decodebytes(payload), self._imgdata)
+ self.assertEqual(base64.decodebytes(bytes(payload, 'ascii')),
+ self._imgdata)
def test_checkSetMinor(self):
im = MIMEImage(self._imgdata, 'fish')
@@ -1050,7 +1052,7 @@ class TestMIMEApplication(unittest.TestCase):
eq = self.assertEqual
bytes = b'\xfa\xfb\xfc\xfd\xfe\xff'
msg = MIMEApplication(bytes)
- eq(msg.get_payload(), b'+vv8/f7/')
+ eq(msg.get_payload(), '+vv8/f7/')
eq(msg.get_payload(decode=True), bytes)
diff --git a/Misc/ACKS b/Misc/ACKS
index b75ff6ce36..2fb8b5b1d6 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -83,6 +83,7 @@ Finn Bock
Paul Boddie
Matthew Boedicker
David Bolen
+Forest Bond
Gawain Bolton
Gregory Bond
Jurjen Bos
diff --git a/Misc/NEWS b/Misc/NEWS
index 9195a04152..0dff231331 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -398,6 +398,9 @@ C-API
Library
-------
+- Issue #4768: base64 encoded email body parts were incorrectly stored as
+ binary strings. They are now correctly converted to strings.
+
- Issue #8833: tarfile created hard link entries with a size field != 0 by
mistake.