[IMP] mail: Refactor code