refractoring Mail module