- adding some debugout witch hopefully helps to find errors with loggin in to differe...
authorRico Schulte <ricoschulte@users.schwerkraft.elitedvb.net>
Sun, 23 Sep 2007 15:43:04 +0000 (15:43 +0000)
committerRico Schulte <ricoschulte@users.schwerkraft.elitedvb.net>
Sun, 23 Sep 2007 15:43:04 +0000 (15:43 +0000)
- add connectSSL while using Port 993

Tested with IMAP-Server of GMX.net and new with IMAP-Server of WEB.de. Both working with Port 143 and 993.

If your server doesnt work, send me the complet output to 3c5x9(at)gmx(dot)net

emailclient/src/plugin.py
emailclient/src/protocol.py

index 8d48ac1..d04900c 100755 (executable)
@@ -200,8 +200,18 @@ class EmailScreen(Screen, EmailHandler):
             
     def onConnect(self, proto):
         self["infolabel"].setText("connected")
+        proto.getCapabilities(
+                        ).addCallback(self.cbCapabilities, proto
+                        ).addErrback(self.ebCapabilities, proto
+                        )
+
+    def cbCapabilities(self,reason,proto):
+        print "cbCapabilities",reason
+        
         self.doLogin(proto)
-        #self.doLoginInsecure(proto)
+
+    def ebCapabilities(reason,proto):
+        print "ebCapabilities",reason
         
     def onConnectFailed(self, reason):
         self["infolabel"].setText(reason.getErrorMessage())
@@ -215,10 +225,16 @@ class EmailScreen(Screen, EmailHandler):
         
     def doLogin(self, proto):
         print "login secure"
-        proto.authenticate(config.plugins.emailimap.password.value
-                           ).addCallback(self.onAuthentication, proto
-                           ).addErrback(self.onAuthenticationFailed, proto
-                           )
+        useTLS = False #True
+        if useTLS:
+            context = proto.context.getContext()
+            d = proto.startTLS(context)
+            d = d.addCallback(proto.authenticate, config.plugins.emailimap.password.value)
+        else:
+            d = proto.authenticate(config.plugins.emailimap.password.value)
+        d.addCallback(self.onAuthentication, proto)
+        d.addErrback(self.onAuthenticationFailed, proto)
+        return d
 
     def onAuthenticationFailed(self, failure, proto):
         # If it failed because no SASL mechanisms match
index 7d23866..bf047cf 100755 (executable)
@@ -6,13 +6,17 @@ from twisted.internet import stdio
 from twisted.mail import imap4
 from twisted.protocols import basic
 
+#from twisted.python import log
+#log.startLogging(open("/tmp/twisted.log","w"))
+
 class SimpleIMAP4Client(imap4.IMAP4Client):
     greetDeferred = None
-    def __init__(self,e2session, contextFactory = None):
+    def __init__(self,e2session, contextFac = None):
         self.e2session = e2session
-        imap4.IMAP4Client.__init__(self,contextFactory = contextFactory)
+        imap4.IMAP4Client.__init__(self,contextFactory = contextFac)
         
     def serverGreeting(self, caps):
+        print "serverGreeting",caps
         self.serverCapabilities = caps
         if self.greetDeferred is not None:
             d, self.greetDeferred = self.greetDeferred, None
@@ -22,14 +26,15 @@ class SimpleIMAP4ClientFactory(protocol.ClientFactory):
     
     protocol = SimpleIMAP4Client
 
-    def __init__(self, e2session, username, onConn):
-        self.ctx = ssl.ClientContextFactory()
+    def __init__(self, e2session, username, onConn,factory):
+        self.ctx = factory
         self.e2session = e2session
         self.username = username
         self.onConn = onConn
 
     def buildProtocol(self, addr):
-        p = self.protocol(self.e2session,self.ctx)
+        print "building protocol",addr
+        p = self.protocol(self.e2session,contextFac = self.ctx)
         p.factory = self
         p.greetDeferred = self.onConn
         auth = imap4.CramMD5ClientAuthenticator(self.username)
@@ -47,6 +52,11 @@ def createFactory( e2session,username,hostname, port):
         ).addErrback(e2session.onConnectFailed
         )
 
-    factory = SimpleIMAP4ClientFactory(e2session,username, onConn)
-    reactor.connectTCP(hostname, port, factory)
-    
\ No newline at end of file
+    f2 = ssl.ClientContextFactory()
+    factory = SimpleIMAP4ClientFactory(e2session,username, onConn,f2)
+    if port == 993:
+        reactor.connectSSL( hostname, port,factory,f2)
+    else:
+        reactor.connectTCP( hostname, port,factory)
+
+    print "factory started"
\ No newline at end of file