refactor mail.py