refactor and add $formatEmail view function