Split the imap sync code in smaller pieces.