Skip to content

email.utils.parseaddr rejects a valid quoted local part containing '[' #158781

Description

@augusto-rehfeldt

Bug report

Bug description:

Documented behaviour: email.utils.formataddr documentation and docstring: "The inverse of parseaddr(), this takes a 2-tuple of the form (realname, email_address) and returns the string value suitable for an RFC 2822 From, To or Cc header."

Expected: ('Alice', '"a[b"@example.com')

Actual: ('', '')

import email.utils as e
import re

pair = ('Alice', '"a[b"@example.com')
name, address = pair
# RFC 2822 quoted-string qtext permits "["; example.com is a valid domain.
if not (re.fullmatch(r'[A-Za-z]+', name) and
        re.fullmatch(r'"[\x21\x23-\x5b\x5d-\x7e]+"@example\.com', address)):
    print('REFUTATION REJECTED: input validity not established')
else:
    expected = (name, address)  # Independently derived from the inverse promise.
    actual = e.parseaddr(e.formataddr(pair))
    if actual != expected:
        print('REFUTATION CONFIRMED:', pair, 'actual:', actual, 'expected:', expected)
    else:
        print('REFUTATION REJECTED: documented round trip succeeds')

Output on Python 3.14.6 (Windows-11-10.0.26220-SP0), standard library email.utils:

REFUTATION CONFIRMED: ('Alice', '"a[b"@example.com') actual: ('', '') expected: ('Alice', '"a[b"@example.com')

This report was found and written by an automated property-testing tool I run (bugforge). The reproducer above was executed and its output is pasted unedited; no person reviewed the report before it was filed. The search script is in https://github.com/augusto-rehfeldt/bugforge-results/tree/main/email.utils-20261003-021105-c1

CPython versions tested on:

3.14

Operating systems tested on:

Windows

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions