summaryrefslogtreecommitdiffstats
path: root/Lib/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/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/smtplib.py')
-rwxr-xr-xLib/smtplib.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/Lib/smtplib.py b/Lib/smtplib.py
index 66b5879..ec43666 100755
--- a/Lib/smtplib.py
+++ b/Lib/smtplib.py
@@ -478,6 +478,18 @@ class SMTP:
"""SMTP 'rset' command -- resets session."""
return self.docmd("rset")
+ def _rset(self):
+ """Internal 'rset' command which ignores any SMTPServerDisconnected error.
+
+ Used internally in the library, since the server disconnected error
+ should appear to the application when the *next* command is issued, if
+ we are doing an internal "safety" reset.
+ """
+ try:
+ self.rset()
+ except SMTPServerDisconnected:
+ pass
+
def noop(self):
"""SMTP 'noop' command -- doesn't do anything :>"""
return self.docmd("noop")
@@ -762,7 +774,7 @@ class SMTP:
if code == 421:
self.close()
else:
- self.rset()
+ self._rset()
raise SMTPSenderRefused(code, resp, from_addr)
senderrs = {}
if isinstance(to_addrs, str):
@@ -776,14 +788,14 @@ class SMTP:
raise SMTPRecipientsRefused(senderrs)
if len(senderrs) == len(to_addrs):
# the server refused all our recipients
- self.rset()
+ self._rset()
raise SMTPRecipientsRefused(senderrs)
(code, resp) = self.data(msg)
if code != 250:
if code == 421:
self.close()
else:
- self.rset()
+ self._rset()
raise SMTPDataError(code, resp)
#if we got here then somebody got our mail
return senderrs