Reworked IMAP event notification code.