reworked email parsing logic