From 3168cbd785051e95d48e2f2be36b91ce676d367a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Casaj=C3=BAs?= Date: Tue, 28 Jan 2025 12:09:36 +0100 Subject: [PATCH] Manage parse_address error --- email_handler.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/email_handler.py b/email_handler.py index eef1e79f..114ab31e 100644 --- a/email_handler.py +++ b/email_handler.py @@ -47,6 +47,11 @@ from typing import List, Tuple, Optional import newrelic.agent from aiosmtpd.controller import Controller from aiosmtpd.smtp import Envelope +from email_validator import validate_email, EmailNotValidError +from flanker.addresslib import address +from flanker.addresslib.address import EmailAddress +from sqlalchemy.exc import IntegrityError + from app import pgp_utils, s3, config, contact_utils from app.alias_utils import ( try_auto_create, @@ -169,12 +174,8 @@ from app.pgp_utils import ( load_public_key_and_check, ) from app.utils import sanitize_email -from email_validator import validate_email, EmailNotValidError -from flanker.addresslib import address -from flanker.addresslib.address import EmailAddress from init_app import load_pgp_public_keys from server import create_light_app -from sqlalchemy.exc import IntegrityError def get_or_create_contact( @@ -601,7 +602,11 @@ def handle_forward(envelope, msg: Message, rcpt_to: str) -> List[Tuple[bool, str for reply_to in reply_to_header_contents.split(",") if reply_to.strip() ]: - reply_to_name, reply_to_email = parse_full_address(reply_to) + try: + reply_to_name, reply_to_email = parse_full_address(reply_to) + except ValueError: + LOG.d(f"Could not parse reply-to address {reply_to}") + continue if reply_to_email == alias.email: LOG.i("Reply-to same as alias %s", alias) else: