diff --git a/app/email_utils.py b/app/email_utils.py index 3a205ff6..334fa4c0 100644 --- a/app/email_utils.py +++ b/app/email_utils.py @@ -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 diff --git a/tests/test_email_utils.py b/tests/test_email_utils.py index 93106747..0b5aad55 100644 --- a/tests/test_email_utils.py +++ b/tests/test_email_utils.py @@ -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")