Skip to content

Commit 9a96e59

Browse files
authored
Accept tagged IPv6 email address literals
1 parent 6ffd862 commit 9a96e59

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎src/validators/email.py‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
# local
77
from .hostname import hostname
8+
from .ip_address import ipv6
89
from .utils import validator
910

1011

@@ -39,7 +40,8 @@ def email(
3940
value:
4041
eMail string to validate.
4142
ipv6_address:
42-
When the domain part is an IPv6 address.
43+
When the domain part is an IPv6 address, including an RFC 5321
44+
address literal such as `[IPv6:2001:db8::1]`.
4345
ipv4_address:
4446
When the domain part is an IPv4 address.
4547
simple_host:
@@ -67,7 +69,12 @@ def email(
6769
if ipv6_address or ipv4_address:
6870
if domain_part.startswith("[") and domain_part.endswith("]"):
6971
# ref: RFC 5321
70-
domain_part = domain_part.lstrip("[").rstrip("]")
72+
if domain_part[1:6].lower() == "ipv6:":
73+
domain_part = domain_part[6:-1]
74+
if not ipv6_address or "%" in domain_part or not ipv6(domain_part, cidr=False):
75+
return False
76+
else:
77+
domain_part = domain_part.lstrip("[").rstrip("]")
7178
else:
7279
return False
7380

0 commit comments

Comments
 (0)