diff -r b6ebc726d5fe Lib/email/quoprimime.py --- a/Lib/email/quoprimime.py Sat Jul 06 13:25:44 2013 +0200 +++ b/Lib/email/quoprimime.py Sat Jul 06 19:00:16 2013 +0400 @@ -319,4 +319,4 @@ the high level email.header class for that functionality. """ s = s.replace('_', ' ') - return re.sub(r'=[a-fA-F0-9]{2}', _unquote_match, s, re.ASCII) + return re.sub(r'=[a-fA-F0-9]{2}', _unquote_match, s, flags=re.ASCII) diff -r b6ebc726d5fe Lib/test/test_email/test_email.py --- a/Lib/test/test_email/test_email.py Sat Jul 06 13:25:44 2013 +0200 +++ b/Lib/test/test_email/test_email.py Sat Jul 06 19:00:16 2013 +0400 @@ -4048,6 +4048,10 @@ def test_header_decode_non_ascii(self): self._test_header_decode('hello=C7there', 'hello\xc7there') + def test_header_decode_re_bug_18380(self): + # Issue 18380: Call re.sub with a positional argument for flags in the wrong position + self.assertEqual(quoprimime.header_decode('=30' * 257), '0' * 257) + def _test_decode(self, encoded, expected_decoded, eol=None): if eol is None: decoded = quoprimime.decode(encoded)