perf(gmail): trim message search fields

This commit is contained in:
Peter Steinberger 2026-01-22 01:46:42 +00:00
parent b392e4df6a
commit 417644868a
3 changed files with 59 additions and 3 deletions

View File

@ -4,7 +4,7 @@ Fast, script-friendly CLI for Gmail, Calendar, Chat, Classroom, Drive, Docs, Sli
## Features
- **Gmail** - search threads, send emails, view attachments, manage labels/drafts/filters/delegation/vacation settings, history, and watch (Pub/Sub push)
- **Gmail** - search threads and messages, send emails, view attachments, manage labels/drafts/filters/delegation/vacation settings, history, and watch (Pub/Sub push)
- **Email tracking** - track opens for `gog gmail send --track` with a small Cloudflare Worker backend
- **Calendar** - list/create/update events, detect conflicts, manage invitations, check free/busy status, team calendars, propose new times, focus/OOO/working-location events, recurrence + reminders
- **Classroom** - manage courses, roster, coursework/materials, submissions, announcements, topics, invitations, guardians, profiles
@ -977,7 +977,7 @@ THREAD_ID SUBJECT FROM DATE
16d1c2b3a4e5f6d7 Project update bob@example.com 2025-01-08
```
Message-level search (one row per email):
Message-level search (one row per email; add `--include-body` to fetch/decode bodies):
```bash
$ gog gmail messages search 'newer_than:7d' --max 3
@ -1021,6 +1021,22 @@ $ gog gmail messages search 'newer_than:7d' --max 3 --json
}
```
```bash
$ gog gmail messages search 'newer_than:7d' --max 1 --include-body --json
{
"messages": [
{
"id": "18f1a2b3c4d5e6f7",
"threadId": "9e8d7c6b5a4f3e2d",
"subject": "Meeting notes",
"from": "alice@example.com",
"date": "2025-01-10",
"body": "Hi team — meeting notes..."
}
]
}
```
Data goes to stdout, errors and progress to stderr for clean piping:
```bash

View File

@ -47,6 +47,7 @@ func (c *GmailMessagesSearchCmd) Run(ctx context.Context, flags *RootFlags) erro
Q(query).
MaxResults(c.Max).
PageToken(c.Page).
Fields("messages(id,threadId),nextPageToken").
Context(ctx).
Do()
if err != nil {
@ -151,7 +152,9 @@ func fetchMessageDetails(ctx context.Context, svc *gmail.Service, messages []*gm
if includeBody {
call = call.Format("full")
} else {
call = call.Format("metadata").MetadataHeaders("From", "Subject", "Date")
call = call.Format("metadata").
MetadataHeaders("From", "Subject", "Date").
Fields("id,threadId,labelIds,payload(headers)")
}
msg, err := call.Context(ctx).Do()
if err != nil {

View File

@ -156,6 +156,43 @@ run_gmail_tests() {
fi
run_required "gmail" "gmail search" gog gmail search "subject:gogcli smoke send $TS" --json >/dev/null
local messages_json
echo "==> gmail messages search"
messages_json=$(gog gmail messages search "subject:gogcli smoke send $TS" --json --max 5)
$PY - "$TS" <<'PY' <<<"$messages_json"
import json,sys
ts=sys.argv[1]
obj=json.load(sys.stdin)
msgs=obj.get("messages") or []
if not msgs:
raise SystemExit("no messages found for smoke search")
PY
if skip "gmail-messages-body"; then
echo "==> gmail messages search include body (skipped)"
else
local body_json
echo "==> gmail messages search include body"
body_json=$(gog gmail messages search "subject:gogcli smoke send $TS" --include-body --json --max 5)
if ! $PY - "$TS" <<'PY' <<<"$body_json"; then
import json,sys
ts=sys.argv[1]
obj=json.load(sys.stdin)
msgs=obj.get("messages") or []
needle=f"hello from gogcli {ts}"
for m in msgs:
body=m.get("body") or ""
if needle in body:
sys.exit(0)
raise SystemExit(f"missing body snippet: {needle}")
PY
if [ "${STRICT:-false}" = true ]; then
return 1
fi
fi
fi
run_required "gmail" "gmail batch modify add" gog gmail batch modify "$send_msg_id" --add STARRED --json >/dev/null
run_required "gmail" "gmail batch modify remove" gog gmail batch modify "$send_msg_id" --remove STARRED --json >/dev/null