Webmail refactoring.

see #585