changeset: 92271:a058760cb069 branch: 3.4 parent: 92268:4cce39cfe46c user: R David Murray date: Sat Aug 30 16:51:59 2014 -0400 files: Lib/smtplib.py Lib/test/test_smtplib.py Misc/NEWS description: #22215: have the smtplib 'quit' command reset the state. Without this reset, starttls would fail if a connect/starttls was done after a quit, because smtplib assumed the existing value of emspt_features was accurate, but it gets reset when starttls completes (and the new value does not contain the starttls capability, since tls is already started at that point). (There may be additional places where this lack of reset was an issue as well.) Patch by Milan Oberkirch. diff -r 4cce39cfe46c -r a058760cb069 Lib/smtplib.py --- a/Lib/smtplib.py Fri Aug 29 23:26:36 2014 +0200 +++ b/Lib/smtplib.py Sat Aug 30 16:51:59 2014 -0400 @@ -866,6 +866,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 -r 4cce39cfe46c -r a058760cb069 Lib/test/test_smtplib.py --- a/Lib/test/test_smtplib.py Fri Aug 29 23:26:36 2014 +0200 +++ b/Lib/test/test_smtplib.py Sat Aug 30 16:51:59 2014 -0400 @@ -858,6 +858,21 @@ self.assertIn(sim_auth_login_password, 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 -r 4cce39cfe46c -r a058760cb069 Misc/NEWS --- a/Misc/NEWS Fri Aug 29 23:26:36 2014 +0200 +++ b/Misc/NEWS Sat Aug 30 16:51:59 2014 -0400 @@ -27,6 +27,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 #22185: Fix an occasional RuntimeError in threading.Condition.wait() caused by mutation of the waiters queue without holding the lock. Patch by Doug Zongker.