1from typing import TYPE_CHECKING
2
3# Export the main method, helper methods, and the public data types.
4from .exceptions import EmailNotValidError, EmailSyntaxError, EmailUndeliverableError
5from .types import ValidatedEmail
6from .validate_email import validate_email
7from .version import __version__
8
9__all__ = ["validate_email",
10 "ValidatedEmail", "EmailNotValidError",
11 "EmailSyntaxError", "EmailUndeliverableError",
12 "caching_resolver", "__version__"]
13
14if TYPE_CHECKING:
15 from .deliverability import caching_resolver
16else:
17 def caching_resolver(*args, **kwargs):
18 # Lazy load `deliverability` as it is slow to import (due to dns.resolver)
19 from .deliverability import caching_resolver
20
21 return caching_resolver(*args, **kwargs)
22
23
24# These global attributes are a part of the library's API and can be
25# changed by library users.
26
27# Default values for keyword arguments.
28
29ALLOW_SMTPUTF8 = True
30ALLOW_EMPTY_LOCAL = False
31ALLOW_QUOTED_LOCAL = False
32ALLOW_DOMAIN_LITERAL = False
33ALLOW_DISPLAY_NAME = False
34STRICT = False
35GLOBALLY_DELIVERABLE = True
36CHECK_DELIVERABILITY = True
37TEST_ENVIRONMENT = False
38DEFAULT_TIMEOUT = 15 # secs
39
40# IANA Special Use Domain Names
41# Last Updated 2021-09-21
42# https://www.iana.org/assignments/special-use-domain-names/special-use-domain-names.txt
43#
44# The domain names without dots would be caught by the check that the domain
45# name in an email address must have a period, but this list will also catch
46# subdomains of these domains, which are also reserved.
47SPECIAL_USE_DOMAIN_NAMES = [
48 # The "arpa" entry here is consolidated from a lot of arpa subdomains
49 # for private address (i.e. non-routable IP addresses like 172.16.x.x)
50 # reverse mapping, plus some other subdomains. Although RFC 6761 says
51 # that application software should not treat these domains as special,
52 # they are private-use domains and so cannot have globally deliverable
53 # email addresses, which is an assumption of this library, and probably
54 # all of arpa is similarly special-use, so we reject it all.
55 "arpa",
56
57 # RFC 6761 says applications "SHOULD NOT" treat the "example" domains
58 # as special, i.e. applications should accept these domains.
59 #
60 # The domain "example" alone fails our syntax validation because it
61 # lacks a dot (we assume no one has an email address on a TLD directly).
62 # "@example.com/net/org" will currently fail DNS-based deliverability
63 # checks because IANA publishes a NULL MX for these domains, and
64 # "@mail.example[.com/net/org]" and other subdomains will fail DNS-
65 # based deliverability checks because IANA does not publish MX or A
66 # DNS records for these subdomains.
67 # "example", # i.e. "wwww.example"
68 # "example.com",
69 # "example.net",
70 # "example.org",
71
72 # RFC 6761 says that applications are permitted to treat this domain
73 # as special and that DNS should return an immediate negative response,
74 # so we also immediately reject this domain, which also follows the
75 # purpose of the domain.
76 "invalid",
77
78 # RFC 6762 says that applications "may" treat ".local" as special and
79 # that "name resolution APIs and libraries SHOULD recognize these names
80 # as special," and since ".local" has no global definition, we reject
81 # it, as we expect email addresses to be gloally routable.
82 "local",
83
84 # RFC 6761 says that applications (like this library) are permitted
85 # to treat "localhost" as special, and since it cannot have a globally
86 # deliverable email address, we reject it.
87 "localhost",
88
89 # RFC 7686 says "applications that do not implement the Tor protocol
90 # SHOULD generate an error upon the use of .onion and SHOULD NOT
91 # perform a DNS lookup.
92 "onion",
93
94 # Although RFC 6761 says that application software should not treat
95 # these domains as special, it also warns users that the address may
96 # resolve differently in different systems, and therefore it cannot
97 # have a globally routable email address, which is an assumption of
98 # this library, so we reject "@test" and "@*.test" addresses, unless
99 # the test_environment keyword argument is given, to allow their use
100 # in application-level test environments. These domains will generally
101 # fail deliverability checks because "test" is not an actual TLD.
102 "test",
103]