[Python-checkins] r83695 - in python/branches/release27-maint: Lib/email/header.py Lib/email/test/test_email.py Lib/email/test/test_email_renamed.py Misc/ACKS Misc/NEWS
r.david.murray
python-checkins at python.org
Wed Aug 4 02:05:51 CEST 2010
Author: r.david.murray
Date: Wed Aug 4 02:05:50 2010
New Revision: 83695
Log:
Merged revisions 83690 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r83690 | r.david.murray | 2010-08-03 18:14:10 -0400 (Tue, 03 Aug 2010) | 10 lines
#3196: if needed pad a short base64 encoded word before trying to decode.
The RFCs encourage following Postel's law: be liberal in what you accept.
So if someone forgot to pad the base64 encoded word payload to an
even four bytes, we add the padding before handing it to base64mime.decode.
Previously, missing padding resulted in a HeaderParseError.
Patch by Jason Williams.
........
Modified:
python/branches/release27-maint/ (props changed)
python/branches/release27-maint/Lib/email/header.py
python/branches/release27-maint/Lib/email/test/test_email.py
python/branches/release27-maint/Lib/email/test/test_email_renamed.py
python/branches/release27-maint/Misc/ACKS
python/branches/release27-maint/Misc/NEWS
Modified: python/branches/release27-maint/Lib/email/header.py
==============================================================================
--- python/branches/release27-maint/Lib/email/header.py (original)
+++ python/branches/release27-maint/Lib/email/header.py Wed Aug 4 02:05:50 2010
@@ -92,6 +92,9 @@
if encoding == 'q':
dec = email.quoprimime.header_decode(encoded)
elif encoding == 'b':
+ paderr = len(encoded) % 4 # Postel's law: add missing padding
+ if paderr:
+ encoded += '==='[:4 - paderr]
try:
dec = email.base64mime.decode(encoded)
except binascii.Error:
Modified: python/branches/release27-maint/Lib/email/test/test_email.py
==============================================================================
--- python/branches/release27-maint/Lib/email/test/test_email.py (original)
+++ python/branches/release27-maint/Lib/email/test/test_email.py Wed Aug 4 02:05:50 2010
@@ -1611,6 +1611,15 @@
('rg', None), ('\xe5', 'iso-8859-1'),
('sbord', None)])
+ def test_rfc2047_B_bad_padding(self):
+ s = '=?iso-8859-1?B?%s?='
+ data = [ # only test complete bytes
+ ('dm==', 'v'), ('dm=', 'v'), ('dm', 'v'),
+ ('dmk=', 'vi'), ('dmk', 'vi')
+ ]
+ for q, a in data:
+ dh = decode_header(s % q)
+ self.assertEqual(dh, [(a, 'iso-8859-1')])
# Test the MIMEMessage class
@@ -3064,7 +3073,7 @@
def test_broken_base64_header(self):
raises = self.assertRaises
- s = 'Subject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3IQ?='
+ s = 'Subject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3I ?='
raises(Errors.HeaderParseError, decode_header, s)
Modified: python/branches/release27-maint/Lib/email/test/test_email_renamed.py
==============================================================================
--- python/branches/release27-maint/Lib/email/test/test_email_renamed.py (original)
+++ python/branches/release27-maint/Lib/email/test/test_email_renamed.py Wed Aug 4 02:05:50 2010
@@ -2958,7 +2958,7 @@
def test_broken_base64_header(self):
raises = self.assertRaises
- s = 'Subject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3IQ?='
+ s = 'Subject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3I ?='
raises(errors.HeaderParseError, decode_header, s)
Modified: python/branches/release27-maint/Misc/ACKS
==============================================================================
--- python/branches/release27-maint/Misc/ACKS (original)
+++ python/branches/release27-maint/Misc/ACKS Wed Aug 4 02:05:50 2010
@@ -831,6 +831,7 @@
Gerry Wiener
Frank Wierzbicki
Bryce "Zooko" Wilcox-O'Hearn
+Jason Williams
John Williams
Sue Williams
Gerald S. Williams
Modified: python/branches/release27-maint/Misc/NEWS
==============================================================================
--- python/branches/release27-maint/Misc/NEWS (original)
+++ python/branches/release27-maint/Misc/NEWS Wed Aug 4 02:05:50 2010
@@ -24,6 +24,9 @@
Library
-------
+- Issue #3196: email header decoding is now forgiving if an RFC2047
+ encoded word encoded in base64 is lacking padding.
+
- Issue #9444: Argparse now uses the first element of prefix_chars as
the option character for the added 'h/help' option if prefix_chars
does not contain a '-', instead of raising an error.
More information about the Python-checkins
mailing list