Skip to content

Fix MIME encoded-word decoding - #133407

Merged
rzikm merged 2 commits into
mainfrom
fix-mime-encoded-word-decoding
Sep 9, 2026
Merged

rzikm merged 2 commits into
mainfrom
fix-mime-encoded-word-decoding

Conversation

@rzikm

@rzikm rzikm commented Sep 8, 2026

Copy link
Copy Markdown
Member

Summary

  • decode RFC 2047 encoded-words token by token when mixed with ordinary ASCII text
  • treat B/Q encoding identifiers case-insensitively
  • preserve linear whitespace around ordinary text while suppressing it between adjacent encoded-words
  • recognize mixed encoded-word values in MailMessage.Subject and ContentType.Name
  • preserve literal text for tokens that are not valid encoded-words and retain existing malformed-payload behavior

Testing

  • System.Net.Mail.csproj build: 0 warnings, 0 errors
  • ByteEncodingTest: 25 passed
  • MessageHeaderBehaviorTest: 15 passed
  • ContentTypeTest: 30 passed

Note

This pull request description was generated with GitHub Copilot.

Decode RFC 2047 encoded-words token by token, honor case-insensitive encoding identifiers, and preserve the required whitespace behavior.

Co-authored-by: Copilot App <[email protected]>
Copilot AI lite review requested due to automatic review settings September 8, 2026 09:30
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@rzikm
rzikm requested a review from a team September 8, 2026 09:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

DecodeEncoding/DecodeHeaderValue can now throw on unknown charsets in scenarios that flow into public APIs (e.g., ContentType.Name) and tests don’t yet cover the new Q/q decode path.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Updates System.Net.Mail’s RFC 2047 “encoded-word” handling to better decode mixed ASCII + encoded-word header values (e.g., subjects and MIME parameter names), including case-insensitive encoding identifiers and improved whitespace behavior.

Changes:

  • Reworks MimeBasePart.DecodeHeaderValue/DecodeEncoding to tokenize by linear whitespace and decode encoded-words per token.
  • Adds regression tests for mixed ASCII + encoded-word decoding, plus ContentType name= decoding.
  • Adds coverage for case-insensitive encoded-word encoding identifiers (tests currently only cover Base64).
File summaries
File Description
src/libraries/System.Net.Mail/src/System/Net/Mime/MimeBasePart.cs Token-based RFC 2047 decoding and encoding detection logic for header values.
src/libraries/System.Net.Mail/tests/Unit/ByteEncodingTest.cs Adds unit tests covering mixed ASCII/encoded-word decoding and identifier casing.
src/libraries/System.Net.Mail/tests/Unit/MessageTests/MessageHeaderBehaviorTest.cs Adds subject regression test for mixed ASCII + encoded-word input.
src/libraries/System.Net.Mail/tests/Functional/ContentTypeTest.cs Adds functional coverage for encoded-word decoding in ContentType.Name.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 4
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings September 8, 2026 12:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The behavioral change is well-scoped, consistently applied across affected call sites, and backed by targeted unit/functional tests for the new decoding rules and edge cases.

Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@wfurt wfurt 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

@rzikm
rzikm merged commit c88e3d0 into main Sep 9, 2026
79 of 82 checks passed
@rzikm
rzikm deleted the fix-mime-encoded-word-decoding branch September 9, 2026 08:33
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 9, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants