/offlineimap/head: changeset 275

Trial cram-md5 support
This commit is contained in:
jgoerzen 2002-11-02 23:14:02 +01:00
parent 3c395c66a9
commit 2ebdae19c9

View File

@ -19,7 +19,7 @@
from offlineimap import imaplib, imaputil, threadutil from offlineimap import imaplib, imaputil, threadutil
from offlineimap.ui import UIBase from offlineimap.ui import UIBase
from threading import * from threading import *
import thread import thread, hmac, base64
class UsefulIMAPMixIn: class UsefulIMAPMixIn:
@ -90,6 +90,20 @@ class IMAPServer:
self.connectionlock.release() self.connectionlock.release()
self.semaphore.release() self.semaphore.release()
def md5handler(self, response):
print "md5handler: got", response
response = response.strip()
challenge = base64.decodestring(response).strip()
msg = self.password
while len(msg) < 64:
msg += "\0"
reply = hmac.new(challenge, msg)
retval = base64.encodestring(self.username + ' ' + \
reply.hexdigest())
print "md5handler: returning", retval
return retval
def acquireconnection(self): def acquireconnection(self):
"""Fetches a connection from the pool, making sure to create a new one """Fetches a connection from the pool, making sure to create a new one
if needed, to obey the maximum connection limits, etc. if needed, to obey the maximum connection limits, etc.
@ -133,7 +147,10 @@ class IMAPServer:
imapobj = UsefulIMAP4(self.hostname, self.port) imapobj = UsefulIMAP4(self.hostname, self.port)
if not self.tunnel: if not self.tunnel:
imapobj.login(self.username, self.password) try:
imapobj.authenticate('CRAM-MD5', self.md5handler)
except:
imapobj.login(self.username, self.password)
if self.delim == None: if self.delim == None:
listres = imapobj.list(self.reference, '""')[1] listres = imapobj.list(self.reference, '""')[1]