Saturday, March 29, 2008

OfflineIMAP MemoryError on OS X 10.4.11

I tried out OfflineIMAP, for the first time tonight. My internet connection has been particularly slow lately and I thought a bit of local caching might reduce the annoyance factor. Installing OfflineIMAP was easy. With DarwinPorts, I just did sudo port install offlineimap. The installation instructions were easy enough to follow and within a few minutes the synchronization process had started.

After a couple minutes, however, offlineimap died with a stack backtrace complaining about a MemoryError and mentioning something about self._sock.recv(recv_size). I thought perhaps the problem was intermittent and tried again, but it always died while processing the same error message. After a manual IMAP session using a telnet client, I was able to locate exactly which message was causing the problem. The message was about 9 MB in size and I assumed that was causing the problem.

After googling for anything relevant, I came across this bug report. Fortunately, the last comment (from 2008-02-23) mentions the revision in which this problem is fixed. Interestingly, the fix that was actually used was proposed over 2 years ago. Here's a visual diff showing the patch itself.

Anyway, to fix the problem yourself, try sudo vi +302 /opt/local//Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/socket.py and change max to min. OfflineIMAP now works just fine. If you're using the Python version that came with OS X 10.4.11, this'll get you to the right place in the right file: vi +300 /System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/ socket.py