mirror of
https://github.com/simple-login/app.git
synced 2025-02-20 22:02:54 +08:00
add email_belongs_to_alias_domains() to verify if an email belongs to one of the alias domains
This commit is contained in:
parent
a6507a39e4
commit
d7ed0d77bd
2 changed files with 20 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue