Bugfixes from IMAP code refactor.