[Checkins] SVN: zope.sendmail/branches/3.7/ Avoid requeuing messages after an SMTP "recipients refused" error.

Tres Seaver cvs-admin at zope.org
Wed May 23 12:23:22 UTC 2012


Log message for revision 126451:
  Avoid requeuing messages after an SMTP "recipients refused" error.
  
  https://bugs.launchpad.net/zope.sendmail/+bug/1003288
  

Changed:
  U   zope.sendmail/branches/3.7/CHANGES.txt
  U   zope.sendmail/branches/3.7/src/zope/sendmail/queue.py
  U   zope.sendmail/branches/3.7/src/zope/sendmail/tests/test_queue.py

-=-
Modified: zope.sendmail/branches/3.7/CHANGES.txt
===================================================================
--- zope.sendmail/branches/3.7/CHANGES.txt	2012-05-23 09:38:04 UTC (rev 126450)
+++ zope.sendmail/branches/3.7/CHANGES.txt	2012-05-23 12:23:18 UTC (rev 126451)
@@ -5,6 +5,8 @@
 3.7.5 (unreleased)
 ------------------
 
+- Avoid requeuing messages after an SMTP "recipients refused" error.
+  https://bugs.launchpad.net/zope.sendmail/+bug/1003288
 
 3.7.4 (2010-10-01)
 ------------------

Modified: zope.sendmail/branches/3.7/src/zope/sendmail/queue.py
===================================================================
--- zope.sendmail/branches/3.7/src/zope/sendmail/queue.py	2012-05-23 09:38:04 UTC (rev 126450)
+++ zope.sendmail/branches/3.7/src/zope/sendmail/queue.py	2012-05-23 12:23:18 UTC (rev 126451)
@@ -271,6 +271,12 @@
                             else:
                                 # Log an error and retry later
                                 raise
+                        except smtplib.SMTPRecipientsRefused, e:
+                            # All recipients are refused by smtp
+                            # server. Dont try to redeliver the message.
+                            self.log.error("Email recipients refused: %s",
+                                           ', '.join(e.recipients))
+                            _os_link(filename, rejected_filename)
 
                         try:
                             os.unlink(filename)

Modified: zope.sendmail/branches/3.7/src/zope/sendmail/tests/test_queue.py
===================================================================
--- zope.sendmail/branches/3.7/src/zope/sendmail/tests/test_queue.py	2012-05-23 09:38:04 UTC (rev 126450)
+++ zope.sendmail/branches/3.7/src/zope/sendmail/tests/test_queue.py	2012-05-23 12:23:18 UTC (rev 126451)
@@ -134,6 +134,27 @@
                              'bar at example.com, baz at example.com',
                              "(550, 'Serious Error')"), {})])
 
+    def test_smtp_recipients_refused(self):
+        # Test a permanent error
+        self.thread.setMailer(SMTPRecipientsRefusedMailerStub(
+                               ['bar at example.com']))
+        self.filename = os.path.join(self.dir, 'message')
+        temp = open(self.filename, "w+b")
+        temp.write('X-Zope-From: foo at example.com\n'
+                   'X-Zope-To: bar at example.com, baz at example.com\n'
+                   'Header: value\n\nBody\n')
+        temp.close()
+        self.md.files.append(self.filename)
+        self.thread.run(forever=False)
+
+        # File must be moved aside
+        self.failIf(os.path.exists(self.filename))
+        self.failUnless(os.path.exists(os.path.join(self.dir,
+                                                    '.rejected-message')))
+        self.assertEquals(self.thread.log.errors,
+                          [('Email recipients refused: %s',
+                           ('bar at example.com',), {})])
+
 test_ini = """[app:zope-sendmail]
 interval = 33
 hostname = testhost
@@ -253,6 +274,16 @@
         self.assertFalse(app.no_tls)
 
 
+class SMTPRecipientsRefusedMailerStub(object):
+
+    def __init__(self, recipients):
+        self.recipients = recipients
+
+    def send(self, fromaddr, toaddrs, message):
+        import smtplib
+        raise smtplib.SMTPRecipientsRefused(self.recipients)
+
+
 def test_suite():
     return TestSuite((
         makeSuite(TestQueueProcessorThread),



More information about the checkins mailing list