add email_belongs_to_alias_domains() to verify if an email belongs to one of the alias domains

This commit is contained in:
Son NK 2020-01-22 10:13:58 +01:00
parent a6507a39e4
commit d7ed0d77bd
2 changed files with 20 additions and 0 deletions

View File

@ -14,6 +14,7 @@ from app.config import (
DKIM_SELECTOR,
DKIM_PRIVATE_KEY,
DKIM_HEADERS,
ALIAS_DOMAINS,
)
from app.log import LOG
@ -253,3 +254,12 @@ def delete_header(msg: Message, header: str):
for h in msg._headers:
if h[0].lower() == header.lower():
msg._headers.remove(h)
def email_belongs_to_alias_domains(email: str) -> bool:
"""return True if an emails ends with one of the alias domains provided by SimpleLogin"""
for domain in ALIAS_DOMAINS:
if email.endswith("@" + domain):
return True
return False

View File

@ -3,6 +3,7 @@ from app.email_utils import (
get_email_part,
get_email_local_part,
get_email_domain_part,
email_belongs_to_alias_domains,
)
@ -26,3 +27,12 @@ def test_get_email_local_part():
def test_get_email_domain_part():
assert get_email_domain_part("ab@cd.com") == "cd.com"
def test_email_belongs_to_alias_domains():
# default alias domain
assert email_belongs_to_alias_domains("ab@sl.local")
assert not email_belongs_to_alias_domains("ab@not-exist.local")
assert email_belongs_to_alias_domains("hey@d1.test")
assert not email_belongs_to_alias_domains("hey@d3.test")