kmail –view can't display some maildir files correctly

I use offlineimap/Maildir/Emacs GNUS to read mails. Sometimes, I have a fancy html mail that can't render nicely in GNUS, so I have defined a key to open it with external helper program, i.e., kmail --view (The Emacs function I used to define the externel helper is bhj-view-mail-external).

But, there is a problem, sometimes kmail can't display my message correctly, instead, it displays something like this:

bad-kmail-view.png

All the Chinese characters are displayed incorrectly, as if they are some latin-1 characters. But there are some Chinese emails that do display correctly.

Some googling took me to this bug. Then I started tweaking kmail relentlessly, and found these results:

  1. The same mail can be viewed correctly if I find it in the kmail main window and double click to view.
  2. The same mail can not be viewed correctly if I open it from command line with kmail --view file://FILEPATH

Openning the file in Emacs editor and comparing it with other viewable Chinese emails, I found a difference, that the buggy emails are Content-Transfer-Encoding: 8bit, while the OK emails are Content-Transfer-Encoding: quoted-printable. So I started to try to convert 8bit mails to quoted-printable.

And the result is a java program Mail8Bit2QuotedPrintable.java and 2 shell scripts: kmail-view in system-config and 8bit2=.