Lenient recovery from duplicate Content-Type parameters - #10
Merged
Conversation
mpasquale-3
marked this pull request as ready for review
August 21, 2026 21:51
mpasquale-3
force-pushed
the
mpasquale-lenient-duplicate-param-recovery
branch
from
August 21, 2026 22:24
ba3236b to
2cbfb00
Compare
jakeesmael
suggested changes
Aug 22, 2026
jakeesmael
previously approved these changes
Aug 24, 2026
When mime.ParseMediaType fails due to duplicate parameter names, strip the duplicates (keeping the first occurrence) and retry. On success, return the recovered media type and params alongside a MalformedHeaderError so callers can distinguish a recovered-but-valid header from a genuinely unparseable one. Exports IsMalformedHeader so consumers (e.g. go-mantis) can opt in to using the recovered values while still observing the malformed-header signal. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…covery Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ty signal Callers can check params != nil to determine whether recovered values are usable, regardless of whether err is non-nil. The invariant is: params != nil means the values are safe to use. This removes unnecessary API surface. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
jakeesmael
approved these changes
Aug 24, 2026
mpasquale-3
force-pushed
the
mpasquale-lenient-duplicate-param-recovery
branch
from
August 24, 2026 19:40
d015b7e to
b026617
Compare
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.
Summary
My Summary:
Apple Mail renders both plaintext and HTML when duplicate Content-Type parameters exist. We need to emulate this permissive behavior in order to parse messages and detect phishes that could be apparent in Apple Mail.
This change adds a
deduplicateContentTypeParamsfunction to deduplicate Content-Type parameters. ThededuplicateContentTypeParamsshort circuits when possible and avoids rebuilding the string with new allocations until we know there is a duplicate.🤖 Generated with Claude Code