Skip to content

gh-160598: Preserve Babyl labels when reopening mailboxes - #160604

Open
kinqsradio wants to merge 1 commit into
python:mainfrom
kinqsradio:fix/babyl-label-roundtrip
Open

kinqsradio wants to merge 1 commit into
python:mainfrom
kinqsradio:fix/babyl-label-roundtrip

Conversation

@kinqsradio

@kinqsradio kinqsradio commented Oct 24, 2026 •

Copy link
Copy Markdown

Fixes #160598.

Reopening a Babyl mailbox left message labels as bytes even though the message APIs and writers expect strings. This could mark an unseen message as read when converting it to another mailbox format, include special labels in Babyl.get_labels(), and raise AttributeError when rewriting or copying labeled messages.

Decode labels as UTF-8 when reading the table of contents and use surrogateescape when reading and writing labels so existing non-UTF-8 label bytes survive a round trip. Add regression tests for reopening, special-label filtering, read-flag conversion, copying, and rewriting, including Unicode and invalid UTF-8 labels.

Validation:

  • Both new regression tests fail before the fix and pass after it.
  • ./python.exe -m test test_mailbox succeeds on a local macOS arm64 CPython 3.16 build (388 tests reported, 3 skipped).
  • CPython patchcheck and git diff --check pass.

AI assistance was used to investigate the issue, prepare the patch and tests, and run local validation.

@kinqsradio
kinqsradio requested a review from a team as a code owner October 24, 2026 16:28
@python-cla-bot

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

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

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.

mailbox.Babyl returns labels as bytes after reading a mailbox file

1 participant