imapserver.py: Implement STARTTLS

If we do not use a SSL connection anyway and if the server supports it,
authenticate automatically with STARTTLS.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Sebastian Spaeth 2011-06-24 16:06:07 +02:00 committed by Nicolas Sebrecht
parent 416df0fc44
commit 6311716edb
2 changed files with 12 additions and 2 deletions

View File

@ -13,6 +13,9 @@ others.
New Features
------------
* Added StartTLS support, it will automatically be used if the server
supports it.
Changes
-------

View File

@ -233,11 +233,18 @@ class IMAPServer:
self.connectionlock.release()
if not self.gssapi:
if 'STARTTLS' in imapobj.capabilities and not\
self.usessl:
self.ui.debug('imap',
'Using STARTTLS connection')
imapobj.starttls()
if 'AUTH=CRAM-MD5' in imapobj.capabilities:
self.ui.debug('imap',
'Attempting CRAM-MD5 authentication')
'Attempting CRAM-MD5 authentication')
try:
imapobj.authenticate('CRAM-MD5', self.md5handler)
imapobj.authenticate('CRAM-MD5',
self.md5handler)
except imapobj.error, val:
self.plainauth(imapobj)
else: