Bug 4652 - Incorrect multi-RFC2047-encoded-word header field displayed less fault-tolerant than possible.
Summary: Incorrect multi-RFC2047-encoded-word header field displayed less fault-tolera...
Status: NEW
Alias: None
Product: Claws Mail (GTK 2)
Classification: Unclassified
Component: Other (show other bugs)
Version: 3.19.1
Hardware: PC Linux
: P3 enhancement
Assignee: users
URL:
Depends on:
Blocks:
 
Reported: 2022-12-03 11:10 UTC by claws-mail-devel
Modified: 2022-12-08 21:47 UTC (History)
0 users

See Also:


Attachments
proposed patch. (11.18 KB, patch)
2022-12-05 20:39 UTC, claws-mail-devel
no flags Details | Diff
revised patch (13.68 KB, patch)
2022-12-08 21:47 UTC, claws-mail-devel
no flags Details | Diff

Description claws-mail-devel 2022-12-03 11:10:03 UTC
Occasionally I receive mails that include an incorrectly RFC2047 encoded Subject header like:

Subject: =?utf-8?B?TmV3IFRyYWRpdGlvbmFsIENhY2hlOiBNw7xobGdhc3NlbmjD?=
 =?utf-8?B?vHR0ZSAoR0NBMFhKUiksIDguODltaSBOVyAoMTQuM2ttIE5XKQ==?=

This is incorrect as by RFC2047 5.3:
  The 'encoded-text' in an 'encoded-word' must be self-contained;
  'encoded-text' MUST NOT be continued from one 'encoded-word' to
  another.

The decoding is:

Subject: New Traditional Cache: Mühlgassenh<1st byte of 2-byte character>
 <2nd byte of 2-byte character>tte (GCA0XJR), 8.89mi NW (14.3km NW)

Claws-mail displays these Header files in an unreadble way, as it suppresses display of some characters after the incorrect encoding.

Nonetheless, I do receive such emails and I cannot reasonably ask the sender to prepare RFC2047 compliant emails. I would prefer claws-mail to be as fault-tolerant as other mail readers, here.

I have spotted the cause for this behavior in src/common/unmime.c unmime_header() which is (RFC compliant!) parsing MIME encoded headers one encoding after the other. Changing the processing in a way to first collect and decode all subsequent encodings, before conv'ing them into the target character set, would make this behavior more fault-tolerant.

While preparing a patch proposal for this behavior I spotted some other potential flaws when unmime'ing header fields, e.g. in handling of RFC822 quoted-string, for which I'll need deeper analysis before elaborating further.

I'll prepare a patch proposal for src/common/unmime.c unmime_header() and attach it to this bug report, as soon as it seems to be ready for review.
Comment 1 Ricardo Mones 2022-12-03 16:25:49 UTC
You're welcome to attach any patch, of course, but notice that the GTK+2 version (gtk2 branch on git) of Claws Mail is not going to be released anymore¹.

If the GTK3 version has the problem you're describing here, please make the patch against either against the latest release tarball (4.1.1 right now) or the master branch on git.

Thanks in advance!

¹ https://lists.claws-mail.org/pipermail/translators/2022-September/000815.html
Comment 2 claws-mail-devel 2022-12-05 20:39:36 UTC
Created attachment 2311 [details]
proposed patch.

Here's a patch proposal for your kind review, including a test case for the malformed header body.

Note, that there are still issues left:
- patch size not minimized
- lots of debugging messages (commented out)
- handling of encoded-words in addr_fields still missing.

Anyway, I'd like to get guidance, whether the patch (and style) look okay and potentially more test cases.
Comment 3 claws-mail-devel 2022-12-05 20:44:04 UTC
btw: patch applies to GTK3 branch HEAD, too. Didn't test, though.
Comment 4 claws-mail-devel 2022-12-08 21:47:38 UTC
Created attachment 2312 [details]
revised patch

Added more test cases, debugged some stuff.

Note You need to log in before you can comment on or make changes to this bug.