Yasuhito FUTATSUKI at POEM has proposed merging 
lp:~futatuki/mailman/2.1-add-smtp-timeout into lp:mailman/2.1.

Requested reviews:
  Mailman Coders (mailman-coders)

For more details, see:

This add a feature to specify timeout for SMTP response to avoid waiting 
response forever, to SMTPDirect Handler. To specify timeout, set SMTP_TIMEOUT 
in mm_cfg.py.

By default, this is disabled(waiting response until respond the MTA).

To test this feature, set mm_cfg.SMTP_TIMEOUT to small value and setup MTA to 
wait responding (by using greet pause feature, etc) and run smtp test or post 
message to mailing list to deliver it.
Your team Mailman Coders is requested to review the proposed merge of 
lp:~futatuki/mailman/2.1-add-smtp-timeout into lp:mailman/2.1.
=== modified file 'Mailman/Defaults.py.in'
--- Mailman/Defaults.py.in	2018-01-30 04:06:24 +0000
+++ Mailman/Defaults.py.in	2018-02-08 12:35:39 +0000
@@ -591,6 +591,12 @@
 # uses DEFAULT_URL_HOST. Normally, you should not change this.
+# The time to wait for a response from MTA for DELIVERY_MODULE = 'SMTPDirect',
+# in positive float seconds or None. Setting a timeout of None disables 
+# timeouts on socket operations.
+# Note: too short timeout will often cause duplicate message delivery.
 # Set these variables if you need to authenticate to your NNTP server for
 # Usenet posting or reading.  If no authentication is necessary, specify None
 # for both variables.

=== modified file 'Mailman/Handlers/SMTPDirect.py'
--- Mailman/Handlers/SMTPDirect.py	2017-05-23 19:45:06 +0000
+++ Mailman/Handlers/SMTPDirect.py	2018-02-08 12:35:39 +0000
@@ -55,13 +55,24 @@
+if mm_cfg.SMTP_TIMEOUT:
+    # wrapper SMTP class to specify timeout (for Python < 2.6 compatibility)
+    class SMTP(smtplib.SMTP):
+        def connect(self, host='localhost', port=0):
+            sv_to = socket.getdefaulttimeout()
+            socket.setdefaulttimeout(mm_cfg.SMTP_TIMEOUT)
+            smtplib.SMTP.connect(self, host, port)
+            socket.setdefaulttimeout(sv_to)
+    SMTP = smtplib.SMTP
 # Manage a connection to the SMTP server
 class Connection:
     def __init__(self):
         self.__conn = None
     def __connect(self):
-        self.__conn = smtplib.SMTP()
+        self.__conn = SMTP()
         self.__conn.connect(mm_cfg.SMTPHOST, mm_cfg.SMTPPORT)
         if mm_cfg.SMTP_AUTH:

Mailman-coders mailing list

Reply via email to