Refactor sync to imap. Use inheritance for sharing code.