Fix extraction of email addresses in some cases

Fixes #2945