[Twisted-Python] IMAP4 plain authentication

Hi, My first post to this list, so apologies in advance if this has already been discussed. I`ve been experimenting with some of the sample code from Abe Fettings (very good) Twisted book and I`m a little stuck with one IMAP authentication method. The code is: from twisted.protocols import imap4 from twisted.internet import protocol, defer class IMAPFolderListProtocol(imap4.IMAP4Client): def serverGreeting(self, capabilities): self.registerAuthenticator( imap4.CramMD5ClientAuthenticator(self.factory.username)) self.registerAuthenticator( imap4.LOGINAuthenticator(self.factory.username)) authenticating = self.authenticate(self.factory.password) authenticating.addCallback(self.__loggedIn) authenticating.chainDeferred(self.factory.deferred) def __loggedIn(self, results): return self.list("", "*").addCallback(self.__gotMailboxList) def __gotMailboxList(self, list): return [boxInfo[2] for boxInfo in list] def connectionLost(self, reason): if not self.factory.deferred.called: # connection was lost unexpectedly! self.factory.deferred.errback(reason) class IMAPFolderListFactory(protocol.ClientFactory): protocol = IMAPFolderListProtocol def __init__(self, username, password): self.username = username self.password = password self.deferred = defer.Deferred() def clientConnectionFailed(self, connection, reason): self.deferred.errback(reason) if __name__ == "__main__": from twisted.internet import reactor import sys, getpass def printMailboxList(list): list.sort() for box in list: print box reactor.stop() def handleError(error): print >> sys.stderr, "Error:", error.getErrorMessage() reactor.stop() if not len(sys.argv) == 3: print "Usage: %s server login" % sys.argv[0] sys.exit(1) server = sys.argv[1] user = sys.argv[2] password = getpass.getpass("Password: ") factory = IMAPFolderListFactory(user, password) factory.deferred.addCallback( printMailboxList).addErrback( handleError) reactor.connectTCP(server, 143, factory) reactor.run() However, when I try to connect to my IMAP4 server using this code, I get: Error: No supported authentication schemes available: Server supports ['PLAIN'], client supports ['CRAM-MD5', 'LOGIN'] I can`t seem to find a suitable PLAIN method in IMAP4client, so before I re-invent the wheel, is there a standard Twisted way to handle this situation (or am I simply missing something obvious)? Thanks, David

On Jan 23, 2006, at 6:00 AM, Thomas HERVE wrote:
If you're just working through a tutorial you can disregard this, but you might consider the fact that the IMAPrev4 spec doesn't allow plaintext authentication over a non-SSL connection. Of course, no server I know of implements the spec to the letter (I believe there's a reason for this I'm forgetting), but changing a reactor.connectTCP() call to a reactor.connectSSL() call (with the requisite arguments) is always something I find amazing (due to its simplicity)... Hrm, that was a lot of parentheses....well, it's still early... -phil

On Jan 23, 2006, at 6:00 AM, Thomas HERVE wrote:
If you're just working through a tutorial you can disregard this, but you might consider the fact that the IMAPrev4 spec doesn't allow plaintext authentication over a non-SSL connection. Of course, no server I know of implements the spec to the letter (I believe there's a reason for this I'm forgetting), but changing a reactor.connectTCP() call to a reactor.connectSSL() call (with the requisite arguments) is always something I find amazing (due to its simplicity)... Hrm, that was a lot of parentheses....well, it's still early... -phil
participants (3)
-
David Watson
-
Phil Christensen
-
Thomas HERVE