summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_smtplib.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2014-04-14 22:21:38 (GMT)
committerR David Murray <rdmurray@bitdance.com>2014-04-14 22:21:38 (GMT)
commitafb151a5cc6fb1012d4b2827d2fdcbf98c07206d (patch)
treeab03e825771e5a38d34ce218cfa26a26fd0b90b7 /Lib/test/test_smtplib.py
parent4a24d09d623f66368bb3ab12dd8f1fed589cece4 (diff)
downloadcpython-afb151a5cc6fb1012d4b2827d2fdcbf98c07206d.zip
cpython-afb151a5cc6fb1012d4b2827d2fdcbf98c07206d.tar.gz
cpython-afb151a5cc6fb1012d4b2827d2fdcbf98c07206d.tar.bz2
#17498: Defer SMTPServerDisconnected errors until the next command.
Normally an SMTP server will return an error, and smtplib will then issue an RSET to return the connection to the known starting state. Some servers, however, disconnect after issuing certain errors. When we issue the RSET, this would result in raising an SMTPServerDisconnected error, *instead* of returning the error code the user of the library was expecting. This fix makes the internal RSET calls ignore the disconnection so that the error code is returned. The user of the library will then get the SMTPServerDisconnected error the next time they try to talk to the server. Patch by Kushal Das.
Diffstat (limited to 'Lib/test/test_smtplib.py')
-rw-r--r--Lib/test/test_smtplib.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_smtplib.py b/Lib/test/test_smtplib.py
index 3f7b9b4..16e90f4 100644
--- a/Lib/test/test_smtplib.py
+++ b/Lib/test/test_smtplib.py
@@ -619,6 +619,7 @@ class SimSMTPChannel(smtpd.SMTPChannel):
data_response = None
rcpt_count = 0
rset_count = 0
+ disconnect = 0
def __init__(self, extra_features, *args, **kw):
self._extrafeatures = ''.join(
@@ -684,6 +685,8 @@ class SimSMTPChannel(smtpd.SMTPChannel):
super().smtp_MAIL(arg)
else:
self.push(self.mail_response)
+ if self.disconnect:
+ self.close_when_done()
def smtp_RCPT(self, arg):
if self.rcpt_response is None:
@@ -875,6 +878,16 @@ class SMTPSimTests(unittest.TestCase):
#TODO: add tests for correct AUTH method fallback now that the
#test infrastructure can support it.
+ # Issue 17498: make sure _rset does not raise SMTPServerDisconnected exception
+ def test__rest_from_mail_cmd(self):
+ smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
+ smtp.noop()
+ self.serv._SMTPchannel.mail_response = '451 Requested action aborted'
+ self.serv._SMTPchannel.disconnect = True
+ with self.assertRaises(smtplib.SMTPSenderRefused):
+ smtp.sendmail('John', 'Sally', 'test message')
+ self.assertIsNone(smtp.sock)
+
# Issue 5713: make sure close, not rset, is called if we get a 421 error
def test_421_from_mail_cmd(self):
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)