Hi, and welcome to the Imap Extension TODO List!
The IMAP extension, while used across many open projects, has a ton of bugs and performs poorly when compared to user-space implementations like Horde/Imap_Client. The library on which this extension's based, c-client, is unmaintained since 2011.
We need to formulate a plan to either (a) accept the extensions for what it is and just fix bugs or (b) reboot the extension from the ground up.
Help wanted to steer and implement.