From 9143a0f6bc4383c45f5e6a5fb90c527be588e71a Mon Sep 17 00:00:00 2001 From: Carlos Quintana <74399022+cquintana92@users.noreply.github.com> Date: Fri, 10 Feb 2023 10:07:43 +0100 Subject: [PATCH] fix: ensure contact name fits within db limits (#1568) --- app/models.py | 2 ++ email_handler.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/app/models.py b/app/models.py index 1ad906e5..4f99b6fe 100644 --- a/app/models.py +++ b/app/models.py @@ -1641,6 +1641,8 @@ class Contact(Base, ModelMixin): Store configuration of sender (website-email) and alias. """ + MAX_NAME_LENGTH = 512 + __tablename__ = "contact" __table_args__ = ( diff --git a/email_handler.py b/email_handler.py index d0a6b3f7..0b5eec20 100644 --- a/email_handler.py +++ b/email_handler.py @@ -182,6 +182,10 @@ def get_or_create_contact(from_header: str, mail_from: str, alias: Alias) -> Con except ValueError: contact_name, contact_email = "", "" + # Ensure contact_name is within limits + if len(contact_name) >= Contact.MAX_NAME_LENGTH: + contact_name = contact_name[0 : Contact.MAX_NAME_LENGTH] + if not is_valid_email(contact_email): # From header is wrongly formatted, try with mail_from if mail_from and mail_from != "<>":