validate address in try_auto_create
This commit is contained in:
parent
0b127216ee
commit
2b84168d68
|
@ -1,6 +1,7 @@
|
||||||
import re
|
import re
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
from email_validator import validate_email, EmailNotValidError
|
||||||
from sqlalchemy.exc import IntegrityError, DataError
|
from sqlalchemy.exc import IntegrityError, DataError
|
||||||
|
|
||||||
from app.config import BOUNCE_PREFIX_FOR_REPLY_PHASE
|
from app.config import BOUNCE_PREFIX_FOR_REPLY_PHASE
|
||||||
|
@ -10,6 +11,7 @@ from app.email_utils import (
|
||||||
send_cannot_create_domain_alias,
|
send_cannot_create_domain_alias,
|
||||||
can_create_directory_for_address,
|
can_create_directory_for_address,
|
||||||
send_cannot_create_directory_alias_disabled,
|
send_cannot_create_directory_alias_disabled,
|
||||||
|
get_email_local_part,
|
||||||
)
|
)
|
||||||
from app.errors import AliasInTrashError
|
from app.errors import AliasInTrashError
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
|
@ -34,6 +36,12 @@ def try_auto_create(address: str) -> Optional[Alias]:
|
||||||
LOG.e("alias %s can't start with %s", address, BOUNCE_PREFIX_FOR_REPLY_PHASE)
|
LOG.e("alias %s can't start with %s", address, BOUNCE_PREFIX_FOR_REPLY_PHASE)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
# NOT allow unicode for now
|
||||||
|
validate_email(address, check_deliverability=False, allow_smtputf8=False)
|
||||||
|
except EmailNotValidError:
|
||||||
|
return None
|
||||||
|
|
||||||
alias = try_auto_create_catch_all_domain(address)
|
alias = try_auto_create_catch_all_domain(address)
|
||||||
if not alias:
|
if not alias:
|
||||||
alias = try_auto_create_directory(address)
|
alias = try_auto_create_directory(address)
|
||||||
|
|
Loading…
Reference in a new issue