[IMP] mail: Refactor some code