Skip to content

fix(gmail): forward the HTML body as text when the original has no plain part - #1321

Closed
saariuslystoned wants to merge 2 commits into
openclaw:mainfrom
saariuslystoned:fix/gmail-forward-html-only-plain
Closed

saariuslystoned wants to merge 2 commits into
openclaw:mainfrom
saariuslystoned:fix/gmail-forward-html-only-plain

Conversation

@saariuslystoned

@saariuslystoned saariuslystoned commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

What problem this solves

gmail forward and gmail drafts forward build the forward's plain-text part from the original's text/plain body. When the original has no plain-text part (an HTML-only message), or a blank one, the plain part holds only the "Forwarded message" headers and no body:

---------- Forwarded message ---------
From: Alice <alice@example.com>
Date: Tue, Mar 10, 2026 at 1:00 PM
Subject: Quarterly

The HTML part is correct. Anyone whose client shows the plain alternative, or a script that reads it, sees an empty forward. Reply already handles this case: applyQuoteToBodies converts the HTML with htmlToPlainText when the original's plain body is blank.

Change

When the original's plain body is empty or whitespace-only and it has an HTML body, the forward converts that HTML with the existing htmlToPlainText and uses the result as the forwarded plain body. Originals with a usable plain part are unchanged, and so is the HTML part.

Evidence

  • TestGmailForward_PlainPartCarriesHTMLOnlyOriginal runs gmail forward and gmail drafts forward through the CLI entry point against the existing forward test server, for an HTML-only original and for one whose plain part is " \r\n". On main (e8428c3) all four cases fail with the headers-only plain part shown above. With this change the plain part contains Quarterly numbers attached. with no markup, and the HTML part still carries the original HTML. The existing forward, reply, quote and drafts tests pass.

  • Built gog binaries from main and from this branch were run against a local Gmail stand-in through GOG_GOOGLE_API_BASE_URL (not Google) that decodes each messages.send body:

    $ gog --account probe@example.com gmail forward html1 --to carol@example.com
    main:   text/plain part = forwarded headers only
    branch: text/plain part = forwarded headers, then "Quarterly numbers attached."
    
  • Every make ci step passed on 1c12bd7 (go1.27.3). The Go test suite (go test -count=1 ./...) ran on a second macOS arm64 machine, and the fmt, lint, deadcode, docs, agent-skills and node checks ran locally.

No live mailbox was used and no message was sent.

🤖 Generated with Claude Code

…ain part

gmail forward and gmail drafts forward copied the original's text/plain body into the forward's plain part. An HTML-only original, or one with a whitespace-only plain part, left that part with the forwarded headers and no body. Convert the HTML to text, as the reply quote already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 8, 2026
@clawsweeper

clawsweeper Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR converts an original message’s HTML to text when forwarding a message with no usable plain-text body.

Example: Forward an HTML-only message containing <p>Quarterly <b>numbers</b> attached.</p> to carol@example.com.

  • Before: The forwarded plain-text alternative contains forwarded headers without the original body.
  • After: The plain-text alternative also contains “Quarterly numbers attached.” while the HTML alternative retains the original HTML.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct fix with relevant shipped-CLI MIME evidence and shared send/draft regression coverage; supplied proof does not claim live Gmail delivery.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The supplied macOS arm64 terminal evidence exercises built gog binaries through gmail forward against a local HTTP Gmail stand-in and shows the decoded outgoing plain MIME part gaining the original text; shared-builder tests additionally cover draft forwarding and whitespace-only plain parts.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Recipients reading the plain-text alternative of a forwarded HTML-only message cannot read its original body.
Reason: Preserving the original body fulfills the forward command’s existing purpose and matches reply behavior without changing user options.

Merge readiness

✅ Ready for maintainer review

Keep this PR: current main still produces headers-only plain alternatives for HTML-only originals, and this focused fix introduces no actionable defect.

Priority: P2
Reviewed head: 1c12bd78c3d999125d6d41bc18e0b909794735a3

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gmail send-forward and draft-forward share a composition builder that fetches the original message, constructs MIME alternatives and attachments, and passes the result to Gmail’s send or draft endpoint.

flowchart TD
  A[Forward CLI] --> C[Shared forward builder]
  B[Draft forward CLI] --> C
  D[Original Gmail message] --> C
  C --> E[Existing HTML to text converter]
  E --> F[Outgoing MIME alternatives]
  C --> F
  F --> G[Gmail send or draft endpoint]
