def buildProtocol(self, addr): p = protocol.ClientFactory.buildProtocol(self, addr) username = self.settings["Username"] p.registerAuthenticator(imap4.CramMD5ClientAuthenticator(username)) p.registerAuthenticator(imap4.LOGINAuthenticator(username)) p.registerAuthenticator(imap4.PLAINAuthenticator(username)) return p
def callback(password): password = password.encode("utf-8") self.proto.registerAuthenticator( imap4.CramMD5ClientAuthenticator(username)) self.proto.registerAuthenticator( imap4.LOGINAuthenticator(username)) return self.proto.authenticate(password).addCallback( self.cb).addErrback(self.loginClientInsecure, username, password).addErrback(self.catchErrors)
def buildProtocol(self, addr): p = self.protocol(self.context) p.factory = self p.greetdefer = self.onconn auth1 = imap4.CramMD5ClientAuthenticator(self.uid) auth2 = imap4.PLAINAuthenticator(self.uid) auth3 = imap4.LOGINAuthenticator(self.uid) p.registerAuthenticator(auth1) p.registerAuthenticator(auth3) p.registerAuthenticator(auth2) p.registerAuthenticator(auth1) return p
def buildProtocol(self, addr): assert not self.usedUp self.usedUp = True p = self.protocol() p.factory = self p.greetDeferred = self.onConn p.registerAuthenticator(imap4.PLAINAuthenticator(self.username)) p.registerAuthenticator(imap4.LOGINAuthenticator(self.username)) p.registerAuthenticator(imap4.CramMD5ClientAuthenticator( self.username)) return p
def serverGreeting(self, unused_capabilities): """The entry point for the whole program. It merely starts the long-running pipeline. """ # NOTE: Although twisted official example suggest using the capabilities # returned here to decide what kind of authentication methods to # register, I found it to be not true as real capabilities are only # returned after the authentication is successful. username = self.pipeline.username self.registerAuthenticator(imap4.PLAINAuthenticator(username)) self.registerAuthenticator(imap4.LOGINAuthenticator(username)) self.registerAuthenticator(imap4.CramMD5ClientAuthenticator(username)) self.pipeline.start()
def buildProtocol(self, addr): """ Initiate the protocol instance. Since we are building a simple IMAP client, we don't bother checking what capabilities the server has. We just add all the authenticators twisted.mail has. Note: Gmail no longer uses any of the methods below, it's been using XOAUTH since 2010. """ assert not self.usedUp self.usedUp = True p = self.protocol(self.ctx) p.factory = self p.greetDeferred = self.onConn p.registerAuthenticator(imap4.PLAINAuthenticator(self.username)) p.registerAuthenticator(imap4.LOGINAuthenticator(self.username)) p.registerAuthenticator( imap4.CramMD5ClientAuthenticator(self.username)) return p
def _loginClient(self): """Logs a client in to an IMAP servier using the CramMD6, Login, or Plain authentication""" if __debug__: self.printCurrentView("_loginClient") assert self.account is not None """Twisted expects ascii values so encode the utf-8 username and password""" username = self.account.username.encode(constants.DEFAULT_CHARSET) password = self.account.password.encode(constants.DEFAULT_CHARSET) self.proto.registerAuthenticator( imap4.CramMD5ClientAuthenticator(username)) self.proto.registerAuthenticator(imap4.LOGINAuthenticator(username)) return self.proto.authenticate(password).addCallback( self.__selectInbox).addErrback(self.loginClientInsecure, username, password)