Skip to content

gh-159858: Fix memoryview payloads with 7bit, 8bit and binary email CTEs - #159859

Open
NikitaMikhailov wants to merge 2 commits into
python:mainfrom
NikitaMikhailov:codex/email-memoryview-cte
Open

NikitaMikhailov wants to merge 2 commits into
python:mainfrom
NikitaMikhailov:codex/email-memoryview-cte

Conversation

@NikitaMikhailov

Copy link
Copy Markdown

Fixes gh-159858.

EmailMessage.set_content() accepts memoryview through the raw data manager's registered bytes handler, but the 7bit, 8bit, and binary branches call a decode() method that memoryview does not provide.

Decode the buffer directly with str(data, encoding, errors). This preserves ASCII validation for 7bit and surrogateescape handling for 8bit and binary, without an intermediate bytes copy.

Regression tests cover bytes, bytearray, and memoryview payloads with all three transfer encodings, including binary data round trips and rejection of non-ASCII 7bit input.

Validation:

  • The new regression tests produce four AttributeError errors before the change and pass afterwards.
  • All 1,822 email tests pass (two skipped).
  • Full CPython suite: SUCCESS, 52,161 tests run, 2,945 skipped; duration 6 min 57 sec.
  • pre-commit checks pass for both changed Python files.
  • Rechecked the unchanged implementation from current main (4c73f50) on October 20; the bug still reproduces in all three cases. All 118 content manager tests pass with this fix.

Includes a Library NEWS entry.

AI assistance: Codex helped prepare the fix and tests and run validation.

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.

email: set_content() raises AttributeError for memoryview with 7bit, 8bit or binary CTE

1 participant