From 4617e5085a89952a0bc99c086e5de8dc9f0a5676 Mon Sep 17 00:00:00 2001 From: "R. David Murray" Date: Mon, 8 Mar 2010 02:04:06 +0000 Subject: 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. --- Lib/email/__init__.py | 2 +- Lib/email/test/data/msg_10.txt | 7 +++++++ Lib/email/test/test_email.py | 6 +++++- Lib/email/test/test_email_renamed.py | 6 +++++- Lib/email/utils.py | 13 +++++++------ Misc/ACKS | 1 + Misc/NEWS | 6 ++++++ 7 files changed, 32 insertions(+), 9 deletions(-) diff --git a/Lib/email/__init__.py b/Lib/email/__init__.py index 8d230fd..a793436 100644 --- a/Lib/email/__init__.py +++ b/Lib/email/__init__.py @@ -4,7 +4,7 @@ """A package for parsing, handling, and generating email messages.""" -__version__ = '4.0.1' +__version__ = '4.0.2' __all__ = [ # Old names diff --git a/Lib/email/test/data/msg_10.txt b/Lib/email/test/data/msg_10.txt index bd30d13..0790396 100644 --- a/Lib/email/test/data/msg_10.txt +++ b/Lib/email/test/data/msg_10.txt @@ -26,6 +26,13 @@ VGhpcyBpcyBhIEJhc2U2NCBlbmNvZGVkIG1lc3NhZ2Uu --BOUNDARY Content-Type: text/plain; charset="iso-8859-1" +Content-Transfer-Encoding: Base64 + +VGhpcyBpcyBhIEJhc2U2NCBlbmNvZGVkIG1lc3NhZ2UuCg== + + +--BOUNDARY +Content-Type: text/plain; charset="iso-8859-1" This has no Content-Transfer-Encoding: header. diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py index aa16ce2..36b308f 100644 --- a/Lib/email/test/test_email.py +++ b/Lib/email/test/test_email.py @@ -205,8 +205,12 @@ class TestMessageAPI(TestEmailBase): # Subpart 3 is base64 eq(msg.get_payload(2).get_payload(decode=True), '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), + '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') def test_get_decoded_uu_payload(self): diff --git a/Lib/email/test/test_email_renamed.py b/Lib/email/test/test_email_renamed.py index fc8f30a..976d892 100644 --- a/Lib/email/test/test_email_renamed.py +++ b/Lib/email/test/test_email_renamed.py @@ -194,8 +194,12 @@ class TestMessageAPI(TestEmailBase): # Subpart 3 is base64 eq(msg.get_payload(2).get_payload(decode=True), '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), + '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') def test_get_decoded_uu_payload(self): diff --git a/Lib/email/utils.py b/Lib/email/utils.py index b9a7642..6d22ca7 100644 --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -60,14 +60,15 @@ def _identity(s): def _bdecode(s): - # We can't quite use base64.encodestring() since it tacks on a "courtesy - # newline". Blech! + """Decodes a base64 string. + + 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: return s - value = base64.decodestring(s) - if not s.endswith('\n') and value.endswith('\n'): - return value[:-1] - return value + return base64.decodestring(s) diff --git a/Misc/ACKS b/Misc/ACKS index 426d0dd..09f4782 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -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. +Joaquin Cuenca Abela David Abrahams Jim Ahlstrom Farhan Ahmad diff --git a/Misc/NEWS b/Misc/NEWS index b1431a3..1f16de8 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -15,6 +15,11 @@ Core and Builtins 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 ----------------- @@ -28,6 +33,7 @@ Extension Modules and standard packing.) + What's New in Python 2.7 alpha 4? ================================= -- cgit v0.12