[PATCH] imapserver.py: Implement STARTTLS

Sebastian Spaeth Sebastian at SSpaeth.de
Fri Jun 24 14:06:07 UTC 2011


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 at SSpaeth.de>
---
Here is a small patch against next which implements STARTTLS and changes
the Changelog draft.  I verified that I could connect via Starttls just
fine to my IMAP server so that patch is not totally broken.

I am not sure if we want to take feature additions such as this one now,
or if we want to postpone it until the nect merge cycle.

 Changelog.draft.rst       |    3 +++
 offlineimap/imapserver.py |   11 +++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/Changelog.draft.rst b/Changelog.draft.rst
index 3d20bcf..fecce26 100644
--- a/Changelog.draft.rst
+++ b/Changelog.draft.rst
@@ -13,6 +13,9 @@ others.
 New Features
 ------------
 
+* Added StartTLS support, it will automatically be used if the server
+  supports it.
+
 Changes
 -------
 
diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py
index 10492cd..a020193 100644
--- a/offlineimap/imapserver.py
+++ b/offlineimap/imapserver.py
@@ -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:
-- 
1.7.4.1




More information about the OfflineIMAP-project mailing list