Kaydet (Commit) 4617e508 authored tarafından R. David Murray's avatar R. David Murray

Issue #7143: get_payload used to strip any trailing newline from a

base64 transfer-encoded payload *after* decoding it; it no longer does.
email had a special method in utils, _bdecode, specifically to do this,
so it must have served a purpose at some point, yet it is clearly wrong
per RFC.  Fixed with Barry's approval, but no backport.  Email package
minor version number is bumped, now version 4.0.1.

Patch by Joaquin Cuenca Abela.
üst 16cd888d
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"""A package for parsing, handling, and generating email messages.""" """A package for parsing, handling, and generating email messages."""
__version__ = '4.0.1' __version__ = '4.0.2'
__all__ = [ __all__ = [
# Old names # Old names
......
...@@ -24,6 +24,13 @@ Content-Transfer-Encoding: Base64 ...@@ -24,6 +24,13 @@ Content-Transfer-Encoding: Base64
VGhpcyBpcyBhIEJhc2U2NCBlbmNvZGVkIG1lc3NhZ2Uu VGhpcyBpcyBhIEJhc2U2NCBlbmNvZGVkIG1lc3NhZ2Uu
--BOUNDARY
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: Base64
VGhpcyBpcyBhIEJhc2U2NCBlbmNvZGVkIG1lc3NhZ2UuCg==
--BOUNDARY --BOUNDARY
Content-Type: text/plain; charset="iso-8859-1" Content-Type: text/plain; charset="iso-8859-1"
......
...@@ -205,8 +205,12 @@ class TestMessageAPI(TestEmailBase): ...@@ -205,8 +205,12 @@ class TestMessageAPI(TestEmailBase):
# Subpart 3 is base64 # Subpart 3 is base64
eq(msg.get_payload(2).get_payload(decode=True), eq(msg.get_payload(2).get_payload(decode=True),
'This is a Base64 encoded message.') 'This is a Base64 encoded message.')
# Subpart 4 has no Content-Transfer-Encoding: header. # Subpart 4 is base64 with a trailing newline, which
# used to be stripped (issue 7143).
eq(msg.get_payload(3).get_payload(decode=True), eq(msg.get_payload(3).get_payload(decode=True),
'This is a Base64 encoded message.\n')
# Subpart 5 has no Content-Transfer-Encoding: header.
eq(msg.get_payload(4).get_payload(decode=True),
'This has no Content-Transfer-Encoding: header.\n') 'This has no Content-Transfer-Encoding: header.\n')
def test_get_decoded_uu_payload(self): def test_get_decoded_uu_payload(self):
......
...@@ -194,8 +194,12 @@ class TestMessageAPI(TestEmailBase): ...@@ -194,8 +194,12 @@ class TestMessageAPI(TestEmailBase):
# Subpart 3 is base64 # Subpart 3 is base64
eq(msg.get_payload(2).get_payload(decode=True), eq(msg.get_payload(2).get_payload(decode=True),
'This is a Base64 encoded message.') 'This is a Base64 encoded message.')
# Subpart 4 has no Content-Transfer-Encoding: header. # Subpart 4 is base64 with a trailing newline, which
# used to be stripped (issue 7143).
eq(msg.get_payload(3).get_payload(decode=True), eq(msg.get_payload(3).get_payload(decode=True),
'This is a Base64 encoded message.\n')
# Subpart 5 has no Content-Transfer-Encoding: header.
eq(msg.get_payload(4).get_payload(decode=True),
'This has no Content-Transfer-Encoding: header.\n') 'This has no Content-Transfer-Encoding: header.\n')
def test_get_decoded_uu_payload(self): def test_get_decoded_uu_payload(self):
......
...@@ -60,14 +60,15 @@ def _identity(s): ...@@ -60,14 +60,15 @@ def _identity(s):
def _bdecode(s): def _bdecode(s):
# We can't quite use base64.encodestring() since it tacks on a "courtesy """Decodes a base64 string.
# newline". Blech!
This function is equivalent to base64.decodestring and it's retained only
for backward compatibility. It used to remove the last \n of the decoded
string, if it had any (see issue 7143).
"""
if not s: if not s:
return s return s
value = base64.decodestring(s) return base64.decodestring(s)
if not s.endswith('\n') and value.endswith('\n'):
return value[:-1]
return value
......
...@@ -10,6 +10,7 @@ Without you, I would've stopped working on Python long ago! ...@@ -10,6 +10,7 @@ Without you, I would've stopped working on Python long ago!
PS: In the standard Python distribution, this file is encoded in UTF-8. PS: In the standard Python distribution, this file is encoded in UTF-8.
Joaquin Cuenca Abela
David Abrahams David Abrahams
Jim Ahlstrom Jim Ahlstrom
Farhan Ahmad Farhan Ahmad
......
...@@ -15,6 +15,11 @@ Core and Builtins ...@@ -15,6 +15,11 @@ Core and Builtins
Library Library
------- -------
- Issue #7143: get_payload used to strip any trailing newline from a
base64 transfer-encoded payload *after* decoding it; it no longer does.
This is a behavior change, so email's minor version number is now
bumped, to version 4.0.2, for the 2.7 release.
Extension Modules Extension Modules
----------------- -----------------
...@@ -28,6 +33,7 @@ Extension Modules ...@@ -28,6 +33,7 @@ Extension Modules
and standard packing.) and standard packing.)
What's New in Python 2.7 alpha 4? What's New in Python 2.7 alpha 4?
================================= =================================
......
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