Skip to content

gh-157880: Write visible headers of BabylMessage in mailbox.Babyl - #157881

Merged
serhiy-storchaka merged 2 commits into
python:mainfrom
vasiliyk:gh-157880-babyl
Oct 22, 2026
Merged

serhiy-storchaka merged 2 commits into
python:mainfrom
vasiliyk:gh-157880-babyl

Conversation

@vasiliyk

@vasiliyk vasiliyk commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

When adding a BabylMessage, Babyl._install_message() flattens its visible headers into a BytesIO and copies them line by line into the mailbox file. The buffer was never rewound after flattening, so readline() returned nothing and the visible headers block and the blank line after it were skipped.
Reading the message back with get_message() or get_bytes() then consumed the body as headers and failed with AssertionError.

Rewind the buffer before reading it, and add a test that adds a BabylMessage with visible headers and reads it back.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the patch. The fix looks good to me.

Please add a test for a message with no visible headers. It is also broken, because the blank line after the headers is not written, and get_bytes() fails with AssertionError.

@vasiliyk

Copy link
Copy Markdown
Contributor Author

Added test_no_visible_headers and renamed the existing test to test_visible_headers for consistency.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

@serhiy-storchaka serhiy-storchaka added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 22, 2026
@serhiy-storchaka
serhiy-storchaka merged commit 1512f78 into python:main Oct 22, 2026
60 of 61 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @vasiliyk for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Oct 22, 2026

Copy link
Copy Markdown

GH-160276 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 22, 2026
@bedevere-app

bedevere-app Bot commented Oct 22, 2026

Copy link
Copy Markdown

GH-160277 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 22, 2026
@vasiliyk
vasiliyk deleted the gh-157880-babyl branch October 22, 2026 18:14
serhiy-storchaka pushed a commit that referenced this pull request Oct 22, 2026
…byl (GH-157881) (GH-160276)

(cherry picked from commit 1512f78)

Co-authored-by: Vasiliy Kiryanov <vasiliy.kiryanov@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants