diff --git a/app/email_utils.py b/app/email_utils.py index ddbfbaab..5ccc852f 100644 --- a/app/email_utils.py +++ b/app/email_utils.py @@ -1070,7 +1070,7 @@ def generate_reply_email(contact_email: str, alias: Alias) -> str: contact_email = contact_email.replace(".", "_") contact_email = convert_to_alphanumeric(contact_email) - reply_domain = alias.get_domain() + reply_domain = get_email_domain_part(alias.email) # not use while to avoid infinite loop for _ in range(1000): if include_sender_in_reverse_alias and contact_email: diff --git a/app/models.py b/app/models.py index 9cf2d845..7782d984 100644 --- a/app/models.py +++ b/app/models.py @@ -1593,10 +1593,6 @@ class Alias(Base, ModelMixin): else: return self.user.email - def get_domain(self) -> str: - splitPos = self.email.find("@") - return self.email[splitPos + 1 :] - def __repr__(self): return f"" diff --git a/email_handler.py b/email_handler.py index a00192d9..fbdb3f0e 100644 --- a/email_handler.py +++ b/email_handler.py @@ -1032,7 +1032,7 @@ def handle_reply(envelope, msg: Message, rcpt_to: str) -> (bool, str): alias = contact.alias alias_address: str = contact.alias.email - alias_domain = alias_address[alias_address.find("@") + 1 :] + alias_domain = get_email_domain_part(alias_address) # Sanity check: verify alias domain is managed by SimpleLogin # scenario: a user have removed a domain but due to a bug, the aliases are still there diff --git a/tests/test_email_utils.py b/tests/test_email_utils.py index 1137df49..126d4c61 100644 --- a/tests/test_email_utils.py +++ b/tests/test_email_utils.py @@ -473,10 +473,12 @@ def test_generate_reply_email(flask_client): alias = Alias.create_new_random(user, AliasGeneratorEnum.uuid.value) Session.commit() reply_email = generate_reply_email("test@example.org", alias) - assert reply_email.endswith(alias.get_domain()) + domain = get_email_domain_part(alias.email) + assert reply_email.endswith(domain) reply_email = generate_reply_email("", alias) - assert reply_email.endswith(alias.get_domain()) + domain = get_email_domain_part(alias.email) + assert reply_email.endswith(domain) def test_generate_reply_email_include_sender_in_reverse_alias(flask_client): @@ -488,10 +490,12 @@ def test_generate_reply_email_include_sender_in_reverse_alias(flask_client): reply_email = generate_reply_email("test@example.org", alias) assert reply_email.startswith("test_at_example_org") - assert reply_email.endswith(alias.get_domain()) + domain = get_email_domain_part(alias.email) + assert reply_email.endswith(domain) reply_email = generate_reply_email("", alias) - assert reply_email.endswith(alias.get_domain()) + domain = get_email_domain_part(alias.email) + assert reply_email.endswith(domain) reply_email = generate_reply_email("👌汉字@example.org", alias) assert reply_email.startswith("yizi_at_example_org")