summaryrefslogtreecommitdiffstats
path: root/Lib/email
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2011-03-16 19:52:22 (GMT)
committerR David Murray <rdmurray@bitdance.com>2011-03-16 19:52:22 (GMT)
commit6d94bd470e3f4aa1dc7295b034553509ace2c654 (patch)
tree48b4d853d3e0755d0f6e3013a2b50603956807da /Lib/email
parentd3b7a55f543bf1c3ea6bcf10dd03b0919822f993 (diff)
downloadcpython-6d94bd470e3f4aa1dc7295b034553509ace2c654.zip
cpython-6d94bd470e3f4aa1dc7295b034553509ace2c654.tar.gz
cpython-6d94bd470e3f4aa1dc7295b034553509ace2c654.tar.bz2
#9298: restore proper folding of base64 encoded bodies.
Patch by Yves Dorfsman.
Diffstat (limited to 'Lib/email')
-rw-r--r--Lib/email/encoders.py2
-rw-r--r--Lib/email/test/test_email.py20
2 files changed, 16 insertions, 6 deletions
diff --git a/Lib/email/encoders.py b/Lib/email/encoders.py
index 0ea441d..dfaac58 100644
--- a/Lib/email/encoders.py
+++ b/Lib/email/encoders.py
@@ -12,7 +12,7 @@ __all__ = [
]
-from base64 import b64encode as _bencode
+from base64 import encodebytes as _bencode
from quopri import encodestring as _encodestring
diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py
index 0f28a9c..6a88b16 100644
--- a/Lib/email/test/test_email.py
+++ b/Lib/email/test/test_email.py
@@ -553,9 +553,18 @@ class TestMessageAPI(TestEmailBase):
msg['Dummy'] = 'dummy\nX-Injected-Header: test'
self.assertRaises(errors.HeaderParseError, msg.as_string)
-
# Test the email.encoders module
class TestEncoders(unittest.TestCase):
+
+ def test_EncodersEncode_base64(self):
+ with openfile('PyBanner048.gif', 'rb') as fp:
+ bindata = fp.read()
+ mimed = email.mime.image.MIMEImage(bindata)
+ base64ed = mimed.get_payload()
+ # the transfer-encoded body lines should all be <=76 characters
+ lines = base64ed.split('\n')
+ self.assertLessEqual(max([ len(x) for x in lines ]), 76)
+
def test_encode_empty_payload(self):
eq = self.assertEqual
msg = Message()
@@ -1107,10 +1116,11 @@ class TestMIMEApplication(unittest.TestCase):
def test_body(self):
eq = self.assertEqual
- bytes = b'\xfa\xfb\xfc\xfd\xfe\xff'
- msg = MIMEApplication(bytes)
- eq(msg.get_payload(), '+vv8/f7/')
- eq(msg.get_payload(decode=True), bytes)
+ bytesdata = b'\xfa\xfb\xfc\xfd\xfe\xff'
+ msg = MIMEApplication(bytesdata)
+ # whitespace in the cte encoded block is RFC-irrelevant.
+ eq(msg.get_payload().strip(), '+vv8/f7/')
+ eq(msg.get_payload(decode=True), bytesdata)