Skip to content

feat(gmail): add forward command with attachment support#474

Open
brettdavies wants to merge 2 commits intosteipete:mainfrom
brettdavies:feat/gmail-forward
Open

feat(gmail): add forward command with attachment support#474
brettdavies wants to merge 2 commits intosteipete:mainfrom
brettdavies:feat/gmail-forward

Conversation

@brettdavies
Copy link

@brettdavies brettdavies commented Mar 24, 2026

Summary

Add gog gmail forward <messageId> command that forwards an email with all original attachments in a single command. Closes #166.

New flags: --to, --cc, --bcc, --subject, --body, --body-file, --from, --attach (repeatable), --no-attachments

Scope

  • New command: gmail forward in the "Write" group (alias: fwd)
  • Forwards original attachments by default; --no-attachments to strip them
  • --attach adds additional local files alongside forwarded attachments
  • Prepends "Fwd: " to subject (case-insensitive skip if already prefixed); --subject to override
  • Optional body preface via --body / --body-file, inserted before forwarded header block
  • --from for send-as alias support via existing resolveComposeFrom()
  • --json / --plain output consistent with gmail send
  • Thread preservation: sets ThreadId on the sent message so the forward stays in the sender's thread, matching Gmail web UI behavior
  • Reuses existing helpers (buildRFC822, resolveComposeFrom, collectAttachments, fetchAttachmentBytes, writeSendResults) — no existing files modified beyond 1-line command registration in gmail.go

Design notes

  • Reviewed PR feat(gmail): add forward command with tests and helpers #167 by @salmonumbrella which informed the design. Key differences from that PR:
    • Calls resolveComposeFrom() directly instead of creating a new resolveSendFrom() — avoids modifying gmail_send.go
    • Adds --attach for local files and --no-attachments to strip originals
    • Preserves thread (sets ThreadId on sent message)
    • Focused scope: no unrelated docs/drive/time changes
    • Recipients via flags (--to) matching gmail send pattern, not positional args

Testing

  • Unit tests (gmail_forward_test.go): 30 subtests covering forwardSubject, forwardHeaderPlain/HTML, buildForwardBodies, plainToHTML, joinForwardSections
  • Integration tests (execute_gmail_forward_test.go): 7 tests via Execute() with httptest mock servers:
    1. Default subject + attachments
    2. HTML-only message (plain text fallback)
    3. Custom subject override
    4. CC/BCC recipients
    5. --no-attachments strips originals
    6. --attach adds local files alongside originals
    7. --no-attachments + --attach replaces originals with locals
  • All existing tests pass (go test ./...)

Known limitations (v1)

  • Inline images (CID-referenced parts) become regular attachments
  • No --body-html for rich-text preface (plain text auto-escaped for HTML variant)

Files

Created:

  • internal/cmd/gmail_forward.go (264 lines) — command + helpers
  • internal/cmd/gmail_forward_test.go (424 lines) — unit tests
  • internal/cmd/execute_gmail_forward_test.go (763 lines) — integration tests

Modified:

  • internal/cmd/gmail.go (+1 line) — command registration

brettdavies and others added 2 commits March 24, 2026 19:54
Add `gog gmail forward <messageId>` command that forwards an email with
all original attachments in a single command. Supports --to, --cc, --bcc,
--subject, --body/--body-file, --from, --attach (local files), and
--no-attachments flags.

Reuses existing helpers (buildRFC822, resolveComposeFrom, collectAttachments,
fetchAttachmentBytes, writeSendResults) without modifying any existing files
beyond command registration in gmail.go.

Closes steipete#166

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Set ThreadId on the sent message to keep the forward in the sender's
thread, matching Gmail web UI behavior.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
brettdavies added a commit to brettdavies/dotfiles that referenced this pull request Mar 24, 2026
Requirements and implementation plan for contributing a gmail forward
command to steipete/gogcli. PR submitted as steipete/gogcli#474.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
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.

Feature request: Add email forwarding support

1 participant