Working email_in and email_out functions

Tested on psql database test. Still need rigorous input validation