]> granicus.if.org Git - python/commitdiff
#11584: make decode_header handle Header objects correctly
authorR David Murray <rdmurray@bitdance.com>
Sat, 18 Jun 2011 16:30:55 +0000 (12:30 -0400)
committerR David Murray <rdmurray@bitdance.com>
Sat, 18 Jun 2011 16:30:55 +0000 (12:30 -0400)
This updates b21fdfa0019c, which fixed this bug incorrectly.

Lib/email/header.py
Lib/email/test/test_email.py
Misc/NEWS

index 0a66df54ae63c8ff7da93c6a1845fae085da5197..06708853c2d90de91981c5300b658ceabeb21db6 100644 (file)
@@ -73,9 +73,10 @@ def decode_header(header):
     An email.errors.HeaderParseError may be raised when certain decoding error
     occurs (e.g. a base64 decoding exception).
     """
-    # If it is a Header object, we can just return the chunks.
+    # If it is a Header object, we can just return the encoded chunks.
     if hasattr(header, '_chunks'):
-        return list(header._chunks)
+        return [(_charset._encode(string, str(charset)), str(charset))
+                    for string, charset in header._chunks]
     # If no encoding, just return the header with no charset.
     if not ecre.search(header):
         return [(header, None)]
index 281a65a6da4df693b5617fe2b04024c335912d7d..97a1e86a25f65306aa01dea736b2ca7a15d5d72d 100644 (file)
@@ -4176,8 +4176,8 @@ A very long line that must get split to something other than at the
 
     def test_escaped_8bit_header(self):
         x = b'Ynwp4dUEbay Auction Semiar- No Charge \x96 Earn Big'
-        x = x.decode('ascii', 'surrogateescape')
-        h = Header(x, charset=email.charset.UNKNOWN8BIT)
+        e = x.decode('ascii', 'surrogateescape')
+        h = Header(e, charset=email.charset.UNKNOWN8BIT)
         self.assertEqual(str(h),
                         'Ynwp4dUEbay Auction Semiar- No Charge \uFFFD Earn Big')
         self.assertEqual(email.header.decode_header(h), [(x, 'unknown-8bit')])
index 170d5224d96b8b66112fc893074db60b8e484bb5..9c3f69347e5c2c849da7590be4c486577f032a83 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -25,6 +25,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #11584: email.header.decode_header no longer fails if the header
+  passed to it is a Header object.
+
 - Issue #11700: mailbox proxy object close methods can now be called multiple
   times without error.