Skip to content

fix: support utf-7 and legacy encodings in email parsing#2109

Open
alpapad wants to merge 1 commit into
rnwood:masterfrom
alpapad:fix/utf7-legacy-email-encoding
Open

fix: support utf-7 and legacy encodings in email parsing#2109
alpapad wants to merge 1 commit into
rnwood:masterfrom
alpapad:fix/utf7-legacy-email-encoding

Conversation

@alpapad
Copy link
Copy Markdown

@alpapad alpapad commented May 30, 2026

Register CodePagesEncodingProvider to enable legacy code page encodings (ISO-8859-8, Windows-1252, etc.) which are commonly used in older email clients and are not available by default in .NET 5+.

Add Utf7EncodingProvider and Utf7WrapperEncoding to re-enable UTF-7 decoding for legacy email messages. .NET 9+ blocks Encoding.GetEncoding(65000) and Encoding.GetEncoding("utf-7") before consulting registered providers. The workaround registers a custom encoding that reports CodePage=65002 (a private-use value not blocked by .NET). MimeKit caches utf-7→65002 and subsequent codepage lookups are intercepted by the provider, delegating actual encoding/decoding to the still-functional Encoding.UTF7 instance.

Register CodePagesEncodingProvider to enable legacy code page encodings
(ISO-8859-8, Windows-1252, etc.) which are commonly used in older email
clients and are not available by default in .NET 5+.

Add Utf7EncodingProvider and Utf7WrapperEncoding to re-enable UTF-7
decoding for legacy email messages. .NET 9+ blocks Encoding.GetEncoding(65000)
and Encoding.GetEncoding("utf-7") before consulting registered providers.
The workaround registers a custom encoding that reports CodePage=65002 (a
private-use value not blocked by .NET). MimeKit caches utf-7→65002 and
subsequent codepage lookups are intercepted by the provider, delegating
actual encoding/decoding to the still-functional Encoding.UTF7 instance.
@github-actions
Copy link
Copy Markdown
Contributor

Thank you for your contribution to smtp4dev! 🎉

Before we can merge your pull request, we need you to sign our Contributor License Agreement (CLA).

📝 Please read the CLA: Contributor License Agreement

✍️ To sign the CLA, please comment on this PR with exactly:

I have read the CLA Document and I hereby sign the CLA

This is a one-time requirement for new contributors. Thank you for your understanding! 🙏


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@alpapad
Copy link
Copy Markdown
Author

alpapad commented May 30, 2026

I have read the CLA Document and I hereby sign the CLA

@sonarqubecloud
Copy link
Copy Markdown

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