From 1a8a231490ae5301d49a95d2c412b510ed9a1084 Mon Sep 17 00:00:00 2001 From: Bobby Bones <159389674+saariuslystoned@users.noreply.github.com> Date: Sun, 8 Nov 2026 14:34:10 -0500 Subject: [PATCH 1/2] fix(gmail): forward the HTML body as text when the original has no plain 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 --- CHANGELOG.md | 2 + internal/cmd/gmail_forward.go | 5 ++ .../cmd/gmail_forward_html_original_test.go | 74 +++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 internal/cmd/gmail_forward_html_original_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 861521fad..9ba4fd5e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.48.1 - Unreleased +- Gmail: carry the original body in the plain-text part of `gmail forward` and `gmail drafts forward` when the original has only HTML or a blank plain-text part, converting the HTML to text as a reply's plain quote already does. The plain part previously held the forwarded headers and no body. — thanks @saariuslystoned. + ## 0.48.0 - 2026-11-05 **Highlights:** New backups stay local until you configure a remote; existing configurations keep working. Store service-account keys in the keyring, search Gmail IDs efficiently, and use environment-backed watch tokens, with Calendar fixes and security dependency updates. diff --git a/internal/cmd/gmail_forward.go b/internal/cmd/gmail_forward.go index b063bb2a0..c0c24f252 100644 --- a/internal/cmd/gmail_forward.go +++ b/internal/cmd/gmail_forward.go @@ -189,6 +189,11 @@ func (c *GmailForwardOptions) buildForwardComposeMessage(ctx context.Context, sv origSubject := headerValue(origMsg.Payload, "Subject") origPlain := gmailcontent.FindPartBody(origMsg.Payload, "text/plain") origHTML := gmailcontent.FindPartBody(origMsg.Payload, "text/html") + // An original with no usable plain text still forwards its body in the + // plain part, as a reply's plain quote does. + if strings.TrimSpace(origPlain) == "" && strings.TrimSpace(origHTML) != "" { + origPlain = htmlToPlainText(origHTML) + } // Build forward subject (avoid stacking prefixes). fwdSubject := buildForwardSubject(origSubject) diff --git a/internal/cmd/gmail_forward_html_original_test.go b/internal/cmd/gmail_forward_html_original_test.go new file mode 100644 index 000000000..41212e3eb --- /dev/null +++ b/internal/cmd/gmail_forward_html_original_test.go @@ -0,0 +1,74 @@ +package cmd + +import ( + "encoding/base64" + "strings" + "testing" +) + +func encodeForwardPart(s string) map[string]any { + data := base64.RawURLEncoding.EncodeToString([]byte(s)) + return map[string]any{"data": data, "size": len(data)} +} + +func forwardOriginalHeaders(subject string) []map[string]any { + return []map[string]any{ + {"name": "From", "value": "Alice "}, + {"name": "Date", "value": "Mon, 10 Mar 2026 09:00:00 -0400"}, + {"name": "Subject", "value": subject}, + } +} + +func mockHTMLOnlyForwardSource() map[string]any { + return map[string]any{ + "id": "orig-msg-1", "threadId": "thread-1", + "payload": map[string]any{ + "mimeType": "text/html", + "headers": forwardOriginalHeaders("HTML original"), + "body": encodeForwardPart("

Quarterly numbers attached.

"), + }, + } +} + +func mockBlankPlainForwardSource() map[string]any { + return map[string]any{ + "id": "orig-msg-1", "threadId": "thread-1", + "payload": map[string]any{ + "mimeType": "multipart/alternative", + "headers": forwardOriginalHeaders("Blank plain original"), + "parts": []map[string]any{ + {"mimeType": "text/plain", "body": encodeForwardPart(" \r\n")}, + {"mimeType": "text/html", "body": encodeForwardPart("

Quarterly numbers attached.

")}, + }, + }, + } +} + +// When the original has no usable plain text, the forward's plain part carries +// the HTML body as text, as a reply's plain quote already does. +func TestGmailForward_PlainPartCarriesHTMLOnlyOriginal(t *testing.T) { + t.Setenv("GOG_TIMEZONE", "UTC") + for _, cmd := range forwardCommands { + for _, src := range []struct { + name string + source func() map[string]any + }{ + {name: "HTML-only original", source: mockHTMLOnlyForwardSource}, + {name: "blank plain part", source: mockBlankPlainForwardSource}, + } { + t.Run(cmd.name+"/"+src.name, func(t *testing.T) { + plain, html := forwardTextParts(t, forwardArgs(cmd.verb), cmd.finalizePath, src.source) + _, body, _ := strings.Cut(plain, forwardedSeparator) + if !strings.Contains(body, "Quarterly numbers attached.") { + t.Errorf("plain part lacks the original body:\n%s", plain) + } + if strings.Contains(body, "") { + t.Errorf("plain part carries raw HTML:\n%s", plain) + } + if !strings.Contains(html, "

Quarterly numbers attached.

") { + t.Errorf("HTML part lacks the original:\n%s", html) + } + }) + } + } +} From 1c12bd78c3d999125d6d41bc18e0b909794735a3 Mon Sep 17 00:00:00 2001 From: Bobby Bones <159389674+saariuslystoned@users.noreply.github.com> Date: Sun, 8 Nov 2026 15:08:15 -0500 Subject: [PATCH 2/2] docs(changelog): reference #1321 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ba4fd5e0..9f3ecf7b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 0.48.1 - Unreleased -- Gmail: carry the original body in the plain-text part of `gmail forward` and `gmail drafts forward` when the original has only HTML or a blank plain-text part, converting the HTML to text as a reply's plain quote already does. The plain part previously held the forwarded headers and no body. — thanks @saariuslystoned. +- Gmail: carry the original body in the plain-text part of `gmail forward` and `gmail drafts forward` when the original has only HTML or a blank plain-text part, converting the HTML to text as a reply's plain quote already does. The plain part previously held the forwarded headers and no body. (#1321) — thanks @saariuslystoned. ## 0.48.0 - 2026-11-05