various email related bug fixes and unit tests