mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2025-04-04 00:17:06 +00:00
Allow .local domains as valid email address, which fixes an issue caused by the 'email_validator' python module that was recently updated to version 1.2.1
This commit is contained in:
parent
65a393cb3f
commit
c79fca6a45
@ -14,11 +14,20 @@ import subprocess, shutil, os, sqlite3, re, ldap3, uuid, hashlib
|
||||
import utils, backend
|
||||
from email_validator import validate_email as validate_email_, EmailNotValidError
|
||||
import idna
|
||||
import socket
|
||||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# remove "local" as a "special use domain" from email_validator
|
||||
# globally because validate validate_email_(email,
|
||||
# test_environment=True) is broken in email_validator 1.2.1
|
||||
# @TODO: remove once email_validator's test_environment argument is fixed (see validate_email() below)
|
||||
import email_validator as _evx
|
||||
_evx.SPECIAL_USE_DOMAIN_NAMES.remove("local")
|
||||
|
||||
|
||||
#
|
||||
# LDAP notes:
|
||||
#
|
||||
@ -74,11 +83,18 @@ def validate_email(email, mode=None):
|
||||
|
||||
# Check the syntax of the address.
|
||||
try:
|
||||
# allow .local domains to pass when they refer to the local machine
|
||||
email_domain = get_domain(email)
|
||||
test_env = (
|
||||
email_domain.endswith(".local") and
|
||||
email_domain == socket.getfqdn()
|
||||
)
|
||||
validate_email_(email,
|
||||
allow_smtputf8=False,
|
||||
check_deliverability=False,
|
||||
allow_empty_local=(mode=="alias")
|
||||
)
|
||||
allow_empty_local=(mode=="alias"),
|
||||
test_environment=test_env
|
||||
)
|
||||
except EmailNotValidError:
|
||||
return False
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user