summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbwarsaw2003-04-19 17:49:03 +0000
committerbwarsaw2003-04-19 17:49:03 +0000
commit502e5ece758a98922ee307bb3ac0a57c18a2bb0f (patch)
treebced5c2cfb0de9d4302e1eba23fbd26dedf71995
parent14162bc86bcba2963bb6a573814d627139eb5fe9 (diff)
downloadmailman-502e5ece758a98922ee307bb3ac0a57c18a2bb0f.tar.gz
mailman-502e5ece758a98922ee307bb3ac0a57c18a2bb0f.tar.zst
mailman-502e5ece758a98922ee307bb3ac0a57c18a2bb0f.zip
Rewrite the Connection class to (hopefully) fix known problems with
SMTP_MAX_SESSIONS_PER_CONNECTION not being honored and connection problems in the middle of a session not being properly recovered. Closing SF bug #707624, although I implemented this in a different way.
-rw-r--r--Mailman/Handlers/SMTPDirect.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/Mailman/Handlers/SMTPDirect.py b/Mailman/Handlers/SMTPDirect.py
index 4724c3a18..da7e3eb2f 100644
--- a/Mailman/Handlers/SMTPDirect.py
+++ b/Mailman/Handlers/SMTPDirect.py
@@ -50,7 +50,7 @@ DOT = '.'
# Manage a connection to the SMTP server
class Connection:
def __init__(self):
- self.__connect()
+ self.__conn = None
def __connect(self):
self.__conn = smtplib.SMTP()
@@ -58,26 +58,30 @@ class Connection:
self.__numsessions = mm_cfg.SMTP_MAX_SESSIONS_PER_CONNECTION
def sendmail(self, envsender, recips, msgtext):
+ if self.__conn is None:
+ self.__connect()
try:
results = self.__conn.sendmail(envsender, recips, msgtext)
except smtplib.SMTPException:
- # For safety, reconnect
- self.__conn.quit()
- self.__connect()
- # Let exceptions percolate up
+ # For safety, close this connection. The next send attempt will
+ # automatically re-open it. Pass the exception on up.
+ self.quit()
raise
- # Decrement the session counter, reconnecting if necessary
+ # This session has been successfully completed.
self.__numsessions -= 1
# By testing exactly for equality to 0, we automatically handle the
# case for SMTP_MAX_SESSIONS_PER_CONNECTION <= 0 meaning never close
# the connection. We won't worry about wraparound <wink>.
if self.__numsessions == 0:
- self.__conn.quit()
- self.__connect()
+ self.quit()
return results
def quit(self):
- self.__conn.quit()
+ try:
+ self.__conn.quit()
+ except smtplib.SMTPException:
+ pass
+ self.__conn = None