An unfortunate reality is that IMAP is a really bad protocol. I encourage you to try implementing a client to get a feel for how difficult and quirky the protocol is. (Be sure to try implementing IDLE)
I'd love to see a better base protocol with a clean extension mechanism and a culture of documenting and publishing such extenstions. One can dream :)