You can't understand the IMAP spec until you have been personally berated by Mark Crispin. Unfortunately, Mark has passed away, so the number of people who understand the spec is only going to decrease.
Thankfully his responses are saved for posterity in the imap-protocol discussion list archive. ;)
https://mailman2.u.washington.edu/mailman/mmsearch/imap-prot...