Skip to content

Commit 9d7d02a

Browse files
committed
Remove example and example.com/net/org from the special use domains list
By popular demand in #78.
1 parent 2bd672f commit 9d7d02a

File tree

2 files changed

+71
-14
lines changed

2 files changed

+71
-14
lines changed

email_validator/__init__.py

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,66 @@
3939
# IANA Special Use Domain Names
4040
# Last Updated 2021-09-21
4141
# https://www.iana.org/assignments/special-use-domain-names/special-use-domain-names.txt
42+
#
4243
# The domain names without dots would be caught by the check that the domain
4344
# name in an email address must have a period, but this list will also catch
4445
# subdomains of these domains, which are also reserved.
4546
SPECIAL_USE_DOMAIN_NAMES = (
46-
"arpa", # consolidated from a lot of arpa subdomains, we'll assume all subdomains of arpa are actually reserved
47-
"example",
48-
"example.com",
49-
"example.net",
50-
"example.org",
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.
5175
"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.
5281
"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.
5386
"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.
5491
"onion",
55-
"test", # see special logic for 'test' where this is checked
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",
56102
)
57103

58104
# ease compatibility in type checking
@@ -501,11 +547,7 @@ def validate_email_domain_part(domain, test_environment=False):
501547
# Some might fail DNS-based deliverability checks, but that
502548
# can be turned off, so we should fail them all sooner.
503549
for d in SPECIAL_USE_DOMAIN_NAMES:
504-
# RFC 6761 says that applications should not block use of the 'test'
505-
# domain name, presumably because that would prevent it from being
506-
# used for actual testing. We'll block it, except when a special
507-
# testing flag is used, indicating that the module is being used
508-
# in a test environment.
550+
# See the note near the definition of SPECIAL_USE_DOMAIN_NAMES.
509551
if d == "test" and test_environment:
510552
continue
511553

tests/test_main.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import dns.resolver
2+
import re
23
import pytest
34
from email_validator import EmailSyntaxError, EmailUndeliverableError, \
45
validate_email, validate_email_deliverability, \
@@ -260,9 +261,6 @@ def test_email_invalid_syntax(email_input, error_msg):
260261
'email_input',
261262
[
262263
('me@anything.arpa'),
263-
('me@anything.example'),
264-
('me@example.com'),
265-
('me@mail.example.com'),
266264
('me@valid.invalid'),
267265
('me@link.local'),
268266
('me@host.localhost'),
@@ -279,6 +277,23 @@ def test_email_invalid_reserved_domain(email_input):
279277
assert "is a special-use or reserved name" in str(exc_info.value)
280278

281279

280+
@pytest.mark.parametrize(
281+
'email_input',
282+
[
283+
('me@mail.example'),
284+
('me@example.com'),
285+
('me@mail.example.com'),
286+
],
287+
)
288+
def test_email_example_reserved_domain(email_input):
289+
# Since these all fail deliverabiltiy from a static list,
290+
# DNS deliverability checks do not arise.
291+
with pytest.raises(EmailUndeliverableError) as exc_info:
292+
validate_email(email_input)
293+
# print(f'({email_input!r}, {str(exc_info.value)!r}),')
294+
assert re.match(r"The domain name [a-z\.]+ does not (accept email|exist)\.", str(exc_info.value)) is not None
295+
296+
282297
@pytest.mark.parametrize(
283298
'email_input',
284299
[

0 commit comments

Comments
 (0)