Loading

Technical review

Best possible solution:

Land the fallback in the existing shared forward builder so both sending and drafting preserve readable original text.

Do we have a high-confidence way to reproduce the issue?

Current-main source deterministically builds a headers-only plain alternative for an HTML-only original; the contributor also records before/after CLI output, but no target code was run during this read-only review.

Is this the best way to solve the issue?

The patch addresses the missing conversion at the shared forward owner and reuses reply’s converter without adding flags, dependencies, or a parallel composition path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against e8428c36dd31.

Provenance checked

  • Forwarded original body selection keeps the original intent (13a1aae: The original forward feature constructs plain and HTML alternatives from the corresponding source parts; its stated purpose includes forwarding original content, with no documented intent to omit HTML-only content from plain output.)
  • Inbound content decoder ownership keeps the original intent (8a58cf7: The decoder extraction replaced findPartBody with gmailcontent.FindPartBody without changing forward-body selection.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Current main retains the defect: The builder independently reads text/plain and text/html, then passes the plain result directly into the forwarded plain body without HTML fallback. (internal/cmd/gmail_forward.go:190, e8428c36dd31)
  • Focused introduced change: The production change adds only a whitespace-aware fallback using the existing converter; the shared builder covers send-forward and draft-forward. (internal/cmd/gmail_forward.go:194, 1c12bd78c3d9)
  • Existing reply contract: applyQuoteToBodies already performs the same whitespace-aware HTML-to-text fallback for quoted originals. (internal/cmd/gmail_reply.go:302, e8428c36dd31)
  • Prior fix explicitly excludes forwarding: The merged body-selection fix at fix(gmail): fall back to HTML when the plain body is only whitespace #1279 expressly states that gmail forward reads text/plain directly and remains affected. (33375c916db4)
  • Original forward behavior and decoder refactor: The original forward implementation passed the plain body directly into formatting; the later decoder extraction only renamed the lookup owner. The original feature rationale is recorded at feat(gmail): add forward command #482. (internal/cmd/gmail_forward.go:190, 8a58cf7d0b12)
  • Behavior proof supplied: The complete PR body records built main and branch binaries invoking gmail forward against a local HTTP Gmail stand-in that decodes messages.send: the branch includes “Quarterly numbers attached.” in text/plain. This exercises the changed MIME construction through the shipped CLI; no live Gmail delivery is claimed. Captured source identity: 2cd1873a71e1c9e70c128cd05f1fb166d0098c7dc8789f41307aeaefecc1cec5. (1c12bd78c3d9)

Likely related people:

  • Malo Bourgon: Raw commit d48a86f adds internal/cmd/gmail_forward.go:209 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d48a86fb3fba; files: internal/cmd/gmail_forward.go)
  • spencer-c-reed: Raw commit 13a1aae adds internal/cmd/gmail_forward.go:79 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 13a1aaea1348; files: internal/cmd/gmail_forward.go)

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Change scope Production +5 lines; tests +74; changelog +2 The small shared-owner fix is supported by distinct send/draft and HTML-only/blank-plain regression cases using existing test infrastructure.

Labels

Label changes:

  • add P2: Plain-text recipients and scripts lose the forwarded original body for HTML-only or blank-plain originals, while the HTML alternative remains available.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Plain-text recipients and scripts lose the forwarded original body for HTML-only or blank-plain originals, while the HTML alternative remains available.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 8, 2026, 3:23 PM ET / 20:23 UTC.

steipete added a commit that referenced this pull request Nov 14, 2026
Consolidate reproduced command bugs from #1308, #1311-#1319, #1321-#1326 and issues #1328, #1329, #1330, #1331, #1335.

Co-authored-by: Bobby Bones <159389674+saariuslystoned@users.noreply.github.com>
Co-authored-by: Sebastien Tardif <sebtardif@ncf.ca>
@steipete

Copy link
Copy Markdown
Collaborator

Thank you for the fix. I reproduced the claim and consolidated including an HTML-only original in the plain-text forwarded body into #1336, with regression coverage and your coauthor credit retained. The full make ci gate, built-CLI checks for the new request-validation fixes, and exact-head GitHub CI passed. Closing this PR as superseded by the merged implementation in #1336.

@steipete steipete closed this Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants