Merge pull request #143 from simple-login/check-mx
Check MX record of email domain to see if it is disposed
This commit is contained in:
commit
af9e93ea30
|
@ -25,6 +25,7 @@ from app.config import (
|
||||||
MAX_NB_EMAIL_FREE_PLAN,
|
MAX_NB_EMAIL_FREE_PLAN,
|
||||||
DISPOSABLE_EMAIL_DOMAINS,
|
DISPOSABLE_EMAIL_DOMAINS,
|
||||||
)
|
)
|
||||||
|
from app.dns_utils import get_mx_domains
|
||||||
from app.log import LOG
|
from app.log import LOG
|
||||||
from app.models import Mailbox, User
|
from app.models import Mailbox, User
|
||||||
|
|
||||||
|
@ -321,16 +322,40 @@ def can_be_used_as_personal_email(email: str) -> bool:
|
||||||
if CustomDomain.get_by(domain=domain, verified=True):
|
if CustomDomain.get_by(domain=domain, verified=True):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
for d in DISPOSABLE_EMAIL_DOMAINS:
|
if is_disposable_domain(domain):
|
||||||
if domain == d:
|
LOG.d("Domain %s is disposable", domain)
|
||||||
return False
|
return False
|
||||||
# subdomain
|
|
||||||
if domain.endswith("." + d):
|
# check if email MX domain is disposable
|
||||||
|
mx_domains = get_mx_domain_list(domain)
|
||||||
|
for mx_domain in mx_domains:
|
||||||
|
if is_disposable_domain(mx_domain):
|
||||||
|
LOG.d("MX Domain %s %s is disposable", mx_domain, domain)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def is_disposable_domain(domain):
|
||||||
|
for d in DISPOSABLE_EMAIL_DOMAINS:
|
||||||
|
if domain == d:
|
||||||
|
return True
|
||||||
|
# subdomain
|
||||||
|
if domain.endswith("." + d):
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def get_mx_domain_list(domain) -> [str]:
|
||||||
|
"""return list of MX domains for a given email.
|
||||||
|
domain name ends *without* a dot (".") at the end.
|
||||||
|
"""
|
||||||
|
priority_domains = get_mx_domains(domain)
|
||||||
|
|
||||||
|
return [d[:-1] for _, d in priority_domains]
|
||||||
|
|
||||||
|
|
||||||
def email_already_used(email: str) -> bool:
|
def email_already_used(email: str) -> bool:
|
||||||
"""test if an email can be used when:
|
"""test if an email can be used when:
|
||||||
- user signs up
|
- user signs up
|
||||||
|
|
Loading…
Reference in a new issue