mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-01-09 07:33:19 -06:00
49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
##########################################################################
|
|
#
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
#
|
|
# Copyright (C) 2013 - 2024, The pgAdmin Development Team
|
|
# This software is released under the PostgreSQL Licence
|
|
#
|
|
##########################################################################
|
|
|
|
import email_validator
|
|
from email_validator import validate_email as email_validate, \
|
|
EmailNotValidError
|
|
|
|
|
|
def validate_email(email, email_config=None):
|
|
try:
|
|
if email_config is None:
|
|
email_config = {}
|
|
import config
|
|
email_config['CHECK_EMAIL_DELIVERABILITY'] = \
|
|
config.CHECK_EMAIL_DELIVERABILITY
|
|
email_config['ALLOW_SPECIAL_EMAIL_DOMAINS'] = \
|
|
config.ALLOW_SPECIAL_EMAIL_DOMAINS
|
|
|
|
# Allow special email domains
|
|
if isinstance(email_config['ALLOW_SPECIAL_EMAIL_DOMAINS'], str):
|
|
email_config['ALLOW_SPECIAL_EMAIL_DOMAINS'] = \
|
|
email_config['ALLOW_SPECIAL_EMAIL_DOMAINS'].split(',')
|
|
|
|
try:
|
|
email_validator.SPECIAL_USE_DOMAIN_NAMES = [
|
|
d for d in email_validator.SPECIAL_USE_DOMAIN_NAMES
|
|
if d not in email_config['ALLOW_SPECIAL_EMAIL_DOMAINS']
|
|
]
|
|
except Exception:
|
|
pass
|
|
|
|
# Validate.
|
|
_ = email_validate(
|
|
email,
|
|
check_deliverability=email_config['CHECK_EMAIL_DELIVERABILITY'])
|
|
|
|
# Update with the normalized form.
|
|
return True
|
|
except EmailNotValidError as e:
|
|
# email is not valid, exception message is human-readable
|
|
print(str(e))
|
|
return False
|