MCPcopy
hub / github.com/django/django / test_address_header_handling

Method test_address_header_handling

tests/mail/tests.py:1347–1410  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1345 )
1346
1347 def test_address_header_handling(self):
1348 # This verifies the modern email API's address header handling.
1349 cases = [
1350 # (address, expected_display_name, expected_addr_spec)
1351 ("to@example.com", "", "to@example.com"),
1352 # Addresses with display-names.
1353 ("A name <to@example.com>", "A name", "to@example.com"),
1354 ('"A name" <to@example.com>', "A name", "to@example.com"),
1355 (
1356 '"Comma, requires quotes" <to@example.com>',
1357 "Comma, requires quotes",
1358 "to@example.com",
1359 ),
1360 ('"to@other.com" <to@example.com>', "to@other.com", "to@example.com"),
1361 # Non-ASCII addr-spec: IDNA encoding for domain.
1362 # (Note: no RFC permits encoding a non-ASCII localpart.)
1363 ("to@éxample.com", "", "to@xn--xample-9ua.com"),
1364 (
1365 "To Example <to@éxample.com>",
1366 "To Example",
1367 "to@xn--xample-9ua.com",
1368 ),
1369 # Pre-encoded IDNA domain is left as is.
1370 # (Make sure IDNA 2008 is not downgraded to IDNA 2003.)
1371 ("to@xn--fa-hia.example.com", "", "to@xn--fa-hia.example.com"),
1372 (
1373 "<to@xn--10cl1a0b660p.example.com>",
1374 "",
1375 "to@xn--10cl1a0b660p.example.com",
1376 ),
1377 (
1378 '"Display, Name" <to@xn--nxasmm1c.example.com>',
1379 "Display, Name",
1380 "to@xn--nxasmm1c.example.com",
1381 ),
1382 # Non-ASCII display-name.
1383 ("Tó Example <to@example.com>", "Tó Example", "to@example.com"),
1384 # Addresses with two @ signs (quoted-string localpart).
1385 ('"to@other.com"@example.com', "", '"to@other.com"@example.com'),
1386 (
1387 'To Example <"to@other.com"@example.com>',
1388 "To Example",
1389 '"to@other.com"@example.com',
1390 ),
1391 # Addresses with long non-ASCII display names.
1392 (
1393 "Tó Example very long" * 4 + " <to@example.com>",
1394 "Tó Example very long" * 4,
1395 "to@example.com",
1396 ),
1397 # Address with long display name and non-ASCII domain.
1398 (
1399 "To Example very long" * 4 + " <to@exampl€.com>",
1400 "To Example very long" * 4,
1401 "to@xn--exampl-nc1c.com",
1402 ),
1403 ]
1404 for address, name, addr in cases:

Callers

nothing calls this directly

Calls 5

messageMethod · 0.95
EmailMessageClass · 0.90
message_from_bytesFunction · 0.85
as_bytesMethod · 0.80
AddressClass · 0.50

Tested by

no test coverage detected