Skip to content

gh-158780: Preserve defects in unstructured email headers - #160862

Closed
GriffinCanCode wants to merge 5 commits into
python:mainfrom
GriffinCanCode:codex/email-unstructured-header-defects
Closed

GriffinCanCode wants to merge 5 commits into
python:mainfrom
GriffinCanCode:codex/email-unstructured-header-defects

Conversation

@GriffinCanCode

@GriffinCanCode GriffinCanCode commented Oct 29, 2026 •

Copy link
Copy Markdown

Fixes #158780.

Unstructured headers discard the defects already recorded in their parse tree.
For example, HeaderRegistry()('Subject', '=?utf-8?b?YQ?=') decodes to 'a' but
reports no InvalidBase64PaddingDefect through its public defects attribute.

Propagate those defects and avoid repeated sibling-list concatenation in the
existing collector. Keep defect order, duplicate object identity, and empty-tree
behavior. The existing parameterized tests now check decoding, defects, and
folding for both Subject and custom headers.

This omission also appears in catalog item 34b.
The collector is listed in #136063, alongside the active parser work in #152521
and #152710. Neither PR currently implements these two changes; this is a small
fix in the same area, with that prior work acknowledged.

Validation on macOS arm64, CPython 3.16 debug:

  • ./python.exe -m test test_email test_mailbox test_smtplib: 2,305 tests, 5 skips.
  • make patchcheck and the applicable pinned pre-commit hooks pass.
  • Decoding and folding match in 78 comparisons across three policies. All five
    added runtime lines were profiled; bounded measurements checked CPU, wall
    time, and traced allocations without claiming universal speed improvements.
  • The full 561-module run completed with local failures in test_chown_gid,
    three test_glob_dotdot cases, and test_fast_path_avoid_busy_loop. The first
    two reproduce with the original email package; the subprocess assertion
    passes in a focused rerun. The full run is not clean.

AI assistance: Codex helped investigate the behavior, prepare the patch and
tests, and run the checks and profiling.

@GriffinCanCode
GriffinCanCode requested a review from a team as a code owner October 29, 2026 03:25
@python-cla-bot

python-cla-bot Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@NekoAsakura

Copy link
Copy Markdown
Member

The issue has been closed as not planned.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UnstructuredHeader drops encoded-word Base64 padding defects

2 participants