Use helper

This commit is contained in:
Adrià Casajús 2023-04-12 12:13:29 +02:00
parent ce2269d3eb
commit 90cef3ca7d
No known key found for this signature in database
GPG key ID: F0033226A5AFC9B9
4 changed files with 10 additions and 10 deletions

View file

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

View file

@ -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"<Alias {self.id} {self.email}>"

View file

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

View file

@ -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")