From 366631ee93b53fc07c7fc99095fd816259604de6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Casaj=C3=BAs?= Date: Fri, 4 Aug 2023 16:17:45 +0200 Subject: [PATCH] Limit length of contact names (#1837) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Adrià Casajús --- email_handler.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/email_handler.py b/email_handler.py index d061bb2e..7db73bc6 100644 --- a/email_handler.py +++ b/email_handler.py @@ -279,6 +279,9 @@ def get_or_create_reply_to_contact( except ValueError: return + if len(contact_name) >= Contact.MAX_NAME_LENGTH: + contact_name = contact_name[0 : Contact.MAX_NAME_LENGTH] + if not is_valid_email(contact_address): LOG.w( "invalid reply-to address %s. Parse from %s", @@ -347,6 +350,10 @@ def replace_header_when_forward(msg: Message, alias: Alias, header: str): continue contact = Contact.get_by(alias_id=alias.id, website_email=contact_email) + contact_name = full_address.display_name + if len(contact_name) >= Contact.MAX_NAME_LENGTH: + contact_name = contact_name[0 : Contact.MAX_NAME_LENGTH] + if contact: # update the contact name if needed if contact.name != full_address.display_name: @@ -354,9 +361,9 @@ def replace_header_when_forward(msg: Message, alias: Alias, header: str): "Update contact %s name %s to %s", contact, contact.name, - full_address.display_name, + contact_name, ) - contact.name = full_address.display_name + contact.name = contact_name Session.commit() else: LOG.d( @@ -371,7 +378,7 @@ def replace_header_when_forward(msg: Message, alias: Alias, header: str): user_id=alias.user_id, alias_id=alias.id, website_email=contact_email, - name=full_address.display_name, + name=contact_name, reply_email=generate_reply_email(contact_email, alias), is_cc=header.lower() == "cc", automatic_created=True,