Repository navigation
Show the text of HTML-only emails in the preview - #42
Merged
Merged
Conversation
JMAP lists the only part of an HTML-only email both as its HTML body and as its text body. The preview prefers the text body and used it as-is, so such an email showed its HTML source: tags, styles and all. A text/html part in the text body now goes through htmlToText(), like the HTML body does.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
An email with only an HTML body showed its HTML source in the hover preview: tags, styles and all.
JMAP (RFC 8621) lists the only part of an HTML-only email both as its
htmlBodyand as itstextBody. The preview preferstextBodyand used its value as-is. That was safe, since the text was escaped, but unreadable. It also made CLAUDE.md's "shows an HTML-only body as plain text" untrue.Fix
In
loadPreviewBody(), atext/htmlpart found intextBodynow goes throughhtmlToText()(added in #40), like thehtmlBodyparts do. Plain-text parts are unchanged. All HTML the preview shows is now turned into text by that one function, which loads nothing and runs nothing.CLAUDE.md's Email Preview entry explains why a
text/htmlpart can appear intextBody.Tests
e2e/tests/preview-html.spec.jsgets a third body shape: an HTML-only email as JMAP sends it, with the same part intextBodyandhtmlBody. Every shape now also checks that the preview shows no<p>markup.main: the new shape fails 5 runs out of 5, because the preview shows the HTML source. The other two shapes pass, since nothing loads or runs.go test -raceandgo vetpass.Testing on Fastmail
git pull, restart the app (go run main.go) and reload the page.