feat: raw email export, body formats, and code quality refactors#3
Merged
marcfargas merged 4 commits intomainfrom Feb 27, 2026
Merged
feat: raw email export, body formats, and code quality refactors#3marcfargas merged 4 commits intomainfrom
marcfargas merged 4 commits intomainfrom
Conversation
New CLI flags on get and thread commands:
go-gmail <account> get <id> --format=eml [--output=<path>] [--b64encode]
go-gmail <account> thread <id> --format=mbox [--output=<path>] [--b64encode]
Output modes:
--output=<path> write bytes to file → JSON { ok, path, bytes }
--b64encode JSON { format, data, bytes } — agent-safe
(neither) raw bytes to stdout — pipe with > file.eml
Implementation:
src/gmail/raw.ts — getMessageRaw() and getThreadMbox()
- getMessageRaw: messages.get(format=raw) → Buffer
- getThreadMbox: parallel raw fetch per message + mbox assembly
(envelope From lines, CRLF→LF, mboxo escaping)
Also fixes the message/rfc822 attachment bug: --format=eml returns the
complete outer message including embedded .eml attachments, bypassing
the broken attachments.get endpoint.
10 new tests (297/297 total passing)
New output formats for 'go-gmail <account> get <messageId>': --format=text plain text body (body.text) --format=html raw HTML body (body.html) --format=sane-html sanitized HTML (safe to render) sane-html strips: <script>, <iframe>, <object>, <form>, all event handlers (onclick/onerror/onload/…), javascript: hrefs, data: image URIs. Keeps: tables, style attributes, cid: images, all layout tags. Adds rel=noopener noreferrer to target=_blank links. All formats support --output=<path> and --b64encode, matching the existing eml/mbox output contract. New: src/gmail/formats.ts — sanitizeEmailHtml() using sanitize-html New dep: sanitize-html (+ @types/sanitize-html) 25 new tests (322/322 total passing)
… code - Extract parseFlags/readBodyFlags to src/bin/gmail-flags.ts (tests now import production code instead of local copies) - Extract gmailApi/handleApiError to src/gmail/api.ts (eliminates byte-for-byte duplication between index.ts and raw.ts) - Extract serializeMimePart() helper, used by both buildMimeMessage and buildForwardMime (eliminates 6-line copy-paste) - Remove duplicate error-handling describe block in index.test.ts - Remove dead 'lookup' import from helpers.ts - Fix handleRawOutput return type: unknown|undefined → object|undefined
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three feature commits + one refactor commit + changesets for 0.4.0.
feat:
--format=eml/--format=mbox(raw RFC 2822 export)go-gmail get <id> --format=eml— full RFC 2822 message bytesgo-gmail thread <id> --format=mbox— full thread as mbox--output=<path>/--b64encodeoutput modesmessage/rfc822embedded attachment retrieval (bypasses brokenattachments.get)feat:
--format=text|html|sane-htmlforgetsane-html: sanitized viasanitize-html(strips scripts, events, javascript: URIs)refactor: extract shared helpers, fix test copies, remove dead code
parseFlags/readBodyFlags→src/bin/gmail-flags.tsgmailApi/handleApiError→src/gmail/api.tsserializeMimePart()MIME helperchore: changesets for 0.4.0
Three changeset files — changesets/action will bump to
0.4.0on merge.Tests
320/322 passing (−2 intentionally deleted duplicate tests)