diff --git a/Lib/email/parser.py b/Lib/email/parser.py --- a/Lib/email/parser.py +++ b/Lib/email/parser.py @@ -100,9 +100,9 @@ meaning it parses the entire contents of the file. """ fp = TextIOWrapper(fp, encoding='ascii', errors='surrogateescape') - with fp: - return self.parser.parse(fp, headersonly) - + msg = self.parser.parse(fp, headersonly) + fp.detach() + return msg def parsebytes(self, text, headersonly=False): """Create a message structure from a byte string.