http://imapfw.offlineimap.org IMAP/mail framework under MIT licence and written in Python
With message reordering I would assume that deadlocks could be tricky.
Ah, ok. But how about e.g. manipulating the IMAP/Maildir?