Port of mail module to last beluga version
Clean source code