Using Offlineimap on Snow Leopard - the Really Fugly Hardcore Solution

So, I got fed up with this issue now and found a solution that isn’t pretty. But it works, apparently without any relevant disadvantages, so I’ll live with it for the time being.

Update: in the comments below there’s a different, somewhat cleaner solution, which doesn’t require you to change your “system” Python files. [SORRY, COMMENT REMOVED]

Yesterday I posted about the problem: offlineimap quits with a “trace trap”, which occurs when the line from _locale import * is executed. For full reference, this line is line 31 of the file locale.py, which lives in your Python version’s library dir. For the standard Python 2.6 that comes with Snow Leopard, that path is /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6 – for your Python version the version number may vary, or in the case of a MacPorts installed Python, it’s going to be somewhere else entirely (/opt/local/lib/python2.5 for instance). I tried hunting down the real origin of this problem, but I wasn’t able to find out anything in the end. I learned an awful lot about using the fantastic toolset that comes with Mac OS X and XCode (Python pdb and gdb, of course, but also the DTrace based stuff like Instruments, dtruss, opensnoop and the like – amazing stuff). But apart from demonstrating that _locale.so can apparently not be imported under the specific circumstances without crashing Python hard, I wasn’t able to get any further. I hope somebody will figure this out eventually.

Meanwhile, looking around the sources (isn’t open source wonderful… – some people always claim you can’t do anything useful with it), I found that there is actually a workaround implementation right there in locale.py. The offending import statement is nested in a try/except block and an exception called ImportError is caught. Presumably that’s the idea. Somehow the problem I’m seeing looks awfully like an import error to me, albeit more of a kick-your-ass-and-hopy-you-die sort of import error (that’s what they say, isn’t it?). So. I just went and took out the import line and the try/except and left the code in place that would be executed in case of the ImportError. Brilliant, eh?

Yeah well, I sort of hate it because I don’t like modifying something I’d call a “system library” from my point of view. Anyway. It works. offlineimap just synchronized about 400 messages or so. Cool. In case you feel like doing the same thing, I’m making a patch file for the file locale.py available here: locale.py.patch

Please be aware that these instructions come without warranty!! They may not work for you or result in other issues! You follow these steps at your own risk!

In order to use the patch, follow these steps:

  1. Download the patch file and save it somewhere on your machine

  2. Find the correct path (see above) where your locale.py lives. Open a Terminal window and cd into that path.

  3. Make a backup copy of the original locale.py: sudo cp locale.py locale.py.orig

  4. Apply the patch with this command: sudo patch < /path/to/locale.py.patch

You should see output from the patch command saying patching file locale.py. This confirms that everything has gone to plan. Now try running offlineimap – it may just work.

Please be aware that these instructions come without warranty!! They may not work for you or result in other issues! You follow these steps at your own risk!

Have fun!

Sorry, this blog does not support comments.

I used various blog hosting services since this blog was established in 2005, but unfortunately they turned out to be unreliable in the long term and comment threads were lost in unavoidable transitions. At this time I don't want to enable third-party services for comments since it has become obvious in recent years that these providers invariably monetize information about their visitors and users.

Please use the links in the page footer to get in touch with me. I'm available for conversations on Keybase, Matrix, Mastodon or Twitter, as well as via email.