Move some mail code to inner package.