[FIX] mail: misc bug fixing

I would like some test cases that highlight why you did changes in this file.