Fix double charset conversion for non-UTF-8 message bodies#10100
Fix double charset conversion for non-UTF-8 message bodies#10100ju-ef wants to merge 1 commit intoroundcube:masterfrom
Conversation
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.
|
I'm not a fun of checking encoding. We should investigate why we do convertion twice, and why more people don't complain. Could you provide a sample message? |
|
I can reproduce it via swaks.
OK - Not OK - So, it's something wrong with stalwart. |
|
Other clients might use different set of imap commands, some of them just download the mail source and parse it themselves, but Roundcube uses e.g. BODYSTRUCTURE response from the IMAP server. If such a response is invalid... It works for me also with Cyrus IMAP. So, it's obviously a Stalwart issue. Enable imap_debug to see what's going on. You can also try with |

Problem
Messages with charset=windows-1251 (quoted-printable encoding) display as garbled text in Roundcube. Other clients (Thunderbird, K-9, mutt) display them correctly.
Root Cause
get_message_part()already converts body charset to UTF-8, butformat_part_body()converts it again using$part->charsetwhich still contains the original charset (e.g. windows-1251). This double conversion produces garbled output.Fix
Check
mb_check_encoding()before converting — if body is already valid UTF-8, skip conversion.Tested
Roundcube 1.6.13 + Stalwart mail server, windows-1251 quoted-printable messages now display correctly.
Related
Similar UTF-8 detection approach used in #10078.