refactor importMails and add tests