diff -r 1cf857652656 Lib/email/quoprimime.py --- a/Lib/email/quoprimime.py Thu Mar 17 12:05:53 2011 -0400 +++ b/Lib/email/quoprimime.py Thu Mar 17 12:29:28 2011 -0400 @@ -135,9 +135,9 @@ charset names the character set to use in the RFC 2046 header. It defaults to iso-8859-1. """ - # Return empty headers unchanged + # Return empty headers as an empty string. if not header_bytes: - return str(header_bytes) + return '' # Iterate over every byte, encoding if necessary. encoded = [] for octet in header_bytes: @@ -268,7 +268,7 @@ if i == n: decoded += eol # Special case if original string did not end with eol - if not encoded.endswith(eol) and decoded.endswith(eol): + if encoded[-1] not in '\r\n' and decoded.endswith(eol): decoded = decoded[:-1] return decoded diff -r 1cf857652656 Lib/email/test/test_email.py --- a/Lib/email/test/test_email.py Thu Mar 17 12:05:53 2011 -0400 +++ b/Lib/email/test/test_email.py Thu Mar 17 12:29:28 2011 -0400 @@ -3299,6 +3299,9 @@ encoded_header = quoprimime.header_encode(header, charset) self.assertEqual(encoded_header, expected_encoded_header) + def test_header_encode_null(self): + self.header_encode(b'', '') + def test_header_encode_one_word(self): self.header_encode(b'hello', '=?iso-8859-1?q?hello?=') @@ -3353,6 +3356,12 @@ def test_decode_one_line_lf(self): self.decode('hello\n', 'hello\n') + def test_decode_one_line_cr(self): + self.decode('hello\r', 'hello\n') + + def test_decode_one_line_eol(self): + self.decode('hello\n', 'helloX', eol='X') + def test_decode_one_line_one_word(self): self.decode('hello\r\nworld', 'hello\nworld') @@ -3362,6 +3371,9 @@ def test_decode_two_lines(self): self.decode('hello\r\nworld\r\n', 'hello\nworld\n') + def test_decode_two_lines_eol(self): + self.decode('hello\r\nworld\r\n', 'helloXworldX', eol='X') + def test_decode_one_long_line(self): self.decode('Spam' * 250, 'Spam' * 250)