Kaydet (Commit) 6d94bd47 authored tarafından R David Murray's avatar R David Murray

#9298: restore proper folding of base64 encoded bodies.

Patch by Yves Dorfsman.
üst d3b7a55f
...@@ -12,7 +12,7 @@ __all__ = [ ...@@ -12,7 +12,7 @@ __all__ = [
] ]
from base64 import b64encode as _bencode from base64 import encodebytes as _bencode
from quopri import encodestring as _encodestring from quopri import encodestring as _encodestring
......
...@@ -553,9 +553,18 @@ class TestMessageAPI(TestEmailBase): ...@@ -553,9 +553,18 @@ class TestMessageAPI(TestEmailBase):
msg['Dummy'] = 'dummy\nX-Injected-Header: test' msg['Dummy'] = 'dummy\nX-Injected-Header: test'
self.assertRaises(errors.HeaderParseError, msg.as_string) self.assertRaises(errors.HeaderParseError, msg.as_string)
# Test the email.encoders module # Test the email.encoders module
class TestEncoders(unittest.TestCase): 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): def test_encode_empty_payload(self):
eq = self.assertEqual eq = self.assertEqual
msg = Message() msg = Message()
...@@ -1107,10 +1116,11 @@ class TestMIMEApplication(unittest.TestCase): ...@@ -1107,10 +1116,11 @@ class TestMIMEApplication(unittest.TestCase):
def test_body(self): def test_body(self):
eq = self.assertEqual eq = self.assertEqual
bytes = b'\xfa\xfb\xfc\xfd\xfe\xff' bytesdata = b'\xfa\xfb\xfc\xfd\xfe\xff'
msg = MIMEApplication(bytes) msg = MIMEApplication(bytesdata)
eq(msg.get_payload(), '+vv8/f7/') # whitespace in the cte encoded block is RFC-irrelevant.
eq(msg.get_payload(decode=True), bytes) eq(msg.get_payload().strip(), '+vv8/f7/')
eq(msg.get_payload(decode=True), bytesdata)
......
...@@ -202,6 +202,7 @@ Daniel Dittmar ...@@ -202,6 +202,7 @@ Daniel Dittmar
Jaromir Dolecek Jaromir Dolecek
Ismail Donmez Ismail Donmez
Dima Dorfman Dima Dorfman
Yves Dorfsman
Cesar Douady Cesar Douady
Dean Draayer Dean Draayer
Fred L. Drake, Jr. Fred L. Drake, Jr.
......
...@@ -40,6 +40,10 @@ Core and Builtins ...@@ -40,6 +40,10 @@ Core and Builtins
Library Library
------- -------
- Issue #9298: base64 bodies weren't being folded to line lengths less than 78,
which was a regression relative to Python2. Unlike Python2, the last line
of the folded body now ends with a carriage return.
- Issue #11569: use absolute path to the sysctl command in multiprocessing to - Issue #11569: use absolute path to the sysctl command in multiprocessing to
ensure that it will be found regardless of the shell PATH. This ensures ensure that it will be found regardless of the shell PATH. This ensures
that multiprocessing.cpu_count works on default installs of MacOSX. that multiprocessing.cpu_count works on default installs of MacOSX.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment