refactor stuffs based on imap-legacy