Repository navigation
gh-151454: Accept Header values in email.message.Message.add_header - #151458
Open
harjothkhara wants to merge 2 commits into
Open
harjothkhara wants to merge 2 commits into
harjothkhara wants to merge 2 commits into
Conversation
…ader Message.items() can yield (name, Header) pairs under the compat32 policy (for a header carrying 8-bit data), and Message[name] = value accepts such Header values, but add_header() raised "TypeError: sequence item 0: expected str instance, Header found" because it assembled the value with SEMISPACE.join(). When no extra parameters are given, add_header() now mirrors __setitem__ and stores the value (Header or str) unmodified, fixing the reported header-copy loop. None is still coerced to '' to preserve add_header()'s historical behavior. The parameterized branch is unchanged: it still builds the header as a string and so continues to require a str value. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Documentation build overview
|
Contributor
Author
|
@picnixz, small email-related fix in |
Contributor
Author
Member
|
Sorry, but no. I just added labels (which I can do easily) but reviewing takes time. I would suggest waiting for someone from the email to pick this up (but please be patient as it may require to wait more than just one or two weeks). |
Member
|
Ok so I still took a bit of my time. I'm going to comment on the issue. |
…with params Combining a Header value with parameters was already rejected, but with the confusing internal TypeError from SEMISPACE.join(). Raise a clear one instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Under the
compat32policy,Message.items()yields aHeaderobject (not astr) for any header carrying 8-bit data. You can assign that back withmsg[name] = value, butmsg.add_header(name, value)— documented as equivalent — raisedTypeError: sequence item 0: expected str instance, Header found, because it always didSEMISPACE.join(parts). So the natural "copy every header" loop breaks:Fix: when no extra parameters are passed,
add_header()now stores the value the same way__setitem__does, so aHeader(orstr) is stored unchanged — matching the documented equivalence.Nonestill becomes''. The parameterized branch is left as-is: it has to build a string, and silently stringifying anunknown-8bitHeaderwould corrupt its bytes to U+FFFD, so it still raises there.Added a regression test and a
versionchangednote../python -m test test_emailpasses.Disclosure: I used AI assistance writing this; I've reviewed the change and can explain it.