Commit 671f6e8
committed
Improve handling of non-ASCII characters in message headers
Improve Anymail's normalized EmailAddress object:
- Stop using Django's undocumented, deprecated sanitize_address() helper
- Add ANYMAIL["IDNA_ENCODER"] setting, defaulting to idna2008 [breaking]
- Implement a few useful IDNA_ENCODER presets
- Add idna package as direct dependency (already sub-dependency of 'requests')
- Add uts46 package optional dependency
- Add base backend idna_encode method for subclass use
- Subclass EmailAddress from Python's modern email.headerregistry.Address object
- Add EmailAddress.as_dict() and formatting options useful for various ESPs
- Add utils to apply/reverse RFC 2047 encoded-word and RFC 5322 quoted-string
formatting
Update each ESP's EmailBackend to use the appropriate EmailAddress and header
encodings, based on testing its API's behavior for Unicode characters.
Add some ESP-specific unsupported feature errors to prevent particularly
problematic Unicode handling:
- Brevo: Prevent non-ASCII values in custom headers to avoid raw, 8-bit
utf-8 (also affects metadata, which uses a custom header)
- Mailgun: Prevent EAI in from_email (API accepts EAI, but generated
message is undeliverable)
- Scaleway: Prevent EAI in any address field (API accepts EAI, but
generated message is undeliverable)
Documentation:
- Add a new "International email" page in the advanced section, with
general details on Unicode handling and the new IDNA_ENCODER setting
- Update each ESP's page to indicate whether it handles EAI
- Document some other ESP-specific Unicode quirks uncovered during testing
Closes #4441 parent 53ea757 commit 671f6e8
File tree
49 files changed
+2271
-261
lines changed- anymail
- backends
- docs
- esps
- tips
- tests
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
49 files changed
+2271
-261
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
28 | 88 | | |
29 | 89 | | |
30 | 90 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
156 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
157 | 180 | | |
158 | 181 | | |
159 | 182 | | |
| |||
232 | 255 | | |
233 | 256 | | |
234 | 257 | | |
235 | | - | |
| 258 | + | |
| 259 | + | |
236 | 260 | | |
237 | 261 | | |
238 | 262 | | |
| |||
355 | 379 | | |
356 | 380 | | |
357 | 381 | | |
358 | | - | |
| 382 | + | |
| 383 | + | |
359 | 384 | | |
360 | 385 | | |
361 | 386 | | |
362 | | - | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
363 | 390 | | |
364 | 391 | | |
365 | 392 | | |
366 | 393 | | |
367 | 394 | | |
368 | 395 | | |
369 | | - | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
370 | 404 | | |
371 | 405 | | |
372 | 406 | | |
| |||
447 | 481 | | |
448 | 482 | | |
449 | 483 | | |
450 | | - | |
451 | | - | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
452 | 487 | | |
453 | 488 | | |
454 | 489 | | |
| |||
462 | 497 | | |
463 | 498 | | |
464 | 499 | | |
465 | | - | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
466 | 504 | | |
467 | 505 | | |
468 | 506 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| 12 | + | |
11 | 13 | | |
| 14 | + | |
12 | 15 | | |
13 | 16 | | |
14 | 17 | | |
| |||
32 | 35 | | |
33 | 36 | | |
34 | 37 | | |
| 38 | + | |
| 39 | + | |
35 | 40 | | |
36 | 41 | | |
37 | 42 | | |
| |||
63 | 68 | | |
64 | 69 | | |
65 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
66 | 91 | | |
67 | 92 | | |
68 | 93 | | |
| |||
157 | 182 | | |
158 | 183 | | |
159 | 184 | | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
160 | 194 | | |
161 | 195 | | |
162 | 196 | | |
| |||
0 commit comments