From dfcb74dc878d3bc5d83c1ce66f0cdc81511a4a19 Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Wed, 25 Nov 2020 15:20:42 +0100 Subject: [PATCH] do not create contact with invalid email in get_or_create_contact() --- email_handler.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/email_handler.py b/email_handler.py index 7aff0cf3..93fb2aae 100644 --- a/email_handler.py +++ b/email_handler.py @@ -104,6 +104,7 @@ from app.email_utils import ( generate_reply_email, is_reply_email, normalize_reply_email, + is_valid_email, ) from app.extensions import db from app.greylisting import greylisting_needed @@ -178,6 +179,16 @@ def get_or_create_contact( ) _, contact_email = parseaddr_unicode(mail_from) + if contact_email and not is_valid_email(contact_email): + LOG.exception( + "invalid contact email %s. Parse from %s %s", + contact_email, + contact_from_header, + mail_from, + ) + # either reuse a contact with empty email or create a new contact with empty email + contact_email = "" + contact = Contact.get_by(alias_id=alias.id, website_email=contact_email) if contact: if contact.name != contact_name: