Skip to content

Commit 5df6394

Browse files
feat(gmail): add flattened headers to gmail get JSON output
Add a headers map with common email headers (from, to, cc, bcc, subject, date) to the JSON output of `gog gmail get`. This makes header extraction much simpler: # Before (error-prone due to jq operator precedence) jq '.message.payload.headers[] | select(.name == "To") | .value' # After jq '.headers.to' 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 28a4513 commit 5df6394

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

internal/cmd/gmail_get.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,20 @@ func (c *GmailGetCmd) Run(ctx context.Context, flags *RootFlags) error {
6464
}
6565

6666
if outfmt.IsJSON(ctx) {
67-
return outfmt.WriteJSON(os.Stdout, map[string]any{"message": msg})
67+
// Include a flattened headers map for easier querying
68+
// (e.g., jq '.headers.to' instead of complex nested queries)
69+
headers := map[string]string{
70+
"from": headerValue(msg.Payload, "From"),
71+
"to": headerValue(msg.Payload, "To"),
72+
"cc": headerValue(msg.Payload, "Cc"),
73+
"bcc": headerValue(msg.Payload, "Bcc"),
74+
"subject": headerValue(msg.Payload, "Subject"),
75+
"date": headerValue(msg.Payload, "Date"),
76+
}
77+
return outfmt.WriteJSON(os.Stdout, map[string]any{
78+
"message": msg,
79+
"headers": headers,
80+
})
6881
}
6982

7083
u.Out().Printf("id\t%s", msg.Id)

0 commit comments

Comments
 (0)