After many battles with the imap extension I took it upon myself to write my own implementation using sockets. Below is what I came up with, and hopefully it will be usefull to others as well. I know that there are some parts of this that can be tweaked, however I will leave that for you to do. Use/abuse/mutilate this as you wish (no license).
(Note: I am not placing the source here since it is well over 1900 lines ~48KB)
http://www.nutextonline.com/cimap.phps
If enough people find this usefull I will continue to improve it and eventually commit it (or have it committed) to pear.
Also worth noting is the fact that you can use the imap extensions on mbox format mailboxes. A combination of this class with the imap extension would certainly make a great combination of done correctly.