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
34GLOBALLY_DELIVERABLE = True
35CHECK_DELIVERABILITY = True
36TEST_ENVIRONMENT = False
37DEFAULT_TIMEOUT = 15 # secs
38
39# IANA Special Use Domain Names
40# Last Updated 2021-09-21
41# https://www.iana.org/assignments/special-use-domain-names/special-use-domain-names.txt
42#
43# The domain names without dots would be caught by the check that the domain
44# name in an email address must have a period, but this list will also catch
45# subdomains of these domains, which are also reserved.
46SPECIAL_USE_DOMAIN_NAMES = [
47 # The "arpa" entry here is consolidated from a lot of arpa subdomains
48 # for private address (i.e. non-routable IP addresses like 172.16.x.x)
49 # reverse mapping, plus some other subdomains. Although RFC 6761 says
50 # that application software should not treat these domains as special,
51 # they are private-use domains and so cannot have globally deliverable
52 # email addresses, which is an assumption of this library, and probably
53 # all of arpa is similarly special-use, so we reject it all.
54 "arpa",
55
56 # RFC 6761 says applications "SHOULD NOT" treat the "example" domains
57 # as special, i.e. applications should accept these domains.
58 #
59 # The domain "example" alone fails our syntax validation because it
60 # lacks a dot (we assume no one has an email address on a TLD directly).
61 # "@example.com/net/org" will currently fail DNS-based deliverability
62 # checks because IANA publishes a NULL MX for these domains, and
63 # "@mail.example[.com/net/org]" and other subdomains will fail DNS-
64 # based deliverability checks because IANA does not publish MX or A
65 # DNS records for these subdomains.
66 # "example", # i.e. "wwww.example"
67 # "example.com",
68 # "example.net",
69 # "example.org",
70
71 # RFC 6761 says that applications are permitted to treat this domain
72 # as special and that DNS should return an immediate negative response,
73 # so we also immediately reject this domain, which also follows the
74 # purpose of the domain.
75 "invalid",
76
77 # RFC 6762 says that applications "may" treat ".local" as special and
78 # that "name resolution APIs and libraries SHOULD recognize these names
79 # as special," and since ".local" has no global definition, we reject
80 # it, as we expect email addresses to be gloally routable.
81 "local",
82
83 # RFC 6761 says that applications (like this library) are permitted
84 # to treat "localhost" as special, and since it cannot have a globally
85 # deliverable email address, we reject it.
86 "localhost",
87
88 # RFC 7686 says "applications that do not implement the Tor protocol
89 # SHOULD generate an error upon the use of .onion and SHOULD NOT
90 # perform a DNS lookup.
91 "onion",
92
93 # Although RFC 6761 says that application software should not treat
94 # these domains as special, it also warns users that the address may
95 # resolve differently in different systems, and therefore it cannot
96 # have a globally routable email address, which is an assumption of
97 # this library, so we reject "@test" and "@*.test" addresses, unless
98 # the test_environment keyword argument is given, to allow their use
99 # in application-level test environments. These domains will generally
100 # fail deliverability checks because "test" is not an actual TLD.
101 "test",
102]