[Checkins] SVN: zope.sendmail/trunk/src/zope/sendmail/ - can now talk to servers that don't implement EHLO

Benji York benji at zope.com
Fri Nov 2 16:17:52 EDT 2007


Log message for revision 81411:
  - can now talk to servers that don't implement EHLO
  - fix bug that caused files with very long names to be created
  - whitespace fixes
  

Changed:
  U   zope.sendmail/trunk/src/zope/sendmail/README.txt
  U   zope.sendmail/trunk/src/zope/sendmail/delivery.py
  U   zope.sendmail/trunk/src/zope/sendmail/mailer.py
  U   zope.sendmail/trunk/src/zope/sendmail/tests/test_mailer.py

-=-
Modified: zope.sendmail/trunk/src/zope/sendmail/README.txt
===================================================================
--- zope.sendmail/trunk/src/zope/sendmail/README.txt	2007-11-02 16:19:38 UTC (rev 81410)
+++ zope.sendmail/trunk/src/zope/sendmail/README.txt	2007-11-02 20:17:51 UTC (rev 81411)
@@ -83,8 +83,8 @@
             name="my-app.smtp"
             hostname="mail.my-app.com"
             port="25"
-            /> 
-            
+            />
+
         <mail:queuedDelivery
             name="my-app.mailer"
             permission="zope.Public"
@@ -129,4 +129,3 @@
 
 * The IMailSentEvent and IMailErrorEvent events aren't used and can't be used
   (you don't want to send emails during the commit phase).
-

Modified: zope.sendmail/trunk/src/zope/sendmail/delivery.py
===================================================================
--- zope.sendmail/trunk/src/zope/sendmail/delivery.py	2007-11-02 16:19:38 UTC (rev 81410)
+++ zope.sendmail/trunk/src/zope/sendmail/delivery.py	2007-11-02 20:17:51 UTC (rev 81411)
@@ -262,7 +262,7 @@
                 fromaddr = ''
                 toaddrs = ()
                 head, tail = os.path.split(filename)
-                tmp_filename = os.path.join(head, 'sending-' + tail)
+                tmp_filename = os.path.join(head, '.sending-' + tail)
                 try:
                     # perform a series of operations in an attempt to ensure
                     # that no two threads/processes send this message

Modified: zope.sendmail/trunk/src/zope/sendmail/mailer.py
===================================================================
--- zope.sendmail/trunk/src/zope/sendmail/mailer.py	2007-11-02 16:19:38 UTC (rev 81410)
+++ zope.sendmail/trunk/src/zope/sendmail/mailer.py	2007-11-02 20:17:51 UTC (rev 81411)
@@ -47,23 +47,26 @@
 
         # send EHLO
         code, response = connection.ehlo()
-        if code < 200 or code >300:
-            raise RuntimeError('Error sending EHLO to the SMTP server '
-                                '(code=%s, response=%s)' % (code, response))
+        if code < 200 or code >= 300:
+            code, response = connection.helo()
+            if code < 200 or code >= 300:
+                raise RuntimeError('Error sending HELO to the SMTP server '
+                                   '(code=%s, response=%s)' % (code, response))
 
         # encryption support
-        have_tls =  connection.has_extn('starttls') 
+        have_tls =  connection.has_extn('starttls')
         if not have_tls and self.force_tls:
             raise RuntimeError('TLS is not available but TLS is required')
 
-        if have_tls and have_ssl and not self.no_tls: 
+        if have_tls and have_ssl and not self.no_tls:
             connection.starttls()
             connection.ehlo()
 
-        if connection.does_esmtp: 
+        if connection.does_esmtp:
             if self.username is not None and self.password is not None:
                 connection.login(self.username, self.password)
         elif self.username:
+            import pdb;pdb.set_trace()
             raise RuntimeError('Mailhost does not support ESMTP but a username '
                                 'is configured')
 

Modified: zope.sendmail/trunk/src/zope/sendmail/tests/test_mailer.py
===================================================================
--- zope.sendmail/trunk/src/zope/sendmail/tests/test_mailer.py	2007-11-02 16:19:38 UTC (rev 81410)
+++ zope.sendmail/trunk/src/zope/sendmail/tests/test_mailer.py	2007-11-02 20:17:51 UTC (rev 81411)
@@ -16,24 +16,24 @@
 $Id$
 """
 
-import unittest
 from StringIO import StringIO
 from zope.interface.verify import verifyObject
 from zope.sendmail.interfaces import ISMTPMailer
+from zope.sendmail.mailer import SMTPMailer
+import socket
+import unittest
 
 
 class TestSMTPMailer(unittest.TestCase):
 
     def setUp(self, port=None):
-        from zope.sendmail.mailer import SMTPMailer
-
+        global SMTP
         class SMTP(object):
 
             def __init__(myself, h, p):
                 myself.hostname = h
                 myself.port = p
                 if type(p) == type(u""):
-                    import socket
                     raise socket.error("Int or String expected")
                 self.smtp = myself
 
@@ -59,6 +59,7 @@
             def starttls(self):
                 pass
 
+
         if port is None:
             self.mailer = SMTPMailer()
         else:
@@ -100,9 +101,42 @@
         self.assert_(self.smtp.quit)
 
 
+class TestSMTPMailerWithNoEHLO(TestSMTPMailer):
+
+    def setUp(self, port=None):
+
+        class SMTPWithNoEHLO(SMTP):
+            does_esmtp = False
+
+            def __init__(myself, h, p):
+                myself.hostname = h
+                myself.port = p
+                if type(p) == type(u""):
+                    raise socket.error("Int or String expected")
+                self.smtp = myself
+
+            def helo(self):
+                return (200, 'Hello, I am your stupid MTA mock')
+
+            def ehlo(self):
+                return (502, 'I don\'t understand EHLO')
+
+
+        if port is None:
+            self.mailer = SMTPMailer()
+        else:
+            self.mailer = SMTPMailer(u'localhost', port)
+        self.mailer.smtp = SMTPWithNoEHLO
+
+    def test_send_auth(self):
+        # This test requires ESMTP, which we're intentionally not enabling
+        # here, so pass.
+        pass
+
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(TestSMTPMailer))
+    suite.addTest(unittest.makeSuite(TestSMTPMailerWithNoEHLO))
     return suite
 
 



More information about the Checkins mailing list