mail refactor