You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,7 @@ There are no significant changes to which email addresses are considered valid/i
11
11
* Some syntax error messages have changed because they are now checked explicitly rather than as a part of other checks.
12
12
* The quoted-string local part syntax (e.g. multiple @-signs, spaces, etc. if surrounded by quotes) and domain-literal addresses (e.g. @[192.XXX...] or @[IPv6:...]) are now parsed but not considered valid by default. Better error messages are now given for these addresses since it can be confusing for a technically valid address to be rejected, and new allow_quoted_local and allow_domain_literal options are added to allow these addresses if you really need them.
13
13
* Some other error messages have changed to not repeat the email address in the error message.
14
+
* The `email` field on the returned `ValidatedEmail` object has been renamed to `normalized` to be clearer about its importance, but access via `.email` is also still supported.
14
15
* The library has been reorganized internally into smaller modules.
15
16
* The tests have been reorganized and expanded. Deliverability tests now mostly use captured DNS responses so they can be run off-line.
16
17
* The __main__ tool now reads options to validate_email from environment variables.
The local part is left alone (if it has internationalized characters
@@ -266,7 +266,7 @@ Normalization
266
266
267
267
The use of Unicode in email addresses introduced a normalization
268
268
problem. Different Unicode strings can look identical and have the same
269
-
semantic meaning to the user. The `email` field returned on successful
269
+
semantic meaning to the user. The `normalized` field returned on successful
270
270
validation provides the correctly normalized form of the given email
271
271
address.
272
272
@@ -275,9 +275,9 @@ equivalent in domain names to their ASCII counterparts. This library
275
275
normalizes them to their ASCII counterparts:
276
276
277
277
```python
278
-
valid= validate_email("me@Domain.com")
279
-
print(valid.email)
280
-
print(valid.ascii_email)
278
+
emailinfo= validate_email("me@Domain.com")
279
+
print(emailinfo.normalized)
280
+
print(emailinfo.ascii_email)
281
281
# prints "me@domain.com" twice
282
282
```
283
283
@@ -321,7 +321,7 @@ For the email address `test@joshdata.me`, the returned object is:
321
321
322
322
```python
323
323
ValidatedEmail(
324
-
email='test@joshdata.me',
324
+
normalized='test@joshdata.me',
325
325
local_part='test',
326
326
domain='joshdata.me',
327
327
ascii_email='test@joshdata.me',
@@ -335,7 +335,7 @@ internationalized domain but ASCII local part, the returned object is:
335
335
336
336
```python
337
337
ValidatedEmail(
338
-
email='example@ツ.life',
338
+
normalized='example@ツ.life',
339
339
local_part='example',
340
340
domain='ツ.life',
341
341
ascii_email='example@xn--bdk.life',
@@ -345,20 +345,20 @@ ValidatedEmail(
345
345
346
346
```
347
347
348
-
Note that the `email` and `domain` fields provide a normalized form of the
348
+
Note that `normalized` and other fields provide a normalized form of the
349
349
email address, domain name, and (in other cases) local part (see earlier
350
350
discussion of normalization), which you should use in your database.
351
351
352
352
Calling `validate_email` with the ASCII form of the above email address,
353
353
`example@xn--bdk.life`, returns the exact same information (i.e., the
354
-
`email` field always will contain Unicode characters, not Punycode).
354
+
`normalized` field always will contain Unicode characters, not Punycode).
355
355
356
356
For the fictitious address `ツ-test@joshdata.me`, which has an
357
357
internationalized local part, the returned object is:
358
358
359
359
```python
360
360
ValidatedEmail(
361
-
email='ツ-test@joshdata.me',
361
+
normalized='ツ-test@joshdata.me',
362
362
local_part='ツ-test',
363
363
domain='joshdata.me',
364
364
ascii_email=None,
@@ -368,10 +368,8 @@ ValidatedEmail(
368
368
```
369
369
370
370
Now `smtputf8` is `True` and `ascii_email` is `None` because the local
371
-
part of the address is internationalized. The `local_part` and `email` fields
372
-
return the normalized form of the address: certain Unicode characters
373
-
(such as angstrom and ohm) may be replaced by other equivalent code
374
-
points (a-with-ring and omega).
371
+
part of the address is internationalized. The `local_part` and `normalized` fields
372
+
return the normalized form of the address.
375
373
376
374
Return value
377
375
------------
@@ -381,8 +379,8 @@ are:
381
379
382
380
| Field | Value |
383
381
| -----:|-------|
384
-
|`email`| The normalized form of the email address that you should put in your database. This combines the `local_part` and `domain` fields (see below). |
385
-
|`ascii_email`| If set, an ASCII-only form of the email address by replacing the domain part with [IDNA](https://tools.ietf.org/html/rfc5891)[Punycode](https://www.rfc-editor.org/rfc/rfc3492.txt). This field will be present when an ASCII-only form of the email address exists (including if the email address is already ASCII). If the local part of the email address contains internationalized characters, `ascii_email` will be `None`. If set, it merely combines `ascii_local_part` and `ascii_domain`. |
382
+
|`normalized`| The normalized form of the email address that you should put in your database. This combines the `local_part` and `domain` fields (see below). |
383
+
|`ascii_email`| If set, an ASCII-only form of the normalized email address by replacing the domain part with [IDNA](https://tools.ietf.org/html/rfc5891)[Punycode](https://www.rfc-editor.org/rfc/rfc3492.txt). This field will be present when an ASCII-only form of the email address exists (including if the email address is already ASCII). If the local part of the email address contains internationalized characters, `ascii_email` will be `None`. If set, it merely combines `ascii_local_part` and `ascii_domain`. |
386
384
|`local_part`| The normalized local part of the given email address (before the @-sign). Normalization includes Unicode NFC normalization and removing unnecessary quoted-string quotes and backslashes. If `allow_quoted_local` is True and the surrounding quotes are necessary, the quotes _will_ be present in this field. |
387
385
|`ascii_local_part`| If set, the local part, which is composed of ASCII characters only. |
388
386
|`domain`| The canonical internationalized Unicode form of the domain part of the email address. If the returned string contains non-ASCII characters, either the [SMTPUTF8](https://tools.ietf.org/html/rfc6531) feature of your mail relay will be required to transmit the message or else the email address's domain part must be converted to IDNA ASCII first: Use `ascii_domain` field instead. |
Copy file name to clipboardExpand all lines: email_validator/exceptions_types.py
+13-5Lines changed: 13 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -22,13 +22,13 @@ class ValidatedEmail(object):
22
22
and other information."""
23
23
24
24
"""The email address that was passed to validate_email. (If passed as bytes, this will be a string.)"""
25
-
original_email: str
25
+
original: str
26
26
27
27
"""The normalized email address, which should always be used in preferance to the original address.
28
28
The normalized address converts an IDNA ASCII domain name to Unicode, if possible, and performs
29
29
Unicode normalization on the local part and on the domain (if originally Unicode). It is the
30
30
concatenation of the local_part and domain attributes, separated by an @-sign."""
31
-
email: str
31
+
normalized: str
32
32
33
33
"""The local part of the email address after Unicode normalization."""
34
34
local_part: str
@@ -68,14 +68,22 @@ def __init__(self, **kwargs):
68
68
setattr(self, k, v)
69
69
70
70
def__repr__(self):
71
-
returnf"<ValidatedEmail {self.email}>"
71
+
returnf"<ValidatedEmail {self.normalized}>"
72
+
73
+
"""For backwards compatibility, support old field names."""
74
+
def__getattr__(self, key):
75
+
ifkey=="original_email":
76
+
returnself.original
77
+
ifkey=="email":
78
+
returnself.normalized
79
+
raiseAttributeError()
72
80
73
81
"""For backwards compatibility, some fields are also exposed through a dict-like interface. Note
74
82
that some of the names changed when they became attributes."""
75
83
def__getitem__(self, key):
76
84
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)
0 commit comments