logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

CVS: tmda/TMDA SMTP.py,1.5,1.6: msg#00008

Subject: CVS: tmda/TMDA SMTP.py,1.5,1.6
Update of /cvsroot/tmda/tmda/TMDA
In directory sc8-pr-cvs1:/tmp/cvs-serv4283/TMDA

Modified Files:
        SMTP.py 
Log Message:
Sync with Mailman 2.1.x's SMTPDirect.py module.


Index: SMTP.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/SMTP.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SMTP.py     27 Apr 2003 07:58:17 -0000      1.5
+++ SMTP.py     2 Sep 2003 04:12:50 -0000       1.6
@@ -39,7 +39,7 @@
 # Manage a connection to an SMTP server.
 class Connection:
     def __init__(self):
-        self.__connect()
+        self.__conn = None
 
     def __connect(self):
         self.__conn = smtplib.SMTP()
@@ -55,25 +55,32 @@
                                  Defaults.SMTPSSL_CERTFILE)
             
     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()
+        if self.__conn is None:
+            return
+        try:
+            self.__conn.quit()
+        except smtplib.SMTPException:
+            pass
+        self.__conn = None
 

_______________________________________
tmda-cvs mailing list
http://tmda.net/lists/listinfo/tmda-cvs



<Prev in Thread] Current Thread [Next in Thread>