Refactoring in mail module.
Merge commit 'a5c4359' into v2.0.0