[Commits] (bkirsch) Added the ability to turn off TLS in smtp twisted code by extending ESMTPSehder

commits at osafoundation.org commits at osafoundation.org
Thu Aug 19 17:33:13 PDT 2004


Commit by: bkirsch
Modified files:
chandler/parcels/osaf/mail/common.py 1.4 1.5
chandler/parcels/osaf/mail/imap.py 1.12 1.13
chandler/parcels/osaf/mail/smtp.py 1.3 1.4

Log message:
Added the ability to turn off TLS in smtp twisted code by extending ESMTPSehder

ViewCVS links:
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/mail/common.py.diff?r1=text&tr1=1.4&r2=text&tr2=1.5
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/mail/imap.py.diff?r1=text&tr1=1.12&r2=text&tr2=1.13
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/mail/smtp.py.diff?r1=text&tr1=1.3&r2=text&tr2=1.4

Index: chandler/parcels/osaf/mail/imap.py
diff -u chandler/parcels/osaf/mail/imap.py:1.12 chandler/parcels/osaf/mail/imap.py:1.13
--- chandler/parcels/osaf/mail/imap.py:1.12	Thu Aug 19 16:59:55 2004
+++ chandler/parcels/osaf/mail/imap.py	Thu Aug 19 17:33:12 2004
@@ -1,5 +1,5 @@
-__revision__  = "$Revision: 1.12 $"
-__date__      = "$Date: 2004/08/19 23:59:55 $"
+__revision__  = "$Revision: 1.13 $"
+__date__      = "$Date: 2004/08/20 00:33:12 $"
 __copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -41,7 +41,7 @@
         """
 
         if not self.useSSL:
-            self.serverCapabilities =  self.__disableTLS(caps)
+            self.serverCapabilities =  common.disableTwistedTLS(caps)
 
         d = defer.Deferred()
         d.addCallback(self.factory.callback, self)
@@ -50,21 +50,6 @@
         d.callback(True)
 
 
-    def __disableTLS(self, caps):
-        """Disables SSL support for debugging so
-           a tcpflow trace can be done on the Client / Server
-           command exchange"""
-
-        if caps != None:
-            try:
-                del caps["STARTTLS"]
-
-            except KeyError:
-                pass
-
-        return caps
-
-
 class ChandlerIMAP4Factory(protocol.ClientFactory):
     protocol = ChandlerIMAP4Client
 

Index: chandler/parcels/osaf/mail/common.py
diff -u chandler/parcels/osaf/mail/common.py:1.4 chandler/parcels/osaf/mail/common.py:1.5
--- chandler/parcels/osaf/mail/common.py:1.4	Tue Aug 17 14:47:57 2004
+++ chandler/parcels/osaf/mail/common.py	Thu Aug 19 17:33:12 2004
@@ -1,5 +1,5 @@
-__revision__  = "$Revision: 1.4 $"
-__date__      = "$Date: 2004/08/17 21:47:57 $"
+__revision__  = "$Revision: 1.5 $"
+__date__      = "$Date: 2004/08/20 00:33:12 $"
 __copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -36,3 +36,22 @@
     """
 
     return email.message_from_string(message)
+
+
+
+def disableTwistedTLS(items):
+    """Disables SSL support for debugging so
+       a tcpflow trace can be done on the Client / Server
+       command exchange
+    """
+
+    if items != None:
+        try:
+            del items["STARTTLS"]
+
+        except KeyError:
+            pass
+
+    return items
+
+

Index: chandler/parcels/osaf/mail/smtp.py
diff -u chandler/parcels/osaf/mail/smtp.py:1.3 chandler/parcels/osaf/mail/smtp.py:1.4
--- chandler/parcels/osaf/mail/smtp.py:1.3	Thu Aug 19 16:59:55 2004
+++ chandler/parcels/osaf/mail/smtp.py	Thu Aug 19 17:33:12 2004
@@ -1,5 +1,5 @@
-__revision__  = "$Revision: 1.3 $"
-__date__      = "$Date: 2004/08/19 23:59:55 $"
+__revision__  = "$Revision: 1.4 $"
+__date__      = "$Date: 2004/08/20 00:33:12 $"
 __copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -22,6 +22,26 @@
 except ImportError:
     from StringIO import StringIO
 
+class ChandlerESMTPSender(smtp.ESMTPSender):
+
+    def tryTLS(self, code, resp, items):
+        if not self.factory.useSSL:
+            items = common.disableTwistedTLS(items)
+
+        smtp.ESMTPSender.tryTLS(self, code, resp, items)
+
+class ChandlerESMTPSenderFactory(smtp.ESMTPSenderFactory):
+
+    protocol = ChandlerESMTPSender
+
+    def __init__(self, username, password, fromEmail, toEmail, file, deferred, retries=5, contextFactory=None,
+                 heloFallback=False, requireAuthentication=True, requireTransportSecurity=True, useSSL=False):
+
+        self.useSSL = useSSL
+
+        smtp.ESMTPSenderFactory.__init__(self, username, password, fromEmail, toEmail, file, deferred, retries,
+                                         contextFactory, heloFallback, requireAuthentication, requireTransportSecurity)
+
 
 class SMTPException(common.MailException):
     pass
@@ -108,14 +128,12 @@
         finally:
            self.restorePreviousView()
 
-        factory = smtp.ESMTPSenderFactory(username, password, from_addr, to_addrs, msg, d,
-                                          0, contextFactory=sslContext, requireAuthentication=authRequired,
-                                          requireTransportSecurity=False)
+        factory = ChandlerESMTPSenderFactory(username, password, from_addr, to_addrs, msg, d,
+                                             0, sslContext, False, authRequired, useSSL, useSSL)
         #XXX: Is this correct
-        if useSSL:
-            reactor.connectSSL(host, port, factory, sslContext)
-        else:
-            reactor.connectTCP(host, port, factory)
+        #if useSSL:
+        #    reactor.connectSSL(host, port, factory, sslContext)
+        reactor.connectTCP(host, port, factory)
 
 
     def __mailSuccess(self, result):



More information about the Commits mailing list