fix encoding of emails and update tests.

@maethu