Implementation of promises in imapHandler