Script 'mail_helper' called by obssrc
Hello community,
here is the log from the commit of package python-email-validator for
openSUSE:Factory checked in at 2026-11-23 12:20:24
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-email-validator (Old)
and /work/SRC/openSUSE:Factory/.python-email-validator.new.1340718 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-email-validator"
Mon Nov 23 12:20:24 2026 rev:14 rq:1399564 version:2.4.0
Changes:
--------
---
/work/SRC/openSUSE:Factory/python-email-validator/python-email-validator.changes
2025-10-02 19:20:22.950916672 +0200
+++
/work/SRC/openSUSE:Factory/.python-email-validator.new.1340718/python-email-validator.changes
2026-11-23 12:21:43.099455118 +0100
@@ -1,0 +2,36 @@
+Fri Nov 20 21:53:14 UTC 2026 - Dirk Müller <[email protected]>
+
+- update to 2.4.0:
+ * Python 3.8 and 3.9 are no longer supported, and Python 3.14
+ and 3.15 are added to testing.
+ * The `original` field of the returned validated email object
+ incorrectly un-escaped the local part of the email address.
+ Now it returns the original address, without any display
+ name, as passed to validate_email.
+ * With `allow_quoted_local=True`, a quoted local part
+ containing U+037E (Greek question mark), which Unicode NFC
+ normalization changes to a semicolon, was returned without
+ its quotes in the normalized address (e.g.
+ `a;[email protected]`), getting around the re-validation added in
+ 2.2.0. The normalized local part is now quoted according to
+ its normalized form, giving `"a;b"@example.com`.
+ * When parsing display names, multiple closing angle brackets
+ at the end of the email address is now rejected.
+ * The IPv6 tag of a domain literal is now case-insensitive, as
+ in the RFCs, so `me@[ipv6:::1]` is accepted (and normalized
+ to `me@[IPv6:::1]`) when `allow_domain_literal=True`.
+ * IPv6 domain literals with a zone index are now rejected.
+ * Internationalized domains with a right-to-left label are now
+ rejected if any other label breaks the IDNA Bidi Rule (RFC
+ 5893), such as a label starting with a digit. Such domains,
+ like `1.xn--4dbc.com` and `xn--4dbc.1.com` (`1.אב.com` and
+ `אב.1.com` in Unicode), could be displayed identically.
+ * Faster validation of domains without Punycode (xn--) labels.
+ * Internationalized domains longer than 253 characters are now
+ rejected for their length before IDNA encoding, which could
+ take time quadratic in the length of the input.
+ * The command line tool now properly reads boolean environment
+ variables and the DEFAULT_TIMEOUT environment variable.
+ * Improvements in type hinting, code comments, and tests.
+
+-------------------------------------------------------------------
Old:
----
email_validator-2.3.0.tar.gz
New:
----
email_validator-2.4.0.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ python-email-validator.spec ++++++
--- /var/tmp/diff_new_pack.CvPa9s/_old 2026-11-23 12:21:44.393509514 +0100
+++ /var/tmp/diff_new_pack.CvPa9s/_new 2026-11-23 12:21:44.395509598 +0100
@@ -1,7 +1,7 @@
#
# spec file for package python-email-validator
#
-# Copyright (c) 2025 SUSE LLC
+# Copyright (c) 2026 SUSE LLC and contributors
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@@ -23,7 +23,7 @@
%endif
%{?sle15_python_module_pythons}
Name: python-email-validator
-Version: 2.3.0
+Version: 2.4.0
Release: 0
Summary: A robust email syntax and deliverability validation library
for Python
License: CC0-1.0
++++++ email_validator-2.3.0.tar.gz -> email_validator-2.4.0.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/python-email-validator-2.3.0/.github/workflows/test_and_build.yaml
new/python-email-validator-2.4.0/.github/workflows/test_and_build.yaml
--- old/python-email-validator-2.3.0/.github/workflows/test_and_build.yaml
2025-08-26 15:03:08.000000000 +0200
+++ new/python-email-validator-2.4.0/.github/workflows/test_and_build.yaml
2026-11-14 21:18:30.000000000 +0100
@@ -7,13 +7,14 @@
runs-on: ubuntu-latest
strategy:
+ fail-fast: false
matrix:
- python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
+ python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.15"]
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v7
- name: Set up Python ${{ matrix.python-version }}
- uses: actions/setup-python@v4
+ uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-email-validator-2.3.0/CHANGELOG.md
new/python-email-validator-2.4.0/CHANGELOG.md
--- old/python-email-validator-2.3.0/CHANGELOG.md 2025-08-26
15:03:08.000000000 +0200
+++ new/python-email-validator-2.4.0/CHANGELOG.md 2026-11-14
21:18:30.000000000 +0100
@@ -1,3 +1,18 @@
+2.4.0 (November 14, 2026)
+-------------------------
+
+* Python 3.8 and 3.9 are no longer supported, and Python 3.14 and 3.15 are
added to testing.
+* The `original` field of the returned validated email object incorrectly
un-escaped the local part of the email address. Now it returns the original
address, without any display name, as passed to validate_email.
+* With `allow_quoted_local=True`, a quoted local part containing U+037E (Greek
question mark), which Unicode NFC normalization changes to a semicolon, was
returned without its quotes in the normalized address (e.g.
`a;[email protected]`), getting around the re-validation added in 2.2.0. The
normalized local part is now quoted according to its normalized form, giving
`"a;b"@example.com`.
+* When parsing display names, multiple closing angle brackets at the end of
the email address is now rejected.
+* The IPv6 tag of a domain literal is now case-insensitive, as in the RFCs, so
`me@[ipv6:::1]` is accepted (and normalized to `me@[IPv6:::1]`) when
`allow_domain_literal=True`.
+* IPv6 domain literals with a zone index are now rejected.
+* Internationalized domains with a right-to-left label are now rejected if any
other label breaks the IDNA Bidi Rule (RFC 5893), such as a label starting with
a digit. Such domains, like `1.xn--4dbc.com` and `xn--4dbc.1.com` (`1.אב.com`
and `אב.1.com` in Unicode), could be displayed identically.
+* Faster validation of domains without Punycode (xn--) labels.
+* Internationalized domains longer than 253 characters are now rejected for
their length before IDNA encoding, which could take time quadratic in the
length of the input.
+* The command line tool now properly reads boolean environment variables and
the DEFAULT_TIMEOUT environment variable.
+* Improvements in type hinting, code comments, and tests.
+
2.3.0 (August 26, 2025)
-----------------------
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-email-validator-2.3.0/Makefile
new/python-email-validator-2.4.0/Makefile
--- old/python-email-validator-2.3.0/Makefile 2025-08-26 15:03:08.000000000
+0200
+++ new/python-email-validator-2.4.0/Makefile 2026-11-14 21:18:30.000000000
+0100
@@ -17,7 +17,7 @@
.PHONY: test
test:
- PYTHONPATH=.:$$PYTHONPATH pytest --cov=email_validator -k "not network"
+ PYTHONPATH=.:$$PYTHONPATH pytest --cov=email_validator -k "not network"
-vv
.PHONY: testcov
testcov: test
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-email-validator-2.3.0/README.md
new/python-email-validator-2.4.0/README.md
--- old/python-email-validator-2.3.0/README.md 2025-08-26 15:03:08.000000000
+0200
+++ new/python-email-validator-2.4.0/README.md 2026-11-14 21:18:30.000000000
+0100
@@ -2,7 +2,7 @@
=========================================
A robust email address syntax and deliverability validation library for
-Python 3.8+ by [Joshua Tauberer](https://joshdata.me).
+Python 3.10+ by [Joshua Tauberer](https://joshdata.me).
This library validates that a string is of the form `[email protected]`
and optionally checks that the domain name is set up to receive email.
@@ -357,7 +357,9 @@
Now `smtputf8` is `True` and `ascii_email` is `None` because the local
part of the address is internationalized. The `local_part` and `normalized`
fields
-return the normalized form of the address.
+return the normalized form of the address. (Because of Unicode normalization,
+it is possible in edge cases for `smtputf8` to be `True` based on the original
+email address when `ascii_email` is also present in the ValidatedEmail.)
Return value
------------
@@ -425,8 +427,7 @@
* Update CHANGELOG.md.
* Update the version number in `email_validator/version.py`.
* Make & push a commit with the new version number and make sure tests pass.
-* Make & push a tag (see command below).
-* Make a release at
https://github.com/JoshData/python-email-validator/releases/new.
+* Make a release at
https://github.com/JoshData/python-email-validator/releases/new creating a new
tag (or use command below).
* Publish a source and wheel distribution to pypi (see command below).
```sh
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/python-email-validator-2.3.0/email_validator/__main__.py
new/python-email-validator-2.4.0/email_validator/__main__.py
--- old/python-email-validator-2.3.0/email_validator/__main__.py
2025-08-26 15:03:08.000000000 +0200
+++ new/python-email-validator-2.4.0/email_validator/__main__.py
2026-11-14 21:18:30.000000000 +0100
@@ -17,7 +17,7 @@
import json
import os
import sys
-from typing import Any, Dict, Optional
+from typing import Any, Optional
from .validate_email import validate_email, _Resolver
from .deliverability import caching_resolver
@@ -28,15 +28,20 @@
# The dns_resolver argument is for tests.
# Set options from environment variables.
- options: Dict[str, Any] = {}
+ options: dict[str, Any] = {}
for varname in ('ALLOW_SMTPUTF8', 'ALLOW_EMPTY_LOCAL',
'ALLOW_QUOTED_LOCAL', 'ALLOW_DOMAIN_LITERAL',
'ALLOW_DISPLAY_NAME',
'GLOBALLY_DELIVERABLE', 'CHECK_DELIVERABILITY',
'TEST_ENVIRONMENT'):
if varname in os.environ:
- options[varname.lower()] = bool(os.environ[varname])
+ # bool() would make any non-empty string True, so e.g.
+ # CHECK_DELIVERABILITY=false would enable the check.
+ options[varname.lower()] = os.environ[varname].strip().lower() not
in ('', '0', 'false', 'no', 'off')
for varname in ('DEFAULT_TIMEOUT',):
if varname in os.environ:
- options[varname.lower()] = float(os.environ[varname])
+ # DEFAULT_TIMEOUT is a module-level default read by
+ # caching_resolver(), not a keyword argument of validate_email.
+ import email_validator
+ email_validator.DEFAULT_TIMEOUT = int(os.environ[varname])
if len(sys.argv) == 1:
# Validate the email addresses passed line-by-line on STDIN.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/python-email-validator-2.3.0/email_validator/deliverability.py
new/python-email-validator-2.4.0/email_validator/deliverability.py
--- old/python-email-validator-2.3.0/email_validator/deliverability.py
2025-08-26 15:03:08.000000000 +0200
+++ new/python-email-validator-2.4.0/email_validator/deliverability.py
2026-11-14 21:18:30.000000000 +0100
@@ -1,4 +1,4 @@
-from typing import Any, List, Optional, Tuple, TypedDict
+from typing import Any, Optional, TypedDict
import ipaddress
@@ -19,7 +19,7 @@
DeliverabilityInfo = TypedDict("DeliverabilityInfo", {
- "mx": List[Tuple[int, str]],
+ "mx": list[tuple[int, str]],
"mx_fallback_type": Optional[str],
"unknown-deliverability": str,
}, total=False)
@@ -66,7 +66,7 @@
deliverability_info["mx_fallback_type"] = None
except dns.resolver.NoAnswer:
- # If there was no MX record, fall back to an A or AAA record
+ # If there was no MX record, fall back to an A or AAAA record
# (RFC 5321 Section 5). Check A first since it's more common.
# If the A/AAAA response has no Globally Reachable IP address,
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/python-email-validator-2.3.0/email_validator/syntax.py
new/python-email-validator-2.4.0/email_validator/syntax.py
--- old/python-email-validator-2.3.0/email_validator/syntax.py 2025-08-26
15:03:08.000000000 +0200
+++ new/python-email-validator-2.4.0/email_validator/syntax.py 2026-11-14
21:18:30.000000000 +0100
@@ -8,12 +8,12 @@
import unicodedata
import idna # implements IDNA 2008; Python's codec is only IDNA 2003
import ipaddress
-from typing import Optional, Tuple, TypedDict, Union
+from typing import Optional, TypedDict
-def split_email(email: str) -> Tuple[Optional[str], str, str, bool]:
- # Return the display name, unescaped local part, and domain part
- # of the address, and whether the local part was quoted. If no
+def split_email(email: str) -> tuple[Optional[str], str, str, bool, str]:
+ # Return the display name, the original local part, the unescaped
+ # local part, and the domain part of the address. If no
# display name was present and angle brackets do not surround
# the address, display name will be None; otherwise, it will be
# set to the display name or the empty string if there were
@@ -36,7 +36,7 @@
#
# Display names are either basic characters (the same basic characters
# permitted in email addresses, but periods are not allowed and spaces
- # are allowed; see RFC 5322 Appendix A.1.2), or or a quoted string with
+ # are allowed; see RFC 5322 Appendix A.1.2), or a quoted string with
# the same rules as a quoted local part. (Multiple quoted strings might
# be allowed? Unclear.) Optional space (RFC 5322 3.4 CFWS) and then the
# email address follows in angle brackets.
@@ -47,7 +47,7 @@
# We assume the input string is already stripped of leading and
# trailing CFWS.
- def split_string_at_unquoted_special(text: str, specials: Tuple[str, ...])
-> Tuple[str, str]:
+ def split_string_at_unquoted_special(text: str, specials: tuple[str, ...])
-> tuple[str, str]:
# Split the string at the first character in specials (an @-sign
# or left angle bracket) that does not occur within quotes and
# is not followed by a Unicode combining character.
@@ -61,7 +61,14 @@
# the < as the start of "<email>" syntax in that case. Likewise,
# if anything combines with an @ or ", we should probably not
# treat it as a special character.
- if unicodedata.normalize("NFC", text[i:])[0] != c:
+ #
+ # Only the characters right after c can combine with it, so
+ # look at a short window rather than normalizing the rest of
+ # the string at every position, which is quadratic in the
+ # length of the input. The window is c, the 30 combining
+ # characters in a row allowed by the Unicode Stream-Safe Text
+ # Format (UAX #15), and one more character.
+ if unicodedata.normalize("NFC", text[i:i + 32])[0] != c:
left_part += c
elif inside_quote:
@@ -112,7 +119,7 @@
return left_part, right_part
- def unquote_quoted_string(text: str) -> Tuple[str, bool]:
+ def unquote_quoted_string(text: str) -> tuple[str, bool]:
# Remove surrounding quotes and unescape escaped backslashes
# and quotes. Escapes are parsed liberally. I think only
# backslashes and quotes can be escaped but we'll allow anything
@@ -178,7 +185,7 @@
raise EmailSyntaxError("There can't be anything after the email
address.")
# Remove the initial and trailing angle brackets.
- addr_spec = right_part[1:].rstrip(">")
+ addr_spec = right_part[1:-1]
# Split the email address at the first unquoted @-sign.
local_part, domain_part = split_string_at_unquoted_special(addr_spec,
("@",))
@@ -193,9 +200,9 @@
domain_part = domain_part[1:]
# Unquote the local part if it is quoted.
- local_part, is_quoted_local_part = unquote_quoted_string(local_part)
+ local_part_unquoted, is_quoted_local_part =
unquote_quoted_string(local_part)
- return display_name, local_part, domain_part, is_quoted_local_part
+ return display_name, local_part, local_part_unquoted,
is_quoted_local_part, domain_part
def get_length_reason(addr: str, limit: int) -> str:
@@ -498,6 +505,14 @@
def validate_email_domain_name(domain: str, test_environment: bool = False,
globally_deliverable: bool = True) -> DomainNameValidationResult:
"""Validates the syntax of the domain part of an email address."""
+ # A domain can get shorter through normalization (either from IDNA
decoding or Unicode normalization),
+ # but the caller may use the original input, so the length check can apply
up front. We also get a
+ # less helpful error via idna.uts46_remap and would rather do it
ourselves. And it's important to
+ # prevent a DOS attack via idna: See below.
+ if len(domain) > DOMAIN_MAX_LENGTH:
+ reason = get_length_reason(domain, limit=DOMAIN_MAX_LENGTH)
+ raise EmailSyntaxError(f"The email address is too long after the
@-sign {reason}.")
+
# Check for invalid characters.
# (RFC 952 plus RFC 6531 section 3.3 for internationalized addresses)
bad_chars = {
@@ -579,6 +594,14 @@
# doesn't give a nice error, so we call the underlying idna.alabel
method
# directly. idna.alabel checks label length and doesn't give great
messages,
# but we can't easily go to lower level methods.
+ #
+ # idna.encode also rejects a domain that is too long before it looks
+ # at any label, because checking or decoding a long label can take time
+ # quadratic in its length (a long Punycode "xn--" label, or, before
idna
+ # 3.15, a long run of Arabic-Indic digits). Since we call idna.alabel
+ # directly, check the length first above. A label never gets shorter
+ # when it is converted to IDNA ASCII, so a domain this long would fail
+ # the length check below anyway.
try:
ascii_domain = ".".join(
idna.alabel(label).decode("ascii")
@@ -644,6 +667,13 @@
if ascii_domain == d or ascii_domain.endswith("." + d):
raise EmailSyntaxError("The part after the @-sign is a special-use
or reserved name that cannot be used with email.")
+ # Domains without Punycode labels come back unchanged from the IDNA round
trip below.
+ if "xn--" not in ascii_domain:
+ return {
+ "ascii_domain": ascii_domain,
+ "domain": ascii_domain,
+ }
+
# We may have been given an IDNA ASCII domain to begin with. Check
# that the domain actually conforms to IDNA. It could look like IDNA
# but not be actual IDNA. For ASCII-only domains, the conversion out
@@ -675,6 +705,20 @@
raise EmailSyntaxError("The part after the @-sign contains invalid
characters: " + ", ".join(sorted(bad_chars)) + ".")
check_unsafe_chars(domain_i18n)
+ # If any label has right-to-left characters, the Bidi Rule applies to
+ # every label in the domain, including left-to-right ones (RFC 5893
+ # Section 1.4 and 2, UTS #46 CheckBidi). The idna package only checks
+ # each label on its own, so a label like "1" next to a right-to-left
+ # label was accepted, and such domains can be displayed identically to
+ # a different domain (e.g. 1.xn--4dbc.com and xn--4dbc.1.com, which
+ # are 1.אב.com and אב.1.com in Unicode, with Hebrew alef bet).
+ if any(unicodedata.bidirectional(c) in ("R", "AL", "AN") for c in
domain_i18n):
+ for label in domain_i18n.split("."):
+ try:
+ idna.check_bidi(label, check_ltr=True)
+ except idna.IDNAError as e:
+ raise EmailSyntaxError(f"The part after the @-sign is not
valid IDNA ({e}).") from e
+
# Check that it can be encoded back to IDNA ASCII. We have no test
# case for this.
try:
@@ -758,7 +802,7 @@
class DomainLiteralValidationResult(TypedDict):
- domain_address: Union[ipaddress.IPv4Address, ipaddress.IPv6Address]
+ domain_address: ipaddress.IPv4Address | ipaddress.IPv6Address
domain: str
@@ -767,7 +811,7 @@
# a compressed/normalized address.
# RFC 5321 4.1.3 and RFC 5322 3.4.1.
- addr: Union[ipaddress.IPv4Address, ipaddress.IPv6Address]
+ addr: ipaddress.IPv4Address | ipaddress.IPv6Address
# Try to parse the domain literal as an IPv4 address.
# There is no tag for IPv4 addresses, so we can never
@@ -784,13 +828,18 @@
"domain": f"[{addr}]",
}
- # If it begins with "IPv6:" it's an IPv6 address.
- if domain_literal.startswith("IPv6:"):
+ # If it begins with "IPv6:" it's an IPv6 address. The tag is
case-insensitive
+ # like all ABNF literal strings (RFC 5234 2.3), so "ipv6:" is accepted too.
+ if domain_literal[:5].lower() == "ipv6:":
try:
addr = ipaddress.IPv6Address(domain_literal[5:])
except ValueError as e:
raise EmailSyntaxError(f"The IPv6 address in brackets after the
@-sign is not valid ({e}).") from e
+ # Python accepts a zone index ("%eth0") but RFC 5321 4.1.3 does not.
+ if addr.scope_id is not None:
+ raise EmailSyntaxError("The IPv6 address in brackets after the
@-sign is not valid (It has a zone index).")
+
# Return the IPv6Address object and construct a normalized
# domain literal.
return {
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/python-email-validator-2.3.0/email_validator/types.py
new/python-email-validator-2.4.0/email_validator/types.py
--- old/python-email-validator-2.3.0/email_validator/types.py 2025-08-26
15:03:08.000000000 +0200
+++ new/python-email-validator-2.4.0/email_validator/types.py 2026-11-14
21:18:30.000000000 +0100
@@ -1,5 +1,5 @@
import warnings
-from typing import Any, Dict, List, Optional, Tuple, Union
+from typing import Any, Optional
class ValidatedEmail:
@@ -41,7 +41,7 @@
"""If a deliverability check is performed and if it succeeds, a list of
(priority, domain)
tuples of MX records specified in the DNS for the domain."""
- mx: List[Tuple[int, str]]
+ mx: list[tuple[int, str]]
"""If no MX records are actually specified in DNS and instead are
inferred, through an obsolete
mechanism, from A or AAAA records, the value is the type of DNS record
used instead (`A` or `AAAA`)."""
@@ -68,7 +68,7 @@
"""For backwards compatibility, some fields are also exposed through a
dict-like interface. Note
that some of the names changed when they became attributes."""
- def __getitem__(self, key: str) -> Union[Optional[str], bool,
List[Tuple[int, str]]]:
+ def __getitem__(self, key: str) -> Optional[str] | bool | list[tuple[int,
str]]:
warnings.warn("dict-like access to the return value of validate_email
is deprecated and may not be supported in the future.", DeprecationWarning,
stacklevel=2)
if key == "email":
return self.normalized
@@ -93,7 +93,8 @@
if not isinstance(other, ValidatedEmail):
return False
return (
- self.normalized == other.normalized
+ getattr(self, 'original', None) == getattr(other, 'original', None)
+ and self.normalized == other.normalized
and self.local_part == other.local_part
and self.domain == other.domain
and getattr(self, 'ascii_email', None) == getattr(other,
'ascii_email', None)
@@ -110,7 +111,7 @@
def as_constructor(self) -> str:
return "ValidatedEmail(" \
+ ",".join(f"\n {key}={repr(getattr(self, key))}"
- for key in ('normalized', 'local_part', 'domain',
+ for key in ('original', 'normalized', 'local_part',
'domain',
'ascii_email', 'ascii_local_part',
'ascii_domain',
'smtputf8', 'mx', 'mx_fallback_type',
'display_name')
@@ -119,8 +120,8 @@
+ ")"
"""Convenience method for accessing ValidatedEmail as a dict"""
- def as_dict(self) -> Dict[str, Any]:
- d = self.__dict__
+ def as_dict(self) -> dict[str, Any]:
+ d = dict(self.__dict__)
if d.get('domain_address'):
d['domain_address'] = repr(d['domain_address'])
return d
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/python-email-validator-2.3.0/email_validator/validate_email.py
new/python-email-validator-2.4.0/email_validator/validate_email.py
--- old/python-email-validator-2.3.0/email_validator/validate_email.py
2025-08-26 15:03:08.000000000 +0200
+++ new/python-email-validator-2.4.0/email_validator/validate_email.py
2026-11-14 21:18:30.000000000 +0100
@@ -1,4 +1,4 @@
-from typing import Optional, Union, TYPE_CHECKING
+from typing import Optional, TYPE_CHECKING
import unicodedata
from .exceptions import EmailSyntaxError
@@ -14,7 +14,7 @@
def validate_email(
- email: Union[str, bytes],
+ email: str | bytes,
/, # prior arguments are positional-only
*, # subsequent arguments are keyword-only
allow_smtputf8: Optional[bool] = None,
@@ -77,7 +77,7 @@
# Normally, there is only one @-sign. But the awkward "quoted string"
# local part form (RFC 5321 4.1.2) allows @-signs in the local
# part if the local part is quoted.
- display_name, local_part, domain_part, is_quoted_local_part \
+ display_name, original_local_part, unescaped_local_part,
is_quoted_local_part, domain_part \
= split_email(email)
if display_name:
@@ -90,22 +90,21 @@
# Collect return values in this instance.
ret = ValidatedEmail()
- ret.original = ((local_part if not is_quoted_local_part
- else ('"' + local_part + '"'))
- + "@" + domain_part) # drop the display name, if any, for
email length tests at the end
+ ret.original = original_local_part + "@" + domain_part # drop the display
name, if any, for email length tests at the end
ret.display_name = display_name
# Validate the email address's local part syntax and get a normalized form.
# If the original address was quoted and the decoded local part is a valid
# unquoted local part, then we'll get back a normalized (unescaped) local
# part.
- local_part_info = validate_email_local_part(local_part,
+ local_part_info = validate_email_local_part(unescaped_local_part,
allow_smtputf8=allow_smtputf8,
allow_empty_local=allow_empty_local,
quoted_local_part=is_quoted_local_part,
strict=strict)
- ret.local_part = local_part_info["local_part"]
- ret.ascii_local_part = local_part_info["ascii_local_part"]
+
+ # Report whether SMTPUTF8 is required for the address as given, prior to
+ # Unicode normalization next.
ret.smtputf8 = local_part_info["smtputf8"]
# RFC 6532 section 3.1 says that Unicode NFC normalization should be
applied,
@@ -120,17 +119,24 @@
# this library. (UTS #39 seems to require that the *input* be NKFC
normalized
# and has other requirements that are hard to check without additional
Unicode
# data, and I don't know whether the rules really apply in the wild.)
- normalized_local_part = unicodedata.normalize("NFC", ret.local_part)
- if normalized_local_part != ret.local_part:
+ #
+ # Normalize the unquoted and unescaped local part, not ret.local_part, and
+ # take the quoting from the second validation. ret.local_part has already
+ # had unnecessary quotes removed, so normalizing it would turn e.g.
+ # "a\u037eb" (quoted, with a Greek question mark) into a;b without quotes.
+ normalized_local_part = unicodedata.normalize("NFC", unescaped_local_part)
+ if normalized_local_part != unescaped_local_part:
try:
- validate_email_local_part(normalized_local_part,
- allow_smtputf8=allow_smtputf8,
- allow_empty_local=allow_empty_local,
- quoted_local_part=is_quoted_local_part,
- strict=strict)
+ local_part_info = validate_email_local_part(normalized_local_part,
+
allow_smtputf8=allow_smtputf8,
+
allow_empty_local=allow_empty_local,
+
quoted_local_part=is_quoted_local_part,
+ strict=strict)
except EmailSyntaxError as e:
raise EmailSyntaxError("After Unicode normalization: " + str(e))
from e
- ret.local_part = normalized_local_part
+
+ ret.local_part = local_part_info["local_part"]
+ ret.ascii_local_part = local_part_info["ascii_local_part"]
# If a quoted local part isn't allowed but is present, now raise an
exception.
# This is done after any exceptions raised by validate_email_local_part so
@@ -173,9 +179,7 @@
ret.normalized = ret.local_part + "@" + ret.domain
# If the email address has an ASCII form, add it.
- if not ret.smtputf8:
- if not ret.ascii_domain:
- raise Exception("Missing ASCII domain.")
+ if ret.ascii_local_part and ret.ascii_domain:
ret.ascii_email = (ret.ascii_local_part or "") + "@" + ret.ascii_domain
else:
ret.ascii_email = None
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/python-email-validator-2.3.0/email_validator/version.py
new/python-email-validator-2.4.0/email_validator/version.py
--- old/python-email-validator-2.3.0/email_validator/version.py 2025-08-26
15:03:08.000000000 +0200
+++ new/python-email-validator-2.4.0/email_validator/version.py 2026-11-14
21:18:30.000000000 +0100
@@ -1 +1 @@
-__version__ = "2.3.0"
+__version__ = "2.4.0"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-email-validator-2.3.0/release_to_pypi.sh
new/python-email-validator-2.4.0/release_to_pypi.sh
--- old/python-email-validator-2.3.0/release_to_pypi.sh 2025-08-26
15:03:08.000000000 +0200
+++ new/python-email-validator-2.4.0/release_to_pypi.sh 2026-11-14
21:18:30.000000000 +0100
@@ -1,5 +1,5 @@
#!/bin/bash
-source env/bin/activate
+source venv/bin/activate
pip3 install --upgrade build twine
rm -rf dist
python3 -m build
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-email-validator-2.3.0/setup.cfg
new/python-email-validator-2.4.0/setup.cfg
--- old/python-email-validator-2.3.0/setup.cfg 2025-08-26 15:03:08.000000000
+0200
+++ new/python-email-validator-2.4.0/setup.cfg 2026-11-14 21:18:30.000000000
+0100
@@ -14,11 +14,12 @@
Intended Audience :: Developers
License :: OSI Approved :: The Unlicense (Unlicense)
Programming Language :: Python :: 3
- Programming Language :: Python :: 3.8
- Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
+ Programming Language :: Python :: 3.13
+ Programming Language :: Python :: 3.14
+ Programming Language :: Python :: 3.15
Topic :: Software Development :: Libraries :: Python Modules
keywords = email address validator
@@ -27,7 +28,7 @@
install_requires =
dnspython>=2.0.0 # optional if deliverability check isn't needed
idna>=2.0.0
-python_requires = >=3.8
+python_requires = >=3.10
[options.package_data]
* = py.typed
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-email-validator-2.3.0/test_requirements.txt
new/python-email-validator-2.4.0/test_requirements.txt
--- old/python-email-validator-2.3.0/test_requirements.txt 2025-08-26
15:03:08.000000000 +0200
+++ new/python-email-validator-2.4.0/test_requirements.txt 2026-11-14
21:18:30.000000000 +0100
@@ -1,5 +1,11 @@
-# This file was generated by running:
-# sudo docker run --rm -it --network=host python:3.8-slim /bin/bash
+# Install packages from setup.cfg using the latest available version
+# so we're notified if something breaks with the latest version.
+idna
+dnspython
+# For the packages require for tests, use pinned versions to ensure
+# builds are mostly reproducible. The rest of this file was generated
+# by running:
+# sudo docker run --rm -it --network=host python:3.10-slim /bin/bash
# pip install dnspython idna # from setup.cfg
# pip install pytest pytest-cov coverage flake8 mypy
# pip freeze
@@ -7,20 +13,21 @@
# the earliest Python version we support, and some exception
# messages may depend on package versions, so we pin versions
# for reproducible testing.)
-coverage==7.5.3
-dnspython==2.6.1
-exceptiongroup==1.2.1
-flake8==7.1.0
-idna==3.7
-iniconfig==2.0.0
+coverage==7.13.5
+exceptiongroup==1.3.1
+flake8==7.3.0
+iniconfig==2.3.0
+librt==0.9.0
mccabe==0.7.0
-mypy==1.10.0
-mypy-extensions==1.0.0
-packaging==24.1
-pluggy==1.5.0
-pycodestyle==2.12.0
-pyflakes==3.2.0
-pytest==8.2.2
-pytest-cov==5.0.0
-tomli==2.0.1
-typing_extensions==4.12.2
+mypy==1.20.1
+mypy_extensions==1.1.0
+packaging==26.0
+pathspec==1.0.4
+pluggy==1.6.0
+pycodestyle==2.14.0
+pyflakes==3.4.0
+Pygments==2.20.0
+pytest==9.0.3
+pytest-cov==7.1.0
+tomli==2.4.1
+typing_extensions==4.15.0
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-email-validator-2.3.0/tests/conftest.py
new/python-email-validator-2.4.0/tests/conftest.py
--- old/python-email-validator-2.3.0/tests/conftest.py 1970-01-01
01:00:00.000000000 +0100
+++ new/python-email-validator-2.4.0/tests/conftest.py 2026-11-14
21:18:30.000000000 +0100
@@ -0,0 +1,21 @@
+
+from typing import Any
+
+from email_validator import ValidatedEmail
+
+
+def pytest_assertrepr_compare(config: Any, op: str, left: Any, right: Any) ->
list[str] | None:
+ if isinstance(left, ValidatedEmail) and isinstance(right, ValidatedEmail)
and op == "==":
+ leftDict = left.as_dict()
+ rightDict = right.as_dict()
+ keys = set(leftDict) | set(rightDict)
+ table = [[key, leftDict.get(key), rightDict.get(key)]
+ for key in keys]
+ maxLen = [max(len(repr(row[col])) for row in table) for col in (0, 1,
2)]
+ return ([repr(left) + " != " + repr(right)]
+ + [(str(t[0]).rjust(maxLen[0])
+ + " " + repr(t[1]).ljust(maxLen[1])
+ + (" ==" if t[1] == t[2] else " !=")
+ + " " + repr(t[2]).ljust(maxLen[2]))
+ for t in table])
+ return None
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/python-email-validator-2.3.0/tests/mocked-dns-answers.json
new/python-email-validator-2.4.0/tests/mocked-dns-answers.json
--- old/python-email-validator-2.3.0/tests/mocked-dns-answers.json
2025-08-26 15:03:08.000000000 +0200
+++ new/python-email-validator-2.4.0/tests/mocked-dns-answers.json
2026-11-14 21:18:30.000000000 +0100
@@ -129,7 +129,7 @@
"type": "A",
"class": "IN"
},
- "answer": []
+ "answer": ["127.0.0.1"]
},
{
"query": {
@@ -141,6 +141,30 @@
},
{
"query": {
+ "name": "ipv6only.joshdata.me",
+ "type": "MX",
+ "class": "IN"
+ },
+ "answer": []
+ },
+ {
+ "query": {
+ "name": "ipv6only.joshdata.me",
+ "type": "A",
+ "class": "IN"
+ },
+ "answer": []
+ },
+ {
+ "query": {
+ "name": "ipv6only.joshdata.me",
+ "type": "AAAA",
+ "class": "IN"
+ },
+ "answer": ["::1"]
+ },
+ {
+ "query": {
"name": "mail.example",
"type": "ANY",
"class": "IN"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/python-email-validator-2.3.0/tests/mocked_dns_response.py
new/python-email-validator-2.4.0/tests/mocked_dns_response.py
--- old/python-email-validator-2.3.0/tests/mocked_dns_response.py
2025-08-26 15:03:08.000000000 +0200
+++ new/python-email-validator-2.4.0/tests/mocked_dns_response.py
2026-11-14 21:18:30.000000000 +0100
@@ -1,4 +1,4 @@
-from typing import Any, Dict, Iterator, Optional
+from typing import Any, Iterator, Optional
import dns.exception
import dns.rdataset
@@ -42,7 +42,7 @@
return caching_resolver(cache=MockedDnsResponseData.INSTANCE,
dns_resolver=dns_resolver)
def __init__(self) -> None:
- self.data: Dict[dns.resolver.CacheKey,
Optional[MockedDnsResponseData.Ans]] = {}
+ self.data: dict[dns.resolver.CacheKey,
Optional[MockedDnsResponseData.Ans]] = {}
# Loads the saved DNS response data from the JSON file and
# re-structures it into dnspython classes.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/python-email-validator-2.3.0/tests/test_deliverability.py
new/python-email-validator-2.4.0/tests/test_deliverability.py
--- old/python-email-validator-2.3.0/tests/test_deliverability.py
2025-08-26 15:03:08.000000000 +0200
+++ new/python-email-validator-2.4.0/tests/test_deliverability.py
2026-11-14 21:18:30.000000000 +0100
@@ -1,4 +1,4 @@
-from typing import Any, Dict
+from typing import Any
import pytest
import re
@@ -35,6 +35,7 @@
# No MX or A/AAAA records, but some other DNS records must
# exist such that the response is NOANSWER instead of NXDOMAIN.
('justtxt.joshdata.me', 'The domain name {domain} does not accept
email'),
+ ('ipv6only.joshdata.me', 'The domain name {domain} does not accept
email'),
],
)
def test_deliverability_fails(domain: str, error: str) -> None:
@@ -65,11 +66,16 @@
assert response.get("unknown-deliverability") == "timeout"
+def test_timeout_and_resolver() -> None:
+ with pytest.raises(ValueError, match="It's not valid to pass both timeout
and dns_resolver."):
+ validate_email_deliverability('timeout.com', 'timeout.com', timeout=1,
dns_resolver=RESOLVER)
+
+
@pytest.mark.network
def test_caching_dns_resolver() -> None:
class TestCache:
def __init__(self) -> None:
- self.cache: Dict[Any, Any] = {}
+ self.cache: dict[Any, Any] = {}
def get(self, key: Any) -> Any:
return self.cache.get(key)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-email-validator-2.3.0/tests/test_main.py
new/python-email-validator-2.4.0/tests/test_main.py
--- old/python-email-validator-2.3.0/tests/test_main.py 2025-08-26
15:03:08.000000000 +0200
+++ new/python-email-validator-2.4.0/tests/test_main.py 2026-11-14
21:18:30.000000000 +0100
@@ -1,3 +1,5 @@
+import ipaddress
+import typing
import pytest
from email_validator import validate_email, EmailSyntaxError
@@ -16,6 +18,36 @@
assert valid_email.as_dict()["original"] == input_email
+def test_dict_accessor_with_domain_address() -> None:
+ input_email = "me@[127.0.0.1]"
+ valid_email = validate_email(input_email, check_deliverability=False,
allow_domain_literal=True)
+ assert valid_email.domain == "[127.0.0.1]"
+ as_dict = valid_email.as_dict()
+ assert isinstance(as_dict, dict)
+ assert as_dict["domain_address"] == "IPv4Address('127.0.0.1')"
+
+
+def test_dict_accessor_does_not_modify_validated_email() -> None:
+ # as_dict() is only for reading: it must not replace the attributes of the
+ # object it is called on. The domain_address attribute is documented to
hold
+ # the ipaddress.IPv4Address object.
+ input_email = "me@[127.0.0.1]"
+ valid_email = validate_email(input_email, check_deliverability=False,
allow_domain_literal=True)
+ domain_address = valid_email.domain_address
+ assert isinstance(domain_address, ipaddress.IPv4Address)
+
+ first_dict = valid_email.as_dict()
+ assert first_dict["domain_address"] == "IPv4Address('127.0.0.1')"
+
+ # The object the dict was made from is unchanged, ...
+ assert valid_email.domain_address is domain_address
+ assert isinstance(valid_email.domain_address, ipaddress.IPv4Address)
+
+ # ... and asking for the dict again gives the same result rather than
+ # repr() of a string.
+ assert valid_email.as_dict() == first_dict
+
+
def test_main_single_good_input(monkeypatch: pytest.MonkeyPatch, capsys:
pytest.CaptureFixture[str]) -> None:
import json
test_email = "[email protected]"
@@ -49,6 +81,43 @@
assert test_cases[3] in stdout
[email protected]('value', ['false', 'False', 'FALSE', '0', 'no',
'off', ' '])
+def test_main_falsy_boolean_option_from_env(monkeypatch: pytest.MonkeyPatch,
capsys: pytest.CaptureFixture[str], value: str) -> None:
+ # Options are set from environment variables of the same name in upper
+ # case. A falsy value there must turn the option off, not on.
+ import json
+ test_email = '[email protected]' # this domain does not
exist in DNS
+ monkeypatch.setenv('CHECK_DELIVERABILITY', value)
+ monkeypatch.setattr('sys.argv', ['email_validator', test_email])
+ validator_command_line_tool(dns_resolver=RESOLVER)
+ stdout, _ = capsys.readouterr()
+ assert json.loads(str(stdout))["normalized"] == test_email
+
+
[email protected]('value', ['false', 'False', '0', 'no', 'off', ' '])
+def test_main_falsy_test_environment_from_env(monkeypatch: pytest.MonkeyPatch,
capsys: pytest.CaptureFixture[str], value: str) -> None:
+ # test_environment off means the reserved "test" domain names are rejected.
+ monkeypatch.setenv('TEST_ENVIRONMENT', value)
+ monkeypatch.setattr('sys.argv', ['email_validator', '[email protected]'])
+ validator_command_line_tool(dns_resolver=RESOLVER)
+ stdout, _ = capsys.readouterr()
+ assert stdout == 'The part after the @-sign is a special-use or reserved
name that cannot be used with email.\n'
+
+
+def test_main_default_timeout_from_env(monkeypatch: pytest.MonkeyPatch,
capsys: pytest.CaptureFixture[str]) -> None:
+ import json
+ import email_validator
+ test_email = '[email protected]'
+ # Set up the restore of the module-level default, which main() overwrites.
+ monkeypatch.setattr('email_validator.DEFAULT_TIMEOUT',
email_validator.DEFAULT_TIMEOUT)
+ monkeypatch.setenv('DEFAULT_TIMEOUT', '5')
+ monkeypatch.setattr('sys.argv', ['email_validator', test_email])
+ validator_command_line_tool(dns_resolver=RESOLVER)
+ stdout, _ = capsys.readouterr()
+ assert json.loads(str(stdout))["normalized"] == test_email
+ assert email_validator.DEFAULT_TIMEOUT == 5
+
+
def test_bytes_input() -> None:
input_email = b"[email protected]"
valid_email = validate_email(input_email, check_deliverability=False)
@@ -65,3 +134,21 @@
valid_email = validate_email(input_email, check_deliverability=False)
with pytest.deprecated_call():
assert valid_email.email is not None
+
+
[email protected]('invalid_email', [
+ None,
+ 12345,
+ [],
+ {},
+ lambda x: x,
+])
+def test_invalid_type(invalid_email: typing.Any) -> None:
+ with pytest.raises(TypeError, match="email must be str or bytes"):
+ validate_email(invalid_email, check_deliverability=False)
+
+
+def test_invalid_ascii() -> None:
+ invalid_email =
b'\xd0\xba\xd0\xb2\xd1\x96\xd1\x82\xd0\xbe\xd1\x87\xd0\xba\xd0\xb0@\xd0\xbf\xd0\xbe\xd1\x88\xd1\x82\xd0\xb0.test'
+ with pytest.raises(EmailSyntaxError, match="The email address is not valid
ASCII."):
+ validate_email(invalid_email, check_deliverability=False)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-email-validator-2.3.0/tests/test_syntax.py
new/python-email-validator-2.4.0/tests/test_syntax.py
--- old/python-email-validator-2.3.0/tests/test_syntax.py 2025-08-26
15:03:08.000000000 +0200
+++ new/python-email-validator-2.4.0/tests/test_syntax.py 2026-11-14
21:18:30.000000000 +0100
@@ -1,3 +1,4 @@
+import time
from typing import Any
import pytest
@@ -102,8 +103,33 @@
),
),
(
+ '"unnecessary.escaped.\\x.local.part"@example.org',
+ MakeValidatedEmail(
+ local_part='unnecessary.escaped.x.local.part',
+ ascii_local_part='unnecessary.escaped.x.local.part',
+ smtputf8=False,
+ ascii_domain='example.org',
+ domain='example.org',
+ normalized='[email protected]',
+ ascii_email='[email protected]'
+ ),
+ ),
+ (
+ '"escaped.quote.\\".local.part"@example.org',
+ MakeValidatedEmail(
+ local_part='"escaped.quote.\\".local.part"',
+ ascii_local_part='"escaped.quote.\\".local.part"',
+ smtputf8=False,
+ ascii_domain='example.org',
+ domain='example.org',
+ normalized='"escaped.quote.\\".local.part"@example.org',
+ ascii_email='"escaped.quote.\\".local.part"@example.org'
+ ),
+ ),
+ (
'MyName <[email protected]>',
MakeValidatedEmail(
+ original='[email protected]',
local_part='me',
ascii_local_part='me',
smtputf8=False,
@@ -117,6 +143,7 @@
(
'My Name <[email protected]>',
MakeValidatedEmail(
+ original='[email protected]',
local_part='me',
ascii_local_part='me',
smtputf8=False,
@@ -130,6 +157,7 @@
(
r'"My.\"Na\\me\".Is" <"me \" \\ me"@example.org>',
MakeValidatedEmail(
+ original=r'"me \" \\ me"@example.org',
local_part=r'"me \" \\ me"',
ascii_local_part=r'"me \" \\ me"',
smtputf8=False,
@@ -140,9 +168,26 @@
display_name='My."Na\\me".Is'
),
),
+ (
+ 'me@גבריאל.xn--4dbrk0ce.il',
+ MakeValidatedEmail(
+ local_part='me',
+ ascii_local_part='me',
+ smtputf8=False,
+ ascii_domain='xn--4dbbc3aq3e.xn--4dbrk0ce.il',
+ ascii_email='[email protected]',
+ domain='גבריאל.ישראל.il',
+ normalized='me@גבריאל.ישראל.il',
+ ),
+ ),
],
)
def test_email_valid(email_input: str, output: ValidatedEmail) -> None:
+ # Simplfiy hard-coded expected values above by filling
+ # in 'original' when it isn't set.
+ if not hasattr(output, 'original'):
+ output.original = email_input
+
# These addresses do not require SMTPUTF8. See
test_email_valid_intl_local_part
# for addresses that are valid but require SMTPUTF8. Check that it passes
with
# allow_smtput8 both on and off.
@@ -297,6 +342,7 @@
(
'\"s\u0323\u0307\" <s\u0323\[email protected]>',
MakeValidatedEmail(
+ original='s\u0323\[email protected]',
local_part='\u1E69',
smtputf8=True,
ascii_domain='nfc.tld',
@@ -315,9 +361,26 @@
normalized='@@fullwidth.at',
),
),
+ (
+ '\[email protected]',
+ MakeValidatedEmail(
+ local_part='`',
+ ascii_local_part='`',
+ smtputf8=True,
+ ascii_domain='example.com',
+ ascii_email='`@example.com',
+ domain='example.com',
+ normalized='`@example.com',
+ ),
+ ),
],
)
def test_email_valid_intl_local_part(email_input: str, output: ValidatedEmail)
-> None:
+ # Simplfiy hard-coded expected values above by filling
+ # in 'original' when it isn't set.
+ if not hasattr(output, 'original'):
+ output.original = email_input
+
# Check that it passes when allow_smtputf8 is True.
assert validate_email(email_input, check_deliverability=False,
allow_display_name=True) == output
@@ -338,6 +401,8 @@
('"unnecessarily.quoted.with.unicode.λ"@example.com',
'unnecessarily.quoted.with.unicode.λ'),
('"quoted.with..unicode.λ"@example.com', '"quoted.with..unicode.λ"'),
('"quoted.with.extraneous.\\escape"@example.com',
'quoted.with.extraneous.escape'),
+ # U+037E (Greek question mark) is valid unquoted but NFC normalizes to
a semicolon, which needs the quotes.
+ ('"quoted.after.normalization.\u037e"@example.com',
'"quoted.after.normalization.;"'),
])
def test_email_valid_only_if_quoted_local_part(email_input: str,
normalized_local_part: str) -> None:
# These addresses are invalid with the default allow_quoted_local=False
option.
@@ -352,6 +417,12 @@
# and even the quoting if they weren't necessary.
assert validated.local_part == normalized_local_part
+ # If the normalized address is ASCII-only, check that it's reported in
ascii_local_part.
+ if normalized_local_part.isascii():
+ assert validated.ascii_local_part == normalized_local_part
+ else:
+ assert not validated.ascii_local_part
+
def test_domain_literal() -> None:
# Check parsing IPv4 addresses.
@@ -369,6 +440,22 @@
assert validated.domain == "[IPv6:::1]"
assert repr(validated.domain_address) == "IPv6Address('::1')"
+ # Check that the IPv6 tag is case-insensitive and normalized.
+ for email_input in ("me@[ipv6:::1]", "me@[IPV6:::1]"):
+ validated = validate_email(email_input, allow_domain_literal=True)
+ assert validated.domain == "[IPv6:::1]"
+ assert repr(validated.domain_address) == "IPv6Address('::1')"
+
+ # Check that an IPv4 address in an IPv6 address is accepted.
+ validated = validate_email("me@[IPv6:::ffff:1.2.3.4]",
allow_domain_literal=True)
+ assert validated.domain == "[IPv6:::ffff:1.2.3.4]"
+
+ # Check that IPv6 zone indexes are rejected.
+ for email_input in ("me@[IPv6:fe80::1%eth0]", "me@[IPv6:::1%]]"):
+ with pytest.raises(EmailSyntaxError) as exc_info:
+ validate_email(email_input, allow_domain_literal=True)
+ assert str(exc_info.value) == "The IPv6 address in brackets after the
@-sign is not valid (It has a zone index)."
+
@pytest.mark.parametrize(
'email_input,error_msg',
@@ -424,7 +511,7 @@
('m...@1111111111222222222233333333334444444444555555555.6666666666777777777788888888889999999999000000000.1111111111222222222233333333334444444444555555555.6666666666777777777788888888889999999999000000000.1111111111222222222233333333334444444444555555555.com',
'The email address is too long (4 characters too many).'),
('my.long.addr...@1111111111222222222233333333334444444444555555555.6666666666777777777788888888889999999999000000000.1111111111222222222233333333334444444444555555555.6666666666777777777788888888889999999999000000000.11111111112222222222333333333344444.info',
'The email address is too long (2 characters too many).'),
('my.long.address@λ111111111222222222233333333334444444444555555555.6666666666777777777788888888889999999999000000000.1111111111222222222233333333334444444444555555555.6666666666777777777788888888889999999999000000000.1111111111222222222233333333334444.info',
'The email address is too long (1-2 characters too many).'),
-
('my.long.address@\uFB2C111111111222222222233333333334444444444555555555.6666666666777777777788888888889999999999000000000.1111111111222222222233333333334444444444555555555.6666666666777777777788888888889999999999000000000.1111111111222222222233333333334444.info',
'The email address is too long (1-3 characters too many).'),
+
('my.long.address@\uFB2C111111111222222222233333333334444444444555555555.a666666666777777777788888888889999999999000000000.a111111111222222222233333333334444444444555555555.a666666666777777777788888888889999999999000000000.a111111111222222222233333333334444.info',
'The email address is too long (1-3 characters too many).'),
('my.λong.addr...@1111111111222222222233333333334444444444555555555.6666666666777777777788888888889999999999000000000.1111111111222222222233333333334444444444555555555.6666666666777777777788888888889999999999000000000.111111111122222222223333333333444.info',
'The email address is too long (1 character too many).'),
('my.λong.addr...@1111111111222222222233333333334444444444555555555.6666666666777777777788888888889999999999000000000.1111111111222222222233333333334444444444555555555.6666666666777777777788888888889999999999000000000.1111111111222222222233333333334444.info',
'The email address is too long (1-2 characters too many).'),
('my.\u0073\u0323\u0307.addr...@1111111111222222222233333333334444444444555555555.6666666666777777777788888888889999999999000000000.1111111111222222222233333333334444444444555555555.6666666666777777777788888888889999999999000000000.1111111111222222222233333333334444.info',
'The email address is too long (1-2 characters too many).'),
@@ -435,6 +522,11 @@
('me@bad-tld-1', 'The part after the @-sign is not valid. It should
have a period.'),
('[email protected]', 'The part after the @-sign is not valid. It is not
within a valid top-level domain.'),
('[email protected]', 'The part after the @-sign is not valid IDNA
(Invalid A-label).'),
+ # 1.xn--4dbc.com is 1.אב.com and xn--4dbc.1.com is אב.1.com
+ # (alef bet in Hebrew). Both display as the same string, so both are
rejected.
+ ('[email protected]', 'The part after the @-sign is not valid IDNA
(First codepoint in label \'1\' must be directionality L, R or AL).'),
+ ('[email protected]', 'The part after the @-sign is not valid IDNA
(First codepoint in label \'1\' must be directionality L, R or AL).'),
+ ('[email protected]', 'The part after the @-sign is not valid IDNA
(First codepoint in label \'1\' must be directionality L, R or AL).'),
('[email protected]', 'An email address cannot have two letters followed
by two dashes immediately after the @-sign or after a period, except
Punycode.'),
('me@yy--0.tld', 'An email address cannot have two letters followed by
two dashes immediately after the @-sign or after a period, except Punycode.'),
('me@[127.0.0.1]', 'A bracketed IP address after the @-sign is not
allowed here.'),
@@ -448,6 +540,7 @@
('<[email protected]', 'An open angle bracket at the start of the email
address has to be followed by a close angle bracket at the end.'),
('<[email protected]> !', 'There can\'t be anything after the email
address.'),
('<\[email protected]', 'The email address contains invalid
characters before the @-sign: \'<\'.'),
+ ('<\u0301\[email protected]', 'The email address contains invalid
characters before the @-sign: \'<\'.'),
('DisplayName <[email protected]>', 'An email address cannot have a
hyphen immediately after the @-sign.'),
('DisplayName <[email protected]>', 'A display name and angle brackets
around the email address are not permitted here.'),
('Display Name <[email protected]>', 'A display name and angle brackets
around the email address are not permitted here.'),
@@ -464,6 +557,28 @@
assert str(exc_info.value) == error_msg
+def test_email_long_input_is_not_quadratic() -> None:
+ # split_email used to NFC-normalize the rest of the string at every
+ # character, so rejecting this took about 15 seconds.
+ start = time.perf_counter()
+ with pytest.raises(EmailSyntaxError, match="unsafe characters"):
+ validate_email("\u0301" * 50000 + "@example.com",
check_deliverability=False)
+ assert time.perf_counter() - start < 2
+
+
+def test_email_long_idna_domain_is_not_quadratic() -> None:
+ # Internationalized domains went to idna.alabel without the up-front
+ # length check idna.encode does. idna.ulabel Punycode-decodes the whole
+ # "xn--" label first, so rejecting the first address took about 5 seconds,
+ # and before idna 3.15 the Arabic-Indic digits in the second took about 35.
+ for email in ("me@\u00e9.xn--" + "9" * 200000 + ".com",
+ "me@" + "\u0660" * 40000 + ".com"):
+ start = time.perf_counter()
+ with pytest.raises(EmailSyntaxError, match="too long after the
@-sign"):
+ validate_email(email, check_deliverability=False)
+ assert time.perf_counter() - start < 2
+
+
@pytest.mark.parametrize(
'email_input,error_msg',
[
@@ -481,6 +596,20 @@
@pytest.mark.parametrize(
+ 'email_input',
+ [
+ '<[email protected]>>',
+ 'Display Name <[email protected]>>',
+ 'Display Name <[email protected]>>>',
+ ])
+def test_email_invalid_syntax_display_name(email_input: str) -> None:
+ # Only one close angle bracket may follow the address.
+ with pytest.raises(EmailSyntaxError) as exc_info:
+ validate_email(email_input, check_deliverability=False,
allow_display_name=True)
+ assert str(exc_info.value) == "The part after the @-sign contains invalid
characters: '>'."
+
+
[email protected](
'email_input',
[
('[email protected]'),