do not create contact with invalid email in get_or_create_contact()

This commit is contained in:
Son NK 2020-11-25 15:20:42 +01:00
parent 609d59d23f
commit dfcb74dc87
1 changed files with 11 additions and 0 deletions

View File

@ -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: