db, imap: retrieve messages from db