MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / validate_email

Function validate_email

web/pgadmin/utils/validation_utils.py:15–59  ·  view source on GitHub ↗
(email, email_config=None)

Source from the content-addressed store, hash-verified

13
14
15def validate_email(email, email_config=None):
16 # email_validator raises TypeError (not EmailNotValidError) when the
17 # input is not str/bytes. Treat anything non-string as invalid so
18 # callers see a clean False, matching the contract that this wrapper
19 # never raises.
20 if not isinstance(email, (str, bytes)):
21 return False
22 try:
23 if email_config is None:
24 email_config = {}
25 import config
26 email_config['CHECK_EMAIL_DELIVERABILITY'] = \
27 config.CHECK_EMAIL_DELIVERABILITY
28 email_config['ALLOW_SPECIAL_EMAIL_DOMAINS'] = \
29 config.ALLOW_SPECIAL_EMAIL_DOMAINS
30 email_config["GLOBALLY_DELIVERABLE"] = \
31 config.GLOBALLY_DELIVERABLE
32
33 # Allow special email domains
34 if isinstance(email_config['ALLOW_SPECIAL_EMAIL_DOMAINS'], str):
35 email_config['ALLOW_SPECIAL_EMAIL_DOMAINS'] = \
36 email_config['ALLOW_SPECIAL_EMAIL_DOMAINS'].split(',')
37
38 try:
39 email_validator.SPECIAL_USE_DOMAIN_NAMES = [
40 d for d in email_validator.SPECIAL_USE_DOMAIN_NAMES
41 if d not in email_config['ALLOW_SPECIAL_EMAIL_DOMAINS']
42 ]
43 except Exception:
44 pass
45
46 email_validator.GLOBALLY_DELIVERABLE = \
47 email_config["GLOBALLY_DELIVERABLE"]
48
49 # Validate.
50 _ = email_validate(
51 email,
52 check_deliverability=email_config['CHECK_EMAIL_DELIVERABILITY'])
53
54 # Update with the normalized form.
55 return True
56 except EmailNotValidError as e:
57 # email is not valid, exception message is human-readable
58 print(str(e))
59 return False

Callers 4

validate_userFunction · 0.90
runTestMethod · 0.90
validateMethod · 0.90
user_info_serverFunction · 0.90

Calls

no outgoing calls

Tested by 1

runTestMethod · 0.72