cpython (merge 3.4 -> default): Merge #22215: have the smtplib 'quit' command reset the state.

http://hg.python.org/cpython/rev/d0d4ab0ba70e changeset: 92272:d0d4ab0ba70e parent: 92270:c499cc2c4a06 parent: 92271:a058760cb069 user: R David Murray <rdmurray@bitdance.com> date: Sat Aug 30 16:55:45 2014 -0400 summary: Merge #22215: have the smtplib 'quit' command reset the state. files: Lib/smtplib.py | 4 ++++ Lib/test/test_smtplib.py | 15 +++++++++++++++ Misc/NEWS | 4 ++++ 3 files changed, 23 insertions(+), 0 deletions(-) diff --git a/Lib/smtplib.py b/Lib/smtplib.py --- a/Lib/smtplib.py +++ b/Lib/smtplib.py @@ -891,6 +891,10 @@ def quit(self): """Terminate the SMTP session.""" res = self.docmd("quit") + # A new EHLO is required after reconnecting with connect() + self.ehlo_resp = self.helo_resp = None + self.esmtp_features = {} + self.does_esmtp = False self.close() return res diff --git a/Lib/test/test_smtplib.py b/Lib/test/test_smtplib.py --- a/Lib/test/test_smtplib.py +++ b/Lib/test/test_smtplib.py @@ -876,6 +876,21 @@ str(err)) smtp.close() + def test_quit_resets_greeting(self): + smtp = smtplib.SMTP(HOST, self.port, + local_hostname='localhost', + timeout=15) + code, message = smtp.ehlo() + self.assertEqual(code, 250) + self.assertIn('size', smtp.esmtp_features) + smtp.quit() + self.assertNotIn('size', smtp.esmtp_features) + smtp.connect(HOST, self.port) + self.assertNotIn('size', smtp.esmtp_features) + smtp.ehlo_or_helo_if_needed() + self.assertIn('size', smtp.esmtp_features) + smtp.quit() + def test_with_statement(self): with smtplib.SMTP(HOST, self.port) as smtp: code, message = smtp.noop() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -124,6 +124,10 @@ Library ------- +- Issue #22216: smtplib now resets its state more completely after a quit. The + most obvious consequence of the previous behavior was a STARTTLS failure + during a connect/starttls/quit/connect/starttls sequence. + - Issue #22098: ctypes' BigEndianStructure and LittleEndianStructure now define an empty __slots__ so that subclasses don't always get an instance dict. Patch by Claudiu Popa. -- Repository URL: http://hg.python.org/cpython
participants (1)
-
r.david.murray