Skip to content

Fix thread decode errors - #145

Open
The-Compiler wants to merge 2 commits into
akissinger:masterfrom
The-Compiler:fix-thread-decode-errors
Open

The-Compiler wants to merge 2 commits into
akissinger:masterfrom
The-Compiler:fix-thread-decode-errors

Conversation

@The-Compiler

Copy link
Copy Markdown
Collaborator

I got a mail which has Content-Type: text/plain with no charset, and hence should be US-ASCII: https://www.rfc-editor.org/info/rfc2045/#section-5.2

However, the mail contains German umlauts encoded as ISO-8859-1 (e.g. ü as =FC in quoted-printable). Despite man notmuch-show claiming:

The JSON output is always encoded as UTF-8 and any message content included in the output will be charset-converted to UTF-8.

the output as shown by

notmuch show --format=json mid:6A79497BAB764AB38C7F0BA1607B46BF@ad.ugs.net

does contain a literal e.g. 0xFC byte in place of the ü.

Passing binary data to Python's json.loads does not help, because it still expects one of UTF-{8,16,32} as per the JSON standard.

Instead of crashing, use errors="replace", which instead replaces the problematic bytes with � (U+FFFD, REPLACEMENT CHARACTER). It's somewhat questionable to do this for machine-parsed output (as it's technically silent data corruption). However, e.g. attachments take a different code path and we assume "raw" data fields to be correct notmuch output. Thus, this should only ever reach the message text as shown to the user, where this seems the correct strategy.

As a drive-by fix, handle refresh errors more gracefully: Before, we opened an empty (no subject) panel when refreshing failed. Instead, refuse to open a panel.

I got a mail which has `Content-Type: text/plain` with no `charset`, and hence
should be US-ASCII: https://www.rfc-editor.org/info/rfc2045/#section-5.2

However, the mail contains German umlauts encoded as ISO-8859-1 (e.g. ü as =FC
in quoted-printable). Despite `man notmuch-show` claiming:

    The JSON output is always encoded as UTF-8 and any message content included
    in the output will be charset-converted to UTF-8.

the output as shown by

    notmuch show --format=json mid:6A79497BAB764AB38C7F0BA1607B46BF@ad.ugs.net

*does* contain a literal e.g. 0xFC byte in place of the ü.

Passing binary data to Python's json.loads does not help, because it still
expects one of UTF-{8,16,32} as per the JSON standard.

Instead of crashing, use errors="replace", which instead replaces the
problematic bytes with � (U+FFFD, REPLACEMENT CHARACTER). It's somewhat
questionable to do this for machine-parsed output (as it's technically silent
data corruption). However, e.g. attachments take a different code path and we
assume "raw" data fields to be correct notmuch output. Thus, this should only
ever reach the message text as shown to the user, where this seems the correct
strategy.
Before, we opened an empty (no subject) panel when refreshing failed. Instead, refuse to open a panel.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant