Index: Lib/email/test/test_email.py =================================================================== --- Lib/email/test/test_email.py (revision 88415) +++ Lib/email/test/test_email.py (working copy) @@ -576,6 +576,20 @@ # Test the email.encoders module class TestEncoders(unittest.TestCase): + def setUp(self): + with openfile('PyBanner048.gif', 'rb') as fp: + self.bindata = fp.read() + + def test_EncodersEncode_base64(self): + mimed = email.mime.image.MIMEImage(self.bindata) + base64ed = mimed.get_payload() + # uncoment the print for a visual clarification of the problem. + #print (base64ed) + + # work out if any line within the string is > 76 chars + 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() @@ -1127,10 +1141,11 @@ 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) + # A strip'ed base64 string is still valid and won't change its value. + eq(msg.get_payload().strip(), '+vv8/f7/') + eq(msg.get_payload(decode=True), bytesdata) Index: Lib/email/encoders.py =================================================================== --- Lib/email/encoders.py (revision 88415) +++ Lib/email/encoders.py (working copy) @@ -12,7 +12,7 @@ ] -from base64 import b64encode as _bencode +from base64 import encodebytes as _bencode from quopri import encodestring as _encodestring