Skip to content

feat: render HTML-only emails as readable text in mail read#9

Merged
gumruyanzh merged 1 commit into
mainfrom
feat/html-to-text-read
Jul 5, 2026
Merged

feat: render HTML-only emails as readable text in mail read#9
gumruyanzh merged 1 commit into
mainfrom
feat/html-to-text-read

Conversation

@gumruyanzh

Copy link
Copy Markdown
Contributor

Summary

mail read on an HTML-only message used to print raw markup (<html>, inline <style>, scripts). This renders it as clean readable text instead.

  • HTMLToText (internal/yahoo/html.go, via golang.org/x/net/html): drops script/style/head/title/noscript, inserts line breaks around block-level elements and <br>, unescapes entities, and collapses whitespace.
  • Message.DisplayBody(): prefers a genuine text/plain part; only renders HTML when that's the sole body. Raw Body/HTMLBody are untouched.
  • Wired into the table and plain (human) formatters only — JSON output stays lossless (raw body/html_body preserved for scripting).
  • Unit tests for HTMLToText (script/style stripping, <br>, entities) and DisplayBody (plain-preferred, HTML fallback).

Verification

  • gofmt/go vet/go build clean; go test ./... green.
  • Live: reading a real HTML-only Yahoo notice now shows formatted text; --json still returns raw HTML in body/html_body.

🤖 Generated with Claude Code

Reading an HTML-only message previously dumped raw markup (<html>, inline
<style>, etc.). Add HTMLToText (x/net/html): it strips script/style/head,
inserts line breaks around block elements, unescapes entities, and
collapses whitespace. A new Message.DisplayBody() prefers a genuine
text/plain part and only renders HTML when that's all there is.

Wired into the table and plain (human) formatters only — JSON output
keeps raw body/html_body so it stays lossless for scripting.

Adds unit tests for HTMLToText and DisplayBody.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gumruyanzh gumruyanzh merged commit bac1aa4 into main Jul 5, 2026
@gumruyanzh gumruyanzh deleted the feat/html-to-text-read branch July 5, 2026 06:16
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