imap: better error handling for a couple of routines