Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. (#1321) — 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.
Expand Down
5 changes: 5 additions & 0 deletions internal/cmd/gmail_forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
74 changes: 74 additions & 0 deletions internal/cmd/gmail_forward_html_original_test.go
Original file line number Diff line number Diff line change
@@ -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 <alice@example.com>"},
{"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("<p>Quarterly <b>numbers</b> attached.</p>"),
},
}
}

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("<p>Quarterly <b>numbers</b> attached.</p>")},
},
},
}
}

// 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, "<b>") {
t.Errorf("plain part carries raw HTML:\n%s", plain)
}
if !strings.Contains(html, "<p>Quarterly <b>numbers</b> attached.</p>") {
t.Errorf("HTML part lacks the original:\n%s", html)
}
})
}
}
}
Loading