Skip to content

Lenient recovery from duplicate Content-Type parameters - #10

Merged
mpasquale-3 merged 3 commits into
masterfrom
mpasquale-lenient-duplicate-param-recovery
Aug 24, 2026
Merged

Lenient recovery from duplicate Content-Type parameters#10
mpasquale-3 merged 3 commits into
masterfrom
mpasquale-lenient-duplicate-param-recovery

Conversation

@mpasquale-3

@mpasquale-3 mpasquale-3 commented Aug 21, 2026

Copy link
Copy Markdown

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 deduplicateContentTypeParams function to deduplicate Content-Type parameters. The deduplicateContentTypeParams short circuits when possible and avoids rebuilding the string with new allocations until we know there is a duplicate.

🤖 Generated with Claude Code

@mpasquale-3
mpasquale-3 marked this pull request as ready for review August 21, 2026 21:51
@mpasquale-3
mpasquale-3 force-pushed the mpasquale-lenient-duplicate-param-recovery branch from ba3236b to 2cbfb00 Compare August 21, 2026 22:24
@mpasquale-3
mpasquale-3 requested a review from a team August 21, 2026 22:48
Comment thread header.go
Comment thread header_test.go Outdated
jakeesmael
jakeesmael previously approved these changes Aug 24, 2026
mpasquale-3 and others added 3 commits August 24, 2026 12:32
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>
@mpasquale-3
mpasquale-3 force-pushed the mpasquale-lenient-duplicate-param-recovery branch from d015b7e to b026617 Compare August 24, 2026 19:40
@mpasquale-3
mpasquale-3 merged commit 6d40c4f into master Aug 24, 2026
3 checks passed
@mpasquale-3
mpasquale-3 deleted the mpasquale-lenient-duplicate-param-recovery branch August 24, 2026 20:06
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