> This bug has already been reported to the OfflineIMAP folks:
> http://software.complete.org/software/issues/show/20 . Apparently the
> bug in Python is fixed, so this problem will no longer occur with
> Python 2.5.3 and higher. However, contrary to the impression given by
> the issue tracker, earlier versions of Python (including the python25
> in Fink) do not have the fix so far as I can tell.
> 
> For earlier versions of Python, there is a way to fix OfflineIMAP
> without hacking on Python; see my patch in the issue tracker. Vincent,
> what do you think of including my patch in Fink's OfflineIMAP  until
> Python 2.5.3 is released and distributed by Fink? At that time, we can
> remove the patch and add a dependency on python25 (>= 1:2.5.2-1) .

Mmkay, I applied your patch, plus a similar one of mine for the non-ssl 
behavior (which also produced the same kind of crash). I am attaching 
the file. At least it doesn't crash for me anymore using IMAP, but I 
don't have access to an IMAPS server at this time, so I will trust you 
on that part.

I will show it to the offlineimap mailing list too and attach it to the 
tracker item of fink (which is currently delayed, with good reason, 
precisely because of its crashing behavior).

  /vincent

-- 
Vincent Beffara
UMPA - ENS Lyon
46 Allée d'Italie
69364 LYON cedex 07
Tel: 04 72 72 85 25
Fax: 04 72 72 84 80
diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py
index 4e37ece..ac39b77 100644
--- a/offlineimap/imapserver.py
+++ b/offlineimap/imapserver.py
@@ -23,6 +23,8 @@ from threading import *
 import thread, hmac, os
 import base64
 
+from StringIO import StringIO
+
 try:
     # do we have a recent pykerberos?
     have_gss = False
@@ -60,10 +62,38 @@ class UsefulIMAP4(UsefulIMAPMixIn, imaplib.IMAP4):
     def open(self, host = '', port = imaplib.IMAP4_PORT):
         imaplibutil.new_open(self, host, port)
 
+    # This is a hack to go around Darwin's implementation of
+    # realloc(), which Python uses inside the socket class. If a message
+    # is larger than 1M, we get it piece by piece instead of all at
+    # once.
+
+    def read(self, size):
+        read = 0
+        io = StringIO()
+        while read < size:
+            tmp = size-read
+            if (tmp>1000000): tmp=1000000
+            data = self.file.read(tmp)
+            read += len(data)
+            io.write(data)
+        return io.getvalue()
+
 class UsefulIMAP4_SSL(UsefulIMAPMixIn, imaplibutil.WrappedIMAP4_SSL):
     def open(self, host = '', port = imaplib.IMAP4_SSL_PORT):
         imaplibutil.new_open_ssl(self, host, port)
 
+    # This is the same thing as above, except we can be a little bit
+    # more clever by avoiding the socket class altogether.
+
+    def read(self, size):
+        read = 0
+        io = StringIO()
+        while read < size:
+            data = self.sslobj.read(size-read)
+            read += len(data)
+            io.write(data)
+        return io.getvalue()
+
 class UsefulIMAP4_Tunnel(UsefulIMAPMixIn, imaplibutil.IMAP4_Tunnel): pass
 
 class IMAPServer:
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Fink-devel mailing list
Fink-devel@lists.sourceforge.net
http://news.gmane.org/gmane.os.apple.fink.devel

Reply via email to