diff --git a/Lib/email/quoprimime.py b/Lib/email/quoprimime.py index bf28d3980db..85efc088aa2 100644 --- a/Lib/email/quoprimime.py +++ b/Lib/email/quoprimime.py @@ -294,4 +294,4 @@ def header_decode(s): the high level email.Header class for that functionality. """ s = s.replace('_', ' ') - return re.sub(r'=\w{2}', _unquote_match, s, re.ASCII) + return re.sub(r'=[a-fA-F0-9]{2}', _unquote_match, s, re.ASCII) diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py index d5ac9c4511f..42a2ee3b2fa 100644 --- a/Lib/email/test/test_email.py +++ b/Lib/email/test/test_email.py @@ -1655,6 +1655,12 @@ def test_rfc2047_B_bad_padding(self): dh = decode_header(s % q) self.assertEqual(dh, [(a, 'iso-8859-1')]) + def test_rfc2047_Q_invalid_digits(self): + # issue 10004. + s = '=?iso-8659-1?Q?andr=e9=zz?=' + self.assertEqual(decode_header(s), + [(b'andr\xe9=zz', 'iso-8659-1')]) + # Test the MIMEMessage class class TestMIMEMessage(TestEmailBase): diff --git a/Misc/NEWS b/Misc/NEWS index 231ca55ed2b..8781c0028cd 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -121,6 +121,9 @@ C-API Library ------- +- Issue #10004: quoprimime no longer generates a traceback when confronted + with invalid characters after '=' in a Q-encoded word. + - Issue #9950: Fix socket.sendall() crash or misbehaviour when a signal is received. Now sendall() properly calls signal handlers if necessary, and retries sending if these returned successfully, including on sockets