]> code.delx.au - offlineimap/commitdiff
Fix performance for SSL
authorJohn Goerzen <jgoerzen@complete.org>
Mon, 3 Mar 2008 14:22:44 +0000 (08:22 -0600)
committerJohn Goerzen <jgoerzen@complete.org>
Mon, 3 Mar 2008 14:22:44 +0000 (08:22 -0600)
Added WrappedIMAP4_SSL class to help fix up performance of SSL

Standard imaplib.py is really bad with this, since it reads one
character at a time.

Reported by Aaron Kaplan at
http://lists.complete.org/offlineimap@complete.org/2008/01/msg00012.html.gz

He wrote:

  I just noticed that the version of offlineimap I've been using
  (3.99.17) is well over four years old.  How time flies.  I haven't
  had any problems with it, but out of curiosity I decided to pull in
  5.99.2 from the fedora repository.  It turns out to take
  consistently over twice as long as the old version to sync the same
  account.  Is this expected?

He tracked it down at
http://lists.complete.org/offlineimap@complete.org/2008/02/msg00012.html.gz

  The following changeset is the one responsible for the difference in
  speed I was noticing between the imaplib.py that was packaged with
  older versions of offlineimap and the one that comes with python:

  * /offlineimap/head: changeset 169
    More optimizations -- this time fix readline() to not work
    character-by-character!

offlineimap/imaplibutil.py
offlineimap/imapserver.py

index 373d227bc2ab0bba33d86505dd8d9dad12776957..23ba654cb3e5ec217d328f1b1727d12ef08b5a25 100644 (file)
@@ -103,6 +103,14 @@ def new_mesg(self, s, secs=None):
             tm = time.strftime('%M:%S', time.localtime(secs))
             UIBase.getglobalui().debug('imap', '  %s.%02d %s' % (tm, (secs*100)%100, s))
 
+class WrappedIMAP4_SSL(IMAP4_SSL):
+    def open(self, host = '', port = IMAP4_SSL_PORT):
+        IMAP4_SSL.open(self, host, port)
+        self.sslobj = sslwrapper(self.sslobj)
+
+    def readline(self):
+        return self.sslobj.readline()
+
 def new_open(self, host = '', port = IMAP4_PORT):
         """Setup connection to remote server on "host:port"
             (default: localhost:standard IMAP4 port).
index b96a4043cf6b9c523686accb3bd714d083e9de2b..6ca1fbcff3969ea489e6c0c88bd8883bd056824d 100644 (file)
@@ -51,7 +51,7 @@ class UsefulIMAP4(UsefulIMAPMixIn, imaplib.IMAP4):
     def open(self, host = '', port = imaplib.IMAP4_PORT):
         imaplibutil.new_open(self, host, port)
 
-class UsefulIMAP4_SSL(UsefulIMAPMixIn, imaplib.IMAP4_SSL):
+class UsefulIMAP4_SSL(UsefulIMAPMixIn, imaplibutil.WrappedIMAP4_SSL):
     def open(self, host = '', port = imaplib.IMAP4_SSL_PORT):
         imaplibutil.new_open_ssl(self, host, port)