Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#30512 closed Cleanup/optimization (fixed)

Update mail backend to use modern standard library parsing approach.

Reported by: Joachim Jablon Owned by: Joachim Jablon
Component: Core (Mail) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

django.core.mail.message.sanitize_address uses email.utils.parseaddr from the standard lib. On Python 3, email.headerregistry.parser.get_mailbox() does the same, and is less error-prone.

Change History (9)

comment:1 by Joachim Jablon, 5 years ago

Has patch: set

comment:2 by Mariusz Felisiak, 5 years ago

Summary: Update mail backend to use modern standard library parsing approachUpdate mail backend to use modern standard library parsing approach.
Triage Stage: UnreviewedAccepted

comment:3 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In f841a77:

Refs #30512 -- Used subTest() in MailTests.test_sanitize_address.

comment:4 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In 8ba20d90:

Refs #30512 -- Added tests for sanitizing email addresses with display name and two @ signs.

comment:5 by Mariusz Felisiak, 5 years ago

Needs tests: set

comment:6 by Mariusz Felisiak, 5 years ago

Needs tests: unset

comment:7 by Mariusz Felisiak, 5 years ago

Triage Stage: AcceptedReady for checkin

comment:8 by Carlton Gibson <carlton@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 2628ea95:

Fixed #30512 -- Used email.headerregistry.parser for parsing emails in sanitize_address().

comment:9 by Carlton Gibson <carlton@…>, 5 years ago

In 1564e42a:

Refs #30512, #15042 -- Added local-only address to sanitize_email() tests cases.

email.headerregistry.parser.get_mailbox() returns a token with a token_type attribute.

If token_type is ’invalid-mailbox’ then RFC violations have been detected. Emails with only the local part, and no domain, are correctly parsed but are marked as ’invalid-mailbox’.

As per #15042, local-only are supported, to enable sending to addresses on localhost.

sanitize_email() does not currently check token_type. This test is added to avoid a regression in case this is revisited in the future.

Note: See TracTickets for help on using tickets.
Back to Top