Bug 443009 - Replying email breaks text encoding
Summary: Replying email breaks text encoding
Status: RESOLVED FIXED
Alias: None
Product: kontact
Classification: Applications
Component: mail (show other bugs)
Version: 5.18.1
Platform: Manjaro Linux
: NOR normal
Target Milestone: ---
Assignee: kdepim bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-09-27 12:50 UTC by boite.pour.spam
Modified: 2023-03-09 12:01 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description boite.pour.spam 2021-09-27 12:50:51 UTC
SUMMARY
On some email (not all), replying breaks the text encoding and all "special" characters are replaced by unreadable code.

The text is displayed correctly in the initial message view (which is HTML)
like this:

Je suis en train de créer une

But if I hit reply, I get this instead:

> Je suis en train de créer



STEPS TO REPRODUCE
1. The initial message was written with Apple mail and is using quoted-printable for the content transfer encoding, and the content type is specifying utf-8, like this:


--Apple-Mail-B6D63D2D-099E-44BF-9EDA-531641451B38
Content-Type: text/plain;
	charset=utf-8
Content-Transfer-Encoding: quoted-printable

Merci Vincent.=20

Salut Cyril j=E2=80=99esp=C3=A8re que tu vas bien ?=20
Je suis en train de cr=C3=A9er...
[...content removed here for privacy...]

--Apple-Mail-B6D63D2D-099E-44BF-9EDA-531641451B38
Content-Type: multipart/mixed;
	boundary=Apple-Mail-ACFFAAD7-7608-4761-8991-19B6D013FB0C
Content-Transfer-Encoding: 7bit


--Apple-Mail-ACFFAAD7-7608-4761-8991-19B6D013FB0C
Content-Type: text/html;
	charset=utf-8
Content-Transfer-Encoding: quoted-printable

<html><head><meta http-equiv=3D"content-type" content=3D"text/html; charset=3D=
utf-8"></head><body dir=3D"auto"><div dir=3D"ltr"><meta http-equiv=3D"conten=
t-type" content=3D"text/html; charset=3Dutf-8">Merci Vincent.&nbsp;<div><br>=
</div><div>Salut Cyril j=E2=80=99esp=C3=A8re que tu vas bien ?&nbsp;</div><d=
iv>Je suis en train de cr=C3=A9er 
[...content removed here for privacy...]

2. If you hit reply on such message, you'll get this:

Le lundi 27 septembre 2021 07:53:13 CEST, vous avez écrit :
> Merci Vincent. 
> 
> Salut Cyril jâespère que tu vas bien ? 
> Je suis en train de créer 

3. Please notice that if I select some text and hit reply, the text is correctly encoded (but I loose the unselected text obviously)
4. Also, switching HTML or plain text does not work either to restore the correct encoding of the text
5. Also, the part that KMail is writing by itself ("vous avez écrit :") is also wrong.


It's not a duplicate of bug 441136 since I don't have the option "Keep original charset when replying" selected.

OBSERVED RESULT
See above

EXPECTED RESULT
See above

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Manjaro
(available in About System)
KDE Plasma Version: 5.22.5
KDE Frameworks Version: 5.85
Qt Version: 5.15.2
KMail: Version 5.18.1 (21.08.1)

ADDITIONAL INFORMATION
Comment 1 Bug Janitor Service 2023-03-07 20:38:25 UTC
A possibly relevant merge request was started @ https://invent.kde.org/pim/messagelib/-/merge_requests/107
Comment 2 Laurent Montel 2023-03-09 12:01:46 UTC
Git commit 29a5a05e2078b75f0a994e29e92707e3ec81e2d1 by Laurent Montel, on behalf of Fabian Vogt.
Committed on 09/03/2023 at 07:27.
Pushed by fvogt into branch 'master'.

Fix fallback path in MessageFactoryNG::applyCharset

In the case that the codec of the original message could not encode the reply,
it was still set as charset but the body encoded with the fallback codec.
This resulted in replies having messed up encoding.
It can be triggered by replying to multipart mails which define the charset
in parts only or if the reply template ends up with other special characters.
Related: bug 447297, bug 298349

M  +64   -0    messagecomposer/autotests/messagefactoryngtest.cpp
M  +3    -0    messagecomposer/autotests/messagefactoryngtest.h
M  +5    -4    messagecomposer/src/helper/messagefactoryng.cpp

https://invent.kde.org/pim/messagelib/commit/29a5a05e2078b75f0a994e29e92707e3ec81e2d1