Fix garbled non-MIME-encoded UTF-8 headers#10078
Open
OctopusET wants to merge 1 commit into
Open
Conversation
ju-ef
added a commit
to ju-ef/roundcubemail
that referenced
this pull request
Feb 24, 2026
Messages with charset=windows-1251 (quoted-printable encoding) display as garbled text in Roundcube. Other clients (Thunderbird, K-9, mutt) display them correctly. `get_message_part()` already converts body charset to UTF-8, but `format_part_body()` converts it again using `$part->charset` which still contains the original charset (e.g. windows-1251). This double conversion produces garbled output. Check `mb_check_encoding()` before converting — if body is already valid UTF-8, skip conversion. Roundcube 1.6.13 + Stalwart mail server, windows-1251 quoted-printable messages now display correctly. Similar UTF-8 detection approach used in roundcube#10078.
b35d2bb to
089e201
Compare
Author
|
@alecpl I cleaned up the PR description. Previous one was too verbose and slop. Would you review this PR? Thank you. |
alecpl
reviewed
Mar 15, 2026
| $default_charset = $fallback ?: self::get_charset(); | ||
|
|
||
| // RFC 6532: detect raw UTF-8 in headers to avoid wrong charset conversion | ||
| if ($fallback !== false && mb_check_encoding($input, 'UTF-8') && preg_match('/[\x80-\xFF]/', $input)) { |
Member
There was a problem hiding this comment.
You should not assume RCUBE_CHARSET is always UTF-8.
Author
There was a problem hiding this comment.
Then should we change to
$default_charset = 'UTF-8';
instead?
Author
There was a problem hiding this comment.
I have rebased and applied that part.
Author
There was a problem hiding this comment.
for that I had to force push, sorry if it made you inconvenient
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.
decode_mime_string()blindly applies the body charset to non-MIME-encoded headers. If the header is raw UTF-8 but the body charset differs, the header gets corrupted.Check for valid UTF-8 before falling back to the body charset, same approach as Thunderbird's
convert8BitHeader(): https://searchfox.org/comm-central/source/mailnews/mime/jsmime/jsmime.mjs#675RFC 6532 (2012) legitimizes raw UTF-8 in email headers via SMTPUTF8 extension.
Screenshots
Before
After