#11584: make decode_header handle Header objects correctly
This updates b21fdfa0019c, which fixed this bug incorrectly.
This commit is contained in:
parent
c88bce1580
commit
6bdb1769dc
|
@ -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)]
|
||||
|
|
|
@ -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')])
|
||||
|
|
Loading…
Reference in New Issue