diff --git a/.agents/skills/gog-admin/SKILL.md b/.agents/skills/gog-admin/SKILL.md index 972a4000f..d0855e0d5 100644 --- a/.agents/skills/gog-admin/SKILL.md +++ b/.agents/skills/gog-admin/SKILL.md @@ -1,6 +1,6 @@ --- name: gog-admin -description: "Workspace Admin operations through gog." +description: "Workspace Admin through gog. Use for Workspace Admin Directory users, groups, and organizational units; use gog-groups for Cloud Identity group membership lookup." --- # Workspace Admin diff --git a/.agents/skills/gog-adsense/SKILL.md b/.agents/skills/gog-adsense/SKILL.md index cf8f768ff..557059e69 100644 --- a/.agents/skills/gog-adsense/SKILL.md +++ b/.agents/skills/gog-adsense/SKILL.md @@ -1,6 +1,6 @@ --- name: gog-adsense -description: "Google AdSense operations through gog." +description: "Google AdSense through gog. Use for AdSense accounts, sites, payments, and earnings reports." --- # Google AdSense diff --git a/.agents/skills/gog-analytics/SKILL.md b/.agents/skills/gog-analytics/SKILL.md index 246b34b13..ca60d6785 100644 --- a/.agents/skills/gog-analytics/SKILL.md +++ b/.agents/skills/gog-analytics/SKILL.md @@ -1,6 +1,6 @@ --- name: gog-analytics -description: "Google Analytics operations through gog." +description: "Google Analytics through gog. Use for Google Analytics account summaries and GA4 reports." --- # Google Analytics diff --git a/.agents/skills/gog-appscript/SKILL.md b/.agents/skills/gog-appscript/SKILL.md index 6e03c3886..433821d90 100644 --- a/.agents/skills/gog-appscript/SKILL.md +++ b/.agents/skills/gog-appscript/SKILL.md @@ -1,6 +1,6 @@ --- name: gog-appscript -description: "Apps Script operations through gog." +description: "Apps Script through gog. Use for Apps Script projects, source files, deployments, and executions." --- # Apps Script diff --git a/.agents/skills/gog-calendar/SKILL.md b/.agents/skills/gog-calendar/SKILL.md index 865104921..57ebd470c 100644 --- a/.agents/skills/gog-calendar/SKILL.md +++ b/.agents/skills/gog-calendar/SKILL.md @@ -1,6 +1,6 @@ --- name: gog-calendar -description: "Google Calendar operations through gog." +description: "Google Calendar through gog. Use for calendars, events, availability, and scheduling; use gog-meeting-prep for meeting briefings or gog-weekly-digest for a cross-service summary." --- # Google Calendar @@ -53,6 +53,7 @@ gog --readonly --account user@example.com calendar events --today --json --wrap- | `time` | Show server time | | `unsubscribe` | Remove a calendar from your calendar list | | `update` | Update an event | +| `update-calendar` | Update calendar-level settings (summary, description, location, timezone) | | `users` | List workspace users (use their email as calendar ID) | | `working-location` | Set working location (home/office/custom) | diff --git a/.agents/skills/gog-chat/SKILL.md b/.agents/skills/gog-chat/SKILL.md index dbcf6b049..1c1e92898 100644 --- a/.agents/skills/gog-chat/SKILL.md +++ b/.agents/skills/gog-chat/SKILL.md @@ -1,6 +1,6 @@ --- name: gog-chat -description: "Google Chat operations through gog." +description: "Google Chat through gog. Use for Google Chat spaces, messages, threads, and members." --- # Google Chat @@ -15,7 +15,7 @@ output, safety, and live-write rules. ```bash gog auth list --check --json --no-input gog schema chat --json -gog --readonly --account user@example.com chat --help +gog --readonly --account user@example.com chat messages list spaces/SPACE_ID --full --json --wrap-untrusted ``` - Select the account explicitly with `--account`. @@ -24,6 +24,17 @@ gog --readonly --account user@example.com chat --help - Use `--no-input` in automation and `--dry-run` before supported writes. - Confirm the exact account, object, and mutation before any write or delete. +## Rich messages + +- List/search default to compact output; add `--full --json` for full SDK-known message content. This is typed JSON, not raw/lossless output. +- `messages get spaces/SPACE/messages/MESSAGE --json` returns a full message; bare IDs require `--space`. +- `--view full` is a search provider option for read/mute metadata, independent of `--full`. List/search/get accept `--markup chat|markdown`. +- Full output includes card, image, GIF, and attachment metadata/URLs; it never fetches image or attachment bytes. +- Use `--wrap-untrusted` for nested card text, labels, filenames and alt text, including with `--results-only --select`. +- `messages update` (alias `edit`) requires `--text` and patches only text. Explicit empty text is sent; provider validation still applies. +- `messages delete` requires confirmation; root `--force` bypasses only the CLI prompt. `--delete-replies` separately enables Google's threaded-reply deletion. +- Preview mutations with `--dry-run`. Readonly blocks mutations. Google ownership/permissions still apply; these commands cannot edit app cards. + ## Commands | Command | Purpose | diff --git a/.agents/skills/gog-classroom/SKILL.md b/.agents/skills/gog-classroom/SKILL.md index bf2aa47ac..99c1b858a 100644 --- a/.agents/skills/gog-classroom/SKILL.md +++ b/.agents/skills/gog-classroom/SKILL.md @@ -1,6 +1,6 @@ --- name: gog-classroom -description: "Google Classroom operations through gog." +description: "Google Classroom through gog. Use for Classroom courses, rosters, coursework, submissions, and announcements." --- # Google Classroom diff --git a/.agents/skills/gog-contacts/SKILL.md b/.agents/skills/gog-contacts/SKILL.md index cc9a3bf5a..d98da87d1 100644 --- a/.agents/skills/gog-contacts/SKILL.md +++ b/.agents/skills/gog-contacts/SKILL.md @@ -1,6 +1,6 @@ --- name: gog-contacts -description: "Google Contacts operations through gog." +description: "Google Contacts through gog. Use for personal contacts, contact groups, and other contacts, with directory lookup also available; use gog-people for the caller profile or Workspace directory profiles." --- # Google Contacts diff --git a/.agents/skills/gog-docs/SKILL.md b/.agents/skills/gog-docs/SKILL.md index 88093aff0..6d6b1b17d 100644 --- a/.agents/skills/gog-docs/SKILL.md +++ b/.agents/skills/gog-docs/SKILL.md @@ -1,6 +1,6 @@ --- name: gog-docs -description: "Google Docs operations through gog." +description: "Google Docs through gog. Use for Google Docs text, formatting, tabs, comments, and document exports." --- # Google Docs diff --git a/.agents/skills/gog-drive/SKILL.md b/.agents/skills/gog-drive/SKILL.md index 66757f4a8..6debd3b57 100644 --- a/.agents/skills/gog-drive/SKILL.md +++ b/.agents/skills/gog-drive/SKILL.md @@ -1,6 +1,6 @@ --- name: gog-drive -description: "Google Drive operations through gog." +description: "Google Drive through gog. Use for Drive file search, uploads, downloads, sharing, folders, and metadata; use gog-drive-audit for a sharing audit." --- # Google Drive diff --git a/.agents/skills/gog-forms/SKILL.md b/.agents/skills/gog-forms/SKILL.md index b44581032..db37be428 100644 --- a/.agents/skills/gog-forms/SKILL.md +++ b/.agents/skills/gog-forms/SKILL.md @@ -1,6 +1,6 @@ --- name: gog-forms -description: "Google Forms operations through gog." +description: "Google Forms through gog. Use for Google Forms structure, questions, responses, and watches." --- # Google Forms diff --git a/.agents/skills/gog-gmail/SKILL.md b/.agents/skills/gog-gmail/SKILL.md index 8953bffdd..1139fa820 100644 --- a/.agents/skills/gog-gmail/SKILL.md +++ b/.agents/skills/gog-gmail/SKILL.md @@ -1,6 +1,6 @@ --- name: gog-gmail -description: "Gmail operations through gog." +description: "Gmail through gog. Use for Gmail search, messages, threads, drafts, sending, labels, filters, and settings; use gog-inbox-triage for inbox review or gog-save-attachments for attachment archival." --- # Gmail diff --git a/.agents/skills/gog-groups/SKILL.md b/.agents/skills/gog-groups/SKILL.md index 44d70dbad..fcd123047 100644 --- a/.agents/skills/gog-groups/SKILL.md +++ b/.agents/skills/gog-groups/SKILL.md @@ -1,6 +1,6 @@ --- name: gog-groups -description: "Google Groups operations through gog." +description: "Google Groups through gog. Use for listing Cloud Identity groups and members; use gog-admin to manage Workspace Admin Directory groups." --- # Google Groups diff --git a/.agents/skills/gog-keep/SKILL.md b/.agents/skills/gog-keep/SKILL.md index 5913cd17c..577f2a044 100644 --- a/.agents/skills/gog-keep/SKILL.md +++ b/.agents/skills/gog-keep/SKILL.md @@ -1,6 +1,6 @@ --- name: gog-keep -description: "Google Keep operations through gog." +description: "Google Keep through gog. Use for Google Keep notes and attachments." --- # Google Keep diff --git a/.agents/skills/gog-maps/SKILL.md b/.agents/skills/gog-maps/SKILL.md index 1f5c0d17e..53164bdbe 100644 --- a/.agents/skills/gog-maps/SKILL.md +++ b/.agents/skills/gog-maps/SKILL.md @@ -1,6 +1,6 @@ --- name: gog-maps -description: "Google Maps operations through gog." +description: "Google Maps through gog. Use for Maps place search, place details, directions, and geocoding." --- # Google Maps diff --git a/.agents/skills/gog-meet/SKILL.md b/.agents/skills/gog-meet/SKILL.md index f20bb4000..1c54e15ed 100644 --- a/.agents/skills/gog-meet/SKILL.md +++ b/.agents/skills/gog-meet/SKILL.md @@ -1,6 +1,6 @@ --- name: gog-meet -description: "Google Meet operations through gog." +description: "Google Meet through gog. Use for Google Meet spaces, configuration, call history, and participants." --- # Google Meet diff --git a/.agents/skills/gog-people/SKILL.md b/.agents/skills/gog-people/SKILL.md index 37df010f1..0bd10a2ec 100644 --- a/.agents/skills/gog-people/SKILL.md +++ b/.agents/skills/gog-people/SKILL.md @@ -1,6 +1,6 @@ --- name: gog-people -description: "Google People operations through gog." +description: "Google People through gog. Use for the caller profile, a person profile, or Workspace directory search; use gog-contacts to manage personal contacts and contact groups." --- # Google People diff --git a/.agents/skills/gog-photos/SKILL.md b/.agents/skills/gog-photos/SKILL.md index 41fc1f927..0ce4de68d 100644 --- a/.agents/skills/gog-photos/SKILL.md +++ b/.agents/skills/gog-photos/SKILL.md @@ -1,6 +1,6 @@ --- name: gog-photos -description: "Google Photos operations through gog." +description: "Google Photos through gog. Use for Google Photos media and albums available to the app, including uploads and the picker." --- # Google Photos diff --git a/.agents/skills/gog-searchconsole/SKILL.md b/.agents/skills/gog-searchconsole/SKILL.md index d0cc78b7a..c58a9971f 100644 --- a/.agents/skills/gog-searchconsole/SKILL.md +++ b/.agents/skills/gog-searchconsole/SKILL.md @@ -1,6 +1,6 @@ --- name: gog-searchconsole -description: "Google Search Console operations through gog." +description: "Google Search Console through gog. Use for Search Console sites, search analytics, sitemaps, and URL inspection." --- # Google Search Console diff --git a/.agents/skills/gog-sheets/SKILL.md b/.agents/skills/gog-sheets/SKILL.md index e5837fc1a..31c609668 100644 --- a/.agents/skills/gog-sheets/SKILL.md +++ b/.agents/skills/gog-sheets/SKILL.md @@ -1,6 +1,6 @@ --- name: gog-sheets -description: "Google Sheets operations through gog." +description: "Google Sheets through gog. Use for spreadsheet cells, formulas, formatting, notes, validation, and sheet structure." --- # Google Sheets diff --git a/.agents/skills/gog-sites/SKILL.md b/.agents/skills/gog-sites/SKILL.md index 3214084c6..6dc508db8 100644 --- a/.agents/skills/gog-sites/SKILL.md +++ b/.agents/skills/gog-sites/SKILL.md @@ -1,6 +1,6 @@ --- name: gog-sites -description: "Google Sites operations through gog." +description: "Google Sites through gog. Use for finding Google Sites in Drive, reading site metadata, and printing editor URLs; use gog-drive for file sharing." --- # Google Sites diff --git a/.agents/skills/gog-slides/SKILL.md b/.agents/skills/gog-slides/SKILL.md index 291381886..f6d464c3a 100644 --- a/.agents/skills/gog-slides/SKILL.md +++ b/.agents/skills/gog-slides/SKILL.md @@ -1,6 +1,6 @@ --- name: gog-slides -description: "Google Slides operations through gog." +description: "Google Slides through gog. Use for presentations, slides, text, images, speaker notes, and exports." --- # Google Slides diff --git a/.agents/skills/gog-tasks/SKILL.md b/.agents/skills/gog-tasks/SKILL.md index 2be3ae1a6..a533fc981 100644 --- a/.agents/skills/gog-tasks/SKILL.md +++ b/.agents/skills/gog-tasks/SKILL.md @@ -1,6 +1,6 @@ --- name: gog-tasks -description: "Google Tasks operations through gog." +description: "Google Tasks through gog. Use for Google Tasks lists, task creation, updates, completion, and materialized repeats." --- # Google Tasks diff --git a/.agents/skills/gog-youtube/SKILL.md b/.agents/skills/gog-youtube/SKILL.md index 974dda9eb..530fe5992 100644 --- a/.agents/skills/gog-youtube/SKILL.md +++ b/.agents/skills/gog-youtube/SKILL.md @@ -1,6 +1,6 @@ --- name: gog-youtube -description: "YouTube operations through gog." +description: "YouTube through gog. Use for YouTube search, videos, channels, activities, comments, playlists, and subscriptions." --- # YouTube diff --git a/.agents/skills/gog/SKILL.md b/.agents/skills/gog/SKILL.md index 3084ce975..109a49972 100644 --- a/.agents/skills/gog/SKILL.md +++ b/.agents/skills/gog/SKILL.md @@ -1,6 +1,6 @@ --- name: gog -description: "gog CLI: safe Google Workspace automation, JSON, auth, scoped reads/writes." +description: "Use the gog CLI when Google connectors lack an operation, shell automation needs stable JSON, or local Google auth needs inspection. Shared account, auth, output, and safety guidance for all gog service skills." --- # gog @@ -91,6 +91,11 @@ account's existing `services`. When replacing an expired or revoked token, do not silently reduce scope; prefer `--services all-user --force-consent` unless the user explicitly asks for narrower scopes. +`all-user` excludes Google Ads (`ads`). Google can require passkey enrollment +before granting the Ads scope, which blocks the whole consent flow, so do not +add `ads` to a routine reauth even when the old token had it. Request it only +when the user needs Google Ads access, with `--services all-user,ads`. + Use narrow services only for throwaway/test accounts, service-specific bot accounts, explicit user requests, or scoped security experiments. Safety should normally be enforced at command time with `--enable-commands`, @@ -137,8 +142,9 @@ the pane width. A truncated consent URL does not fail loudly: Google renders client misconfiguration and sends you debugging the wrong thing. Verify the captured URL contains `response_type` before using it. -Write the URL to a mode-0600 file and hand it to the browser by file reference -(see `$browser-use`); never echo it. Appending `&login_hint=user@example.com` +Write the URL to a mode-0600 file and use a browser automation tool that can +read that file and open the consent URL without displaying it in logs; never +echo it. Appending `&login_hint=user@example.com` skips the account chooser and removes a whole class of wrong-account risk. Expect up to two interstitials when the OAuth client is unverified or in diff --git a/.ci-policy.md b/.ci-policy.md new file mode 100644 index 000000000..d9634a936 --- /dev/null +++ b/.ci-policy.md @@ -0,0 +1 @@ +CodeQL scans main weekly to retain security refreshes without redundant per-push scans in this quiet repository; PR/manual scans and ordinary CI remain enabled. diff --git a/.github/actionlint.yaml b/.github/actionlint.yaml index 1dadfc099..1cfdbb8d8 100644 --- a/.github/actionlint.yaml +++ b/.github/actionlint.yaml @@ -1,5 +1,7 @@ self-hosted-runner: labels: + # GitHub-hosted macOS 27 is not in actionlint's runner catalog yet. + - xcode-27 - blacksmith-16vcpu-ubuntu-2404 - blacksmith-16vcpu-windows-2025 - crabbox diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 000000000..83bd09ae7 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,64 @@ + + +## What Problem This Solves + + + +## User Impact + + + +## Why This Change Was Made + + + +## Evidence + + diff --git a/.github/release-allowed-signers b/.github/release-allowed-signers index 500e102be..9648cc0c6 100644 --- a/.github/release-allowed-signers +++ b/.github/release-allowed-signers @@ -1 +1,2 @@ steipete@gmail.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAII9XsaCcr8TInPnHcuTVfvXXcsoUFrOE7menfbEIHFW9 steipete@gmail.com +vincentkoc namespaces="git" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMYJHwFnesHbwtPLErQBRMffbET0Wrbzh+PjkndZRNyy diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c2e1aa9a..28d3794e8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,10 +47,10 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 with: - go-version: "1.26.9" + go-version: "1.26.11" cache: true - name: Test minimum supported Go series - run: go test ./... + run: go test -timeout=20m ./... - name: Build run: go build ./cmd/gog @@ -60,7 +60,7 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 with: - node-version: "26" + node-version: "26.12.1" - name: Enable Corepack (pnpm) run: | npm install --global corepack@0.36.0 @@ -97,7 +97,7 @@ jobs: shell: bash - name: Test # Skip tests that depend on macOS Keychain / Linux keyring or Unix path semantics. - # These are covered by ubuntu-latest and macos-15 jobs. + # These are covered by ubuntu-latest and xcode-27 jobs. # See https://github.com/openclaw/gogcli/issues/395 run: make test shell: bash @@ -111,7 +111,13 @@ jobs: run: go build ./cmd/gog darwin-cgo-build: - runs-on: macos-15 + runs-on: xcode-27 + env: + MACOSX_DEPLOYMENT_TARGET: "15.0" + # Explicit flags also keep cached cgo objects tied to the deployment target. + CGO_CFLAGS: "-O2 -g -mmacosx-version-min=15.0" + CGO_CXXFLAGS: "-O2 -g -mmacosx-version-min=15.0" + CGO_LDFLAGS: "-O2 -g -mmacosx-version-min=15.0" steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 @@ -122,3 +128,5 @@ jobs: run: make test - name: Build (Keychain / cgo) run: CGO_ENABLED=1 go build ./cmd/gog + - name: Verify macOS deployment target + run: ./scripts/check-darwin-minos.sh ./gog diff --git a/.github/workflows/clawsweeper-dispatch.yml b/.github/workflows/clawsweeper-dispatch.yml index 5af378a96..bf7bea08d 100644 --- a/.github/workflows/clawsweeper-dispatch.yml +++ b/.github/workflows/clawsweeper-dispatch.yml @@ -12,33 +12,25 @@ permissions: contents: read concurrency: - group: clawsweeper-dispatch-${{ github.repository }}-${{ github.event.issue.number || github.event.pull_request.number || github.run_id }} + group: clawsweeper-dispatch-${{ github.repository }}-${{ github.event_name }}-${{ github.event.comment.id || github.event.issue.number || github.event.pull_request.number || github.run_id }}-${{ endsWith(github.actor, '[bot]') && (github.event.action == 'labeled' || github.event.action == 'unlabeled') && github.actor || 'dispatchable' }} cancel-in-progress: ${{ github.event.action == 'edited' || github.event.action == 'synchronize' || github.event.action == 'ready_for_review' }} jobs: dispatch: runs-on: ubuntu-latest + # id-token proves this repository, event, branch, and run to the queue. + # The job never checks out or executes pull request code. + permissions: + contents: read + id-token: write if: ${{ !(endsWith(github.actor, '[bot]') && (github.event.action == 'labeled' || github.event.action == 'unlabeled')) }} env: - HAS_CLAWSWEEPER_APP_PRIVATE_KEY: ${{ secrets.CLAWSWEEPER_APP_PRIVATE_KEY != '' }} - CLAWSWEEPER_APP_CLIENT_ID: Iv23liOECG0slfuhz093 SUPERSEDES_IN_PROGRESS: ${{ (github.event.action == 'edited' || github.event.action == 'synchronize' || github.event.action == 'ready_for_review') && 'true' || 'false' }} steps: - name: Debounce bursty metadata events if: ${{ github.event.action == 'labeled' || github.event.action == 'unlabeled' }} run: sleep 20 - - name: Create ClawSweeper dispatch token - id: token - if: ${{ env.HAS_CLAWSWEEPER_APP_PRIVATE_KEY == 'true' }} - uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0 - with: - client-id: ${{ env.CLAWSWEEPER_APP_CLIENT_ID }} - private-key: ${{ secrets.CLAWSWEEPER_APP_PRIVATE_KEY }} - owner: openclaw - repositories: clawsweeper - permission-contents: write - - name: Pre-filter ClawSweeper comment id: comment_filter if: ${{ github.event_name == 'issue_comment' }} @@ -46,157 +38,222 @@ jobs: COMMENT_BODY: ${{ github.event.comment.body }} run: | set -euo pipefail - if grep -Eiq '(^|[[:space:]])@(clawsweeper|openclaw-clawsweeper)\b(\[bot\])?|(^|[[:space:]])/(clawsweeper|review|autoclose|auto([[:space:]]+|-)?merge)\b' <<< "$COMMENT_BODY"; then + if [[ "$COMMENT_BODY" == *")' "$body_file"; then - echo "Ignoring ClawSweeper proof-nudge comment." - exit 0 - fi - if [ -n "$TARGET_TOKEN" ]; then - GH_TOKEN="$TARGET_TOKEN" gh api -X POST \ - -H "Accept: application/vnd.github+json" \ - "repos/$TARGET_REPO/issues/comments/$COMMENT_ID/reactions" \ - -f content="eyes" >/dev/null || true - fi - status_comment_id="" - if [ -n "$TARGET_TOKEN" ]; then - case "$AUTHOR_ASSOCIATION" in - OWNER|MEMBER|COLLABORATOR) - status_body="$(printf '%s\n' \ - "" \ - "πŸ¦žπŸ‘€" \ - "ClawSweeper picked this up." \ - "" \ - "Command router queued. I will update this comment with the next step.")" - status_payload="$(jq -nc --arg body "$status_body" '{body:$body}')" - status_err="$(mktemp)" - if status_response="$(GH_TOKEN="$TARGET_TOKEN" gh api \ - "repos/$TARGET_REPO/issues/$ITEM_NUMBER/comments" \ - --method POST \ - --input - <<< "$status_payload" 2>"$status_err")"; then - status_comment_id="$(jq -r '.id // empty' <<< "$status_response")" - else - cat "$status_err" >&2 - echo "::warning::Could not create ClawSweeper queued status comment; dispatching command router without one." - fi - rm -f "$status_err" - ;; - esac - fi - payload="$(jq -nc \ + set -euo pipefail + client_payload="$(jq -nc \ --arg target_repo "$TARGET_REPO" \ --argjson item_number "$ITEM_NUMBER" \ --argjson comment_id "$COMMENT_ID" \ - --arg status_comment_id "$status_comment_id" \ - --arg source_event "issue_comment" \ --arg source_action "$SOURCE_ACTION" \ - '{event_type:"clawsweeper_comment",client_payload:({target_repo:$target_repo,item_number:$item_number,comment_id:$comment_id,source_event:$source_event,source_action:$source_action,max_comments:"1"} + (if $status_comment_id != "" then {status_comment_id:($status_comment_id|tonumber)} else {} end))}')" - GH_TOKEN="$DISPATCH_TOKEN" gh api repos/openclaw/clawsweeper/dispatches \ - --method POST \ - --input - <<< "$payload" + '{target_repo:$target_repo,item_number:$item_number,comment_id:$comment_id,source_event:"issue_comment",source_action:$source_action}')" + # The App webhook remains an independent delivery route. + if [ -n "${ACTIONS_ID_TOKEN_REQUEST_URL:-}" ] && + [ -n "${ACTIONS_ID_TOKEN_REQUEST_TOKEN:-}" ] && + oidc_token="$(curl --fail --silent --show-error --connect-timeout 5 --max-time 15 \ + --header "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \ + --get --data-urlencode "audience=$TARGET_DISPATCH_URL" \ + "$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -er '.value | strings | select(length > 0)')" && + [ -n "$oidc_token" ]; then + echo "::add-mask::$oidc_token" + direct_body="$RUNNER_TEMP/clawsweeper-direct-intake.json" + if direct_status="$(curl --silent --show-error --connect-timeout 5 --max-time 20 \ + --request POST \ + --header "authorization: Bearer $oidc_token" \ + --header "content-type: application/json" \ + --data "$client_payload" \ + --output "$direct_body" \ + --write-out '%{http_code}' \ + "$TARGET_DISPATCH_URL")" && + [[ "$direct_status" == 2[0-9][0-9] ]]; then + echo "Queued ClawSweeper intake directly: $(jq -c . "$direct_body" 2>/dev/null || echo '{}')" + exit 0 + fi + # Only non-transient 4xx is a deliberate refusal; the App webhook covers it. + # Timeouts, throttling, and verifier/Worker failures must stay re-runnable. + if [[ "${direct_status:-}" == 4[0-9][0-9] && "$direct_status" != 408 && "$direct_status" != 429 ]]; then + echo "::warning::ClawSweeper intake declined this event (HTTP $direct_status); the App webhook route still applies." + exit 0 + fi + echo "::error::ClawSweeper intake unavailable (HTTP ${direct_status:-none}); re-run this job after the Worker recovers." + else + echo "::error::ClawSweeper OIDC token unavailable; the dispatch job needs id-token: write." + fi + exit 1 diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 000000000..93ab6e9c2 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,56 @@ +name: CodeQL + +on: + pull_request: + branches: [main] + types: [opened, synchronize, reopened, ready_for_review] + schedule: + - cron: "47 4 * * 2" + workflow_dispatch: {} + +permissions: + contents: read + security-events: write + +concurrency: + group: codeql-${{ github.event_name }}-${{ github.event.pull_request.number || (github.event_name == 'workflow_dispatch' && github.run_id) || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + analyze: + name: Analyze (${{ matrix.language }}) + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - language: actions + build-mode: none + - language: javascript-typescript + build-mode: none + - language: go + build-mode: autobuild + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Install Go + if: matrix.language == 'go' + uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 + with: + go-version-file: go.mod + cache: false + + - name: Initialize CodeQL + uses: github/codeql-action/init@93a54aaef5ced74c8d9fae64bdfb97f6a18c21b4 # v4 + with: + languages: ${{ matrix.language }} + build-mode: ${{ matrix.build-mode }} + dependency-caching: true + + - name: Analyze + uses: github/codeql-action/analyze@93a54aaef5ced74c8d9fae64bdfb97f6a18c21b4 # v4 + with: + category: /language:${{ matrix.language }} diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index fbc82706e..cfe58075d 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -43,7 +43,7 @@ jobs: - name: Set up Node uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 with: - node-version: "26" + node-version: "26.12.1" - name: Build docs site run: make docs-site diff --git a/.github/workflows/release-unified.yml b/.github/workflows/release-unified.yml index 94427d9c2..56740e41a 100644 --- a/.github/workflows/release-unified.yml +++ b/.github/workflows/release-unified.yml @@ -16,7 +16,7 @@ permissions: {} jobs: preflight: - runs-on: macos-15 + runs-on: xcode-27 permissions: contents: read steps: @@ -64,6 +64,7 @@ jobs: with: version: ${{ inputs.version }} dry-run: ${{ inputs.dry_run }} + require-signed-tag: true repository-type: openclaw homebrew-tap: openclaw/homebrew-tap homebrew-formula: gogcli diff --git a/.goreleaser.yaml b/.goreleaser.yaml index e171f622b..a18d5d94c 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -67,11 +67,11 @@ builds: - AR=/usr/bin/ar - CC=/usr/bin/clang - CXX=/usr/bin/clang++ - - CGO_CFLAGS=-O2 -g + - CGO_CFLAGS=-O2 -g -mmacosx-version-min=15.0 - "CGO_CPPFLAGS=" - - CGO_CXXFLAGS=-O2 -g + - CGO_CXXFLAGS=-O2 -g -mmacosx-version-min=15.0 - CGO_ENABLED=1 - - CGO_LDFLAGS=-O2 -g + - CGO_LDFLAGS=-O2 -g -mmacosx-version-min=15.0 - "GOCACHEPROG=" - "GODEBUG=" - GO111MODULE=on diff --git a/CHANGELOG.md b/CHANGELOG.md index 62e57c6c1..56fdffede 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,144 @@ # Changelog -## 0.44.1 - Unreleased +## 0.48.2 - Unreleased -- Output: warn on stderr when a `--select` path matches no objects in a nonempty result, preserving JSON output and exit status. (#1210) β€” thanks @postoso. -- Auth: clarify that `auth login` opens the browser account manager, and document manual authorization and unattended health checks. (#1214) β€” thanks @jingtying. -- Dependencies: refresh Google API and MCP clients plus tracking-worker tooling within the Go 1.26 floor and 24-hour worker release cooldown; add a non-publishing release-pipeline dry run. +- Calendar: reject non-empty attendee input that yields no addresses instead of clearing every attendee. (jai/gogcli#1) + +- Calendar: carry explicit summary clears into Zoom meeting creation and regeneration. (jai/gogcli#1) + +- Auth: serialize rekey output publication, recheck concurrent replacement permission and refuse staged permission loss. (jai/gogcli#1) + +- Chat: add full SDK message output for list/search, get with markup selection, text-only update/edit, and confirmed delete with explicit reply deletion; preserve compact defaults and wrap nested rich content for agents. (jai/gogcli#1) β€” thanks @jai. + +- Dependencies: refresh the MCP and Google API clients, networking libraries, and tracking-worker tooling while preserving the Go 1.26 minimum, 24-hour worker cooldown, and security overrides. + +## 0.48.1 - 2026-11-15 + +**Highlights:** Safer Gmail replies exclude every send-as alias, Calendar queries and recurring updates handle edge cases correctly, and Go security updates address GO-2026-6859. + +- Security: build with Go 1.27.4 and test the minimum series on Go 1.26.11 to address GO-2026-6859, preserving the Go 1.26.0 source minimum. +- Dependencies: refresh Google clients, networking libraries, and tracking-worker tools while retaining the 24-hour worker cooldown and security overrides. + +- Calendar: reject empty or inverted RFC3339 free/busy windows, resolve calendar names containing `@` consistently, and reject malformed nonblank attendee clears. (#1328, #1329, #1330) β€” thanks @privatenumber and @pkyIntelligence. +- Calendar: read search and team event pages up to `--max`, truncate the parent series for future-instance updates, and warn about unavailable free/busy calendars with stable row ordering. (#1311, #1317, #1322) β€” thanks @saariuslystoned. +- Gmail: exclude all send-as aliases from reply-all and default auto-replies; stop default auto-replies when alias discovery fails, and preserve Cc-only reply-all recipients. (#1318, #1325) β€” thanks @saariuslystoned. +- Gmail: forward HTML-only originals in the plain-text part and read every watch history page before advancing the cursor. (#1312, #1321) β€” thanks @saariuslystoned. +- Sheets: preserve numeric JSON tokens in append requests and keep multiline cells on one line in text output. (#1316, #1331) β€” thanks @saariuslystoned and @pkyIntelligence. +- Output: return empty arrays for Drive labels, Drive/Docs comments, and Sheets notes and links, including `--results-only`. (#1314, #1326) β€” thanks @saariuslystoned. +- Drive: accept commas in label field flags and download or export a shortcut's target. (#1315, #1319) β€” thanks @saariuslystoned. +- Tasks: send explicit empty titles and notes when clearing them, and reject an empty status. (#1313) β€” thanks @saariuslystoned. +- Contacts: document and apply Google's 30-result search ceiling, warning when a larger limit is requested. (#1323) β€” thanks @saariuslystoned. +- AdSense: show report warnings and truncation hints on stderr in table output. (#1324) β€” thanks @saariuslystoned. +- Sites: preserve requested false booleans in site metadata JSON. (#1308) β€” thanks @SebTardif. +- Agent skills: describe when to use each service and distinguish overlapping workflows; explain browser consent without requiring an unshipped skill. (#1335) β€” thanks @henkisdabro. + +- Docs: use placeholder accounts in Gmail auto-reply, Drive audit, and live-testing examples. (#1332) β€” thanks @vyctorbrzezowski. + +## 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. + +The backup changes in #1303 and #1304 preserve existing saved remotes and Git origins. Gmail attachment behavior after delivery (#1300) is contributor-reported; local MIME regression tests pass. Automatic reauthorization (#1278) has synthetic regression coverage but was not tested with a live consent flow. + +- Backup: keep new backups local until a remote is configured; preserve saved remotes and existing Git origins, and explain local-only operation. (#1287) β€” thanks @NasAndNora. + +- Backup: allow a locally initialized backup to acquire its first configured remote without replacing an existing origin. (#1287) β€” thanks @NasAndNora. + +- Auth: add optional `auth service-account set --keyring` storage with migration back to files, isolated configuration references, and cleanup on rotation or unset; existing key files remain supported. (#1294) β€” thanks @tommyjoseph. + +- Gmail: give every outgoing attachment a unique, stable `X-Attachment-Id`, including duplicate files, while preserving inline Content-ID references. (#1299, #1300) β€” thanks @zupolgec. + +- Auth: retain the command runtime and OAuth client dependencies during automatic reauthorization, preserving cancellation and the stored service/scope grant. (#1277, #1278) β€” thanks @TheAngryPit. + +- Calendar: reject empty or inverted time windows before querying, keep successful historical search ranges unchanged, and extend far-future searches from their explicit start. (#1280, #1298) β€” thanks @remote-controlled-man and @privatenumber. + +- Gmail: treat a whitespace-only `text/plain` part as missing when choosing a message body, so `gmail get`, `gmail thread get` and `--sanitize-content` output fall back to the HTML part instead of returning an empty body (seen in Meetup notifications). (#1279) β€” thanks @Flamefork. + +- Release: require SSH-signed annotated tags authorized by the committed signer policy before builds and publication; preserve tagless dry runs. + +- CI: run CodeQL weekly and on pull requests or manual dispatch, retaining Actions, Go, and JavaScript analysis without duplicate scans on every main push. + +- Dependencies: refresh MCP, Google API/gRPC and networking libraries plus tracking-worker tooling; retain the documented Go minimum, patched build toolchain, release cooldown, and security overrides. (#1274) + +- Dependencies: refresh Google clients, MCP, Kong, Markdown/YAML libraries, and tracking-worker tools; update the workerd security pin while retaining Go 1.26, the patched build toolchain, and the 24-hour worker cooldown. (#1302) + +- Gmail: add `--ids-only` to `gmail messages search` and `gmail search` to return IDs from the list call without one detail request per result, for bulk jobs that pipe into `gmail batch modify`. (#1257) β€” thanks @jatinbansal1998. + +- Gmail: add `watch serve --token-env` and `--hook-token-env` to read tokens from named environment variables, preserving literal flags and stored-hook defaults. (#1292) β€” thanks @mmaps. + +- Google APIs: raise the rate-limit retry budget from three to six backoffs (63s to just under 94.5s in total) so per-minute quotas such as Gmail's "Units per minute per user" can refill before a command fails. (#1257) β€” thanks @jatinbansal1998. + +- Calendar: honor explicitly empty event summaries, locations, and attendee lists in update requests, while preserving omitted fields. (#1268) β€” thanks @pkyIntelligence. + +- Calendar: accept `primary` and unlisted email-like IDs in `--cal` and `--calendars` while retaining named-calendar resolution. (#1283, #1297) β€” thanks @goutamadwant. + +- Calendar: reject a single page token across multiple calendars before fetching events; retain single-calendar continuation and `--all-pages`. (#1281, #1285) β€” thanks @goutamadwant. + +- Calendar: sort all-day events in their calendar timezone, including partial responses and display-timezone overrides. (#1284, #1286) β€” thanks @goutamadwant. + +- Calendar: include camelCase `calendarId` on multi-calendar JSON events while retaining the existing `CalendarID` key for scripts. (#1282, #1290) β€” thanks @i098. + +- MCP: add optional `page` continuation tokens to `gmail_search` and `calendar_events`, preserving bounded reads and existing CLI pagination. (#1269, #1270) β€” thanks @pkyIntelligence. + +- Docs: preserve API 404 causes so missing documents exit with the documented `not_found` code 5 while keeping the existing error message. (#1288, #1289) β€” thanks @HardMax71. + +## 0.47.1 - 2026-10-26 + +**Highlights:** Preserve Gmail text direction and narrowed Calendar grants, fix headless Linux authentication, and reject compromised certificates in the tracking worker. + +- Gmail: give the author's own text its direction in HTML (`dir="auto"` on each line of converted plain text, once around given HTML, and on the signature) so right-to-left text reads correctly and English keeps its direction when a right-to-left reply quotes it; whole HTML documents go in as given. (#1255) β€” thanks @malob. + +- Auth: use the encrypted file backend on headless Linux when D-Bus is explicitly disabled, instead of falling through to an uninitialized password store. (#1258) β€” thanks @pkyIntelligence. + +- Auth: preserve Calendar read-only scope selections during automatic reauthorization instead of requesting previously granted broader access. (#1259) β€” thanks @pkyIntelligence. + +- Security: update the tracking worker's workerd runtime to reject compromised eMudhra certificate chains. (#1264) β€” thanks @joshavant. + +- Dependencies: update Google IAM, GAX, enterprise certificate support, Workers types, Wrangler, and oxlint-tsgolint while retaining Go 1.26 and the tracking worker’s 24-hour release cooldown. + +## 0.47.0 - 2026-10-23 + +**Highlights:** Opt-in HTML Gmail bodies, selected search headers, and calendar settings updates, with OAuth error redaction and certificate trust fixes. + +- Gmail: add opt-in `--html-from-text` (or `GOG_GMAIL_HTML_FROM_TEXT`) to generate an escaped HTML alternative for plain send, reply, and draft bodies; preserve plain-text defaults and explicit HTML. (#1251) β€” thanks @mathieu-ships. +- Gmail: expose up to 50 selected headers in message-search JSON and MCP with `--headers`, reusing existing reads and preserving sanitization and untrusted-content wrapping. (#1190, #1249) β€” thanks @obokaman-com. +- Calendar: add `update-calendar` to inspect or patch calendar-level names, descriptions, locations, and timezones, with field validation, offline previews, and explicit optional-field clearing. (#1245) β€” thanks @sorenisanerd. +- Auth: omit OAuth provider descriptions, URLs, and response bodies from command errors, per-item results, backup diagnostics, health checks, and watch/verbose logs; retain fixed recovery guidance, authentication exit codes, and both Calendar/Zoom rollback causes. (#1243) β€” thanks @pkyIntelligence. +- Security: upgrade Alpine's default CA packages in Docker image build and runtime stages to reject the compromised eMudhra certificate chains. (#1244) β€” thanks @joshavant. +- Auth: make Google Ads (`ads`) an explicit opt-in instead of part of the default `user`/`all-user` set; Google can gate the Ads scope behind mandatory passkey enrollment, which blocked ordinary reauth. Request it with `--services user,ads`. +- Dependencies: update Pub/Sub, Google API and x/tools plus Cloudflare Workers types and Wrangler; retain Go 1.26 and the tracking worker’s 24-hour release cooldown. +- Gmail: retry 403 rate limits with the existing bounded backoff and stop remaining detail fetches when a search fails; preserve error bodies and open the watch circuit on 403 rate limits. (#1241, #1242) β€” thanks @xyrolle. +- Gmail: leave quoted search operators to Gmail instead of silently narrowing results with label filters. (#1247) β€” thanks @SebTardif. +- Gmail: include nonempty Cc and Bcc headers in thread text output. (#1248) β€” thanks @alexpriest. +- Gmail: preserve the direction of reply and forward headers beside right-to-left text, and add Gmail's quote classes without altering plain text or quoted content. (#1250) β€” thanks @malob. +- Drive: preserve requested false booleans in list/search JSON, including grouped fields, slash paths, and wildcards; keep conditionally absent fields omitted. (#1246) β€” thanks @SebTardif. + +## 0.46.0 - 2026-10-20 + +**Highlights:** Safely re-encrypt auth stores, route Google API calls through credential-free relays, and compose richer Gmail forwards, with Go security fixes. + +- Auth: add `gog auth rekey ` to write and verify a separate re-encrypted directory while leaving the live keyring untouched; hold the store lock throughout, publish only complete fsynced output, and retain the old directory during installation. (#1224) β€” thanks @sorenisanerd. +- Google APIs: add `GOG_GOOGLE_API_BASE_URL` to send `*.googleapis.com` requests to a test server, emulator, proxy, or relay that adds credentials outside gog; requests keep path and query, pass the original host as `X-Forwarded-Host`, carry no gog credentials, and refuse cross-origin redirects. (#1225, #1226) β€” thanks @km-tr. +- Gmail: add `--note-html` and `--note-html-file` to forwards and preserve plain-note line breaks in HTML output. (#1215) β€” thanks @malob. +- Auth: accept `gog auth ` as shorthand for `gog auth add `; bare `gog auth` and mistyped subcommands keep their existing errors. (#1221) +- Gmail: lay out the forwarded-message header block the way Gmail Web does: plain text with the sender's name in bold, `Name ` (or ``) for the sender and each recipient with addresses linked in HTML, and two blank lines before the original body. (#1236) β€” thanks @malob. +- Drive: preserve requested top-level false booleans in `drive get --json`, including the default `starred` and `hasThumbnail` fields; keep conditionally absent fields omitted. (#1223) β€” thanks @postoso. +- Security: build release binaries and Docker images with Go 1.27.3 and test the minimum series with Go 1.26.10 to address the crypto/x509 vulnerability GO-2026-6809, while preserving the Go 1.26 minimum. +- CI: use macOS 27 runners for Darwin checks and release preflight while enforcing the macOS 15.0 deployment target. +- Dependencies: refresh the Google API client and generated API definitions while retaining the Go 1.26 minimum and the tracking worker's 24-hour release cooldown. +- Dependencies: refresh the Google API client, golangci-lint, Cloudflare Workers types, Wrangler, PostCSS, and Undici while retaining Go 1.26, pnpm 11, and the worker’s 24-hour release cooldown. +- Dependencies: update Vitest and Cloudflare Workers types within the worker’s 24-hour release cooldown. +- Dependencies: refresh Wrangler, Cloudflare Workers types, Oxlint, and Oxfmt within the tracking worker's 24-hour release cooldown. + +## 0.45.0 - 2026-10-16 + +**Highlights:** Preserve Gmail search results for negated and OR queries, warn about unmatched JSON selections, and improve reply formatting. - Gmail: derive `labelIds` only from system-label terms that hold for every result; a term under `NOT` or `-`, inside a negated group, or in a query with `OR`, `|` or `{…}` is left to Gmail, so `search`, `--count`, `archive`, `trash`, `mark-read`, `unread` and `autoreply` no longer silently narrow such queries. (#1212) β€” thanks @wstock. +- Output: warn on stderr when a `--select` path matches no objects in a nonempty result, preserving JSON output and exit status. (#1210) β€” thanks @postoso. - Gmail: render the reply attribution line the way Gmail Web does in both text and HTML: no comma after the date, `Name ` (or ``) with the address linked in HTML, and a narrow no-break space before AM/PM (also in forwarded `Date:` lines). (#1213) β€” thanks @malob. +- Auth: clarify that `auth login` opens the browser account manager, and document manual authorization and unattended health checks. (#1214) β€” thanks @jingtying. +- Dependencies: refresh Google API and MCP clients plus tracking-worker tooling within the Go 1.26 floor and 24-hour worker release cooldown; add a non-publishing release-pipeline dry run. ## 0.44.0 - 2026-10-11 diff --git a/Dockerfile b/Dockerfile index 5e4ec5cf2..dfbfb9b3a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,10 @@ # syntax=docker/dockerfile:1.27.0 -ARG GO_VERSION=1.27.2 +ARG GO_VERSION=1.27.4 ARG ALPINE_VERSION=3.24 -FROM golang:${GO_VERSION}-alpine@sha256:f92b6ef800e499660581efdabdf25d9d817a9d124eaf900924f0504e7e27e12d AS build +FROM golang:${GO_VERSION}-alpine@sha256:0a5f7fe796599ff487605987432e7619ae45beeb2fba4c2ce0b907879932aebf AS build +RUN apk add --no-cache --upgrade ca-certificates=20261020-r0 ca-certificates-bundle=20261020-r0 RUN apk add --no-cache ca-certificates git tzdata @@ -22,6 +23,7 @@ RUN CGO_ENABLED=0 GOOS=linux go build -trimpath \ -o /out/gog ./cmd/gog FROM alpine:${ALPINE_VERSION} +RUN apk add --no-cache --upgrade ca-certificates=20261020-r0 ca-certificates-bundle=20261020-r0 LABEL org.opencontainers.image.source="https://github.com/openclaw/gogcli" LABEL org.opencontainers.image.description="Google services CLI for terminal automation" diff --git a/Makefile b/Makefile index 8789f9d63..6fc7040fd 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,8 @@ DATE := $(shell date -u +%Y-%m-%dT%H:%M:%SZ) LDFLAGS := -X github.com/openclaw/gogcli/internal/cmd.version=$(VERSION) -X github.com/openclaw/gogcli/internal/cmd.commit=$(COMMIT) -X github.com/openclaw/gogcli/internal/cmd.date=$(DATE) # `make lint` already covers vet-equivalent checks; skip duplicate work in `make test`. GO_TEST_FLAGS ?= -vet=off +# The command package's complete suite can exceed Go's default ten-minute limit. +GO_TEST_TIMEOUT ?= 20m TEST_FLAGS ?= TEST_PKGS ?= ./... @@ -25,7 +27,7 @@ GOIMPORTS := $(TOOLS_DIR)/goimports GOLANGCI_LINT := $(TOOLS_DIR)/golangci-lint DEADCODE := $(TOOLS_DIR)/deadcode TOOLS_STAMP := $(TOOLS_DIR)/.versions -TOOLS_VERSION := gofumpt=v0.12.0;goimports=v0.52.0;golangci-lint=v2.14.0;deadcode=v0.52.0 +TOOLS_VERSION := gofumpt=v0.12.0;goimports=v0.52.0;golangci-lint=v2.15.0;deadcode=v0.52.0 # Allow passing CLI args as extra "targets": # make gogcli -- --help @@ -92,7 +94,7 @@ tools: set -e; \ GOBIN=$(TOOLS_DIR) go install mvdan.cc/gofumpt@v0.12.0; \ GOBIN=$(TOOLS_DIR) go install golang.org/x/tools/cmd/goimports@v0.52.0; \ - GOBIN=$(TOOLS_DIR) go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.14.0; \ + GOBIN=$(TOOLS_DIR) go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.15.0; \ GOBIN=$(TOOLS_DIR) go install golang.org/x/tools/cmd/deadcode@v0.52.0; \ printf '%s\n' "$(TOOLS_VERSION)" > "$(TOOLS_STAMP)"; \ fi @@ -141,7 +143,7 @@ docker-version-check: fi test: - @go test $(GO_TEST_FLAGS) $(TEST_FLAGS) $(TEST_PKGS) + @go test -timeout=$(GO_TEST_TIMEOUT) $(GO_TEST_FLAGS) $(TEST_FLAGS) $(TEST_PKGS) @node --test scripts/eval-gws.test.mjs scripts/eval-gws-agents.test.mjs scripts/check-docker-go-version.test.mjs eval-gws: build diff --git a/README.md b/README.md index 928b3f825..f250f8174 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,8 @@ gog auth doctor --check gog gmail search 'newer_than:7d' --max 10 ``` +`gog auth you@gmail.com` is shorthand for `gog auth add you@gmail.com`, with the same flags. + For Gmail queries beginning with `-`, place all flags before `--`; see [Search and Read](docs/gmail-workflows.md#search-and-read). @@ -85,11 +87,42 @@ Generic API commands support service-hosted Discovery documents such as Meet v2 when the default central Directory returns 404. Explicit `GOG_DISCOVERY_BASE_URL` overrides retain their existing behavior. +`GOG_GOOGLE_API_BASE_URL=http(s)://host[:port]` sends Google API requests for +`https://googleapis.com` and `https://*.googleapis.com` to a test server, +emulator, proxy, or relay that adds credentials outside gog. Path and query are +kept and the original host is sent as `X-Forwarded-Host`. While it is set, gog +attaches no credentials to Google API requests (no OAuth, ADC, service-account, +`--access-token`, or API-key credentials), does not need stored tokens, and +refuses cross-origin redirects, so the relay handles any upstream redirects. +`--account` still selects the account label. Use https for endpoints that are +not on loopback. +Discovery documents still use `GOG_DISCOVERY_BASE_URL`; gRPC clients such as +the Pub/Sub pull used by `gmail watch pull`, Maps/Places API-key calls, and +downloads from non-googleapis.com URLs are not redirected, and `gog auth` commands +still talk to Google directly. Invalid values fail +with a usage error. + Consumer Google accounts work with user-facing APIs. Admin Directory, Cloud Identity Groups, Chat, Keep, and domain-wide delegation require a managed Google Workspace domain. The [Workspace Admin guide](docs/workspace-admin.md) explains that setup. +## Chat messages + +```bash +gog --account you@example.com chat messages list spaces/AAA --full --json --wrap-untrusted +gog --account you@example.com chat messages search 'release' --full --view full --json +gog --account you@example.com chat messages get spaces/AAA/messages/BBB --json +gog chat messages update spaces/AAA/messages/BBB --text='Replacement' --dry-run --json +gog chat messages delete spaces/AAA/messages/BBB --delete-replies --dry-run --json +``` + +Compact list/search defaults are preserved. Full output is SDK-typed JSON, +including rich content and image URLs; it does not download image bytes. +See [Chat rich messages](docs/chat-rich-messages.md) for output contracts, +permissions, safe text edits, and the distinction between CLI `--force` and +API reply deletion. + ## Automate safely `--json` emits structured output and `--plain` emits stable TSV. Prompts, @@ -151,6 +184,11 @@ The generated table below records the user OAuth and Workspace service-account surface. `gog auth services` reports the same information from the installed binary. +The default `user`/`all-user` set excludes `ads`. Google treats authorizing an +app for Google Ads as a sensitive action and can block consent behind a +mandatory passkey enrollment. Add it only when you need it: +`gog auth add you@example.com --services user,ads`. + | Service | User | APIs | Scopes | Notes | | --- | --- | --- | --- | --- | @@ -174,7 +212,7 @@ binary. | analytics | yes | Analytics Admin API, Analytics Data API | `https://www.googleapis.com/auth/analytics.readonly` | GA4 account summaries + reporting | | searchconsole | yes | Search Console API | `https://www.googleapis.com/auth/webmasters` | Search Analytics + sitemap management + URL Inspection | | adsense | no | AdSense Management API | `https://www.googleapis.com/auth/adsense.readonly` | Consumer OAuth; explicit opt-in with --services adsense; read-only | -| ads | yes | Google Ads API | `https://www.googleapis.com/auth/adwords` | OAuth scope only | +| ads | no | Google Ads API | `https://www.googleapis.com/auth/adwords` | Explicit opt-in with --services ads; Google may require a passkey to authorize Google Ads access | | groups | no | Cloud Identity API | `https://www.googleapis.com/auth/cloud-identity.groups.readonly` | Workspace only | | keep | no | Keep API | `https://www.googleapis.com/auth/keep` | Workspace only; service account (domain-wide delegation) | | admin | no | Admin SDK Directory API | `https://www.googleapis.com/auth/admin.directory.user`
`https://www.googleapis.com/auth/admin.directory.group`
`https://www.googleapis.com/auth/admin.directory.group.member` | Workspace only; service account with domain-wide delegation required | @@ -185,6 +223,12 @@ binary. ## Documentation +`gog drive get --fields id,trashed --json` preserves `"trashed": false`. +The default metadata also includes false `starred` and `hasThumbnail` values. +Conditionally absent fields (`shared`, `ownedByMe`, `writersCanShare`, and +`hasAugmentedPermissions`) and nested booleans retain the SDK's omission behavior; +use `gog drive raw` when you need the exact API response. + - [Overview and guides](https://gogcli.sh/) - [Examples](docs/examples.md) - [Command index](docs/commands/README.md) diff --git a/docs/RELEASING.md b/docs/RELEASING.md index cf2ac863f..635a4612a 100644 --- a/docs/RELEASING.md +++ b/docs/RELEASING.md @@ -4,9 +4,9 @@ summary: "Unified GitHub Actions release process for GogCLI" # Releasing `gogcli` -Official releases run only through `.github/workflows/release-unified.yml`, which calls the fleet-standard `openclaw/release-workflows` Go CLI pipeline at `@v1`. Do not create or push release tags locally, and do not use local signing or notarization credentials. +Official releases run only through `.github/workflows/release-unified.yml`, which calls the fleet-standard `openclaw/release-workflows` Go CLI pipeline at `@v1`. Binary signing, notarization, and publication stay in Actions. After a successful dry run, create and verify the release tag with an SSH key listed in `.github/release-allowed-signers` before dispatching publication. -Release authorization is repository Actions write access combined with a protected, required-check-green `main` commit and the organization-scoped signing, notarization, and tap credentials. The shared workflow creates the immutable annotated tag; GogCLI intentionally has no separate local tag-signer authorization step. +Release authorization is repository Actions write access combined with a protected, required-check-green `main` commit and the organization-scoped signing, notarization, and tap credentials. The caller enables `require-signed-tag`, so the shared workflow requires an existing SSH-signed annotated tag and verifies its target and signature before building and again before publication. The committed `.github/release-allowed-signers` policy authorizes the listed keys for Peter and Vincent; a local default signing key is eligible only if it is listed there. Create the tag manually at the frozen release commit and verify it against that committed policy before pushing. Never move or replace a release tag, and do not substitute a local allowlist. ## Prepare the release @@ -15,9 +15,9 @@ Release authorization is repository Actions write access combined with a protect 3. Set `internal/cmd/VERSION` to `vX.Y.Z`. 4. Run `make ci`, review the complete diff, and land it on protected `main` with required checks green. -The workflow first runs a read-only `xcrun notarytool history` preflight. The Darwin build pins `MACOSX_DEPLOYMENT_TARGET=15.0` and checks every binary slice with `otool` before signing or publication. +The workflow first runs a read-only `xcrun notarytool history` preflight on the `xcode-27` runner. The Darwin CI and release builds pin `MACOSX_DEPLOYMENT_TARGET=15.0`, include `-mmacosx-version-min=15.0` in the cgo compiler/linker flags so cached objects use the same target, and check every binary slice with `otool` before signing or publication. -The workflow freezes the protected `main` commit, creates or reuses its immutable annotated version tag, builds from that commit, signs and notarizes the native Darwin binaries with organization secrets, verifies the complete asset inventory independently on arm64 and Intel runners, publishes the GitHub Release, and updates `openclaw/homebrew-tap/Formula/gogcli.rb` from verifier-bound asset hashes. +The workflow freezes the protected `main` commit, verifies and reuses its existing signed annotated version tag, builds from that commit, signs and notarizes the native Darwin binaries with organization secrets, verifies the complete asset inventory independently for arm64 and x86_64 (running Intel binaries under Rosetta on Apple Silicon), publishes the GitHub Release, and updates `openclaw/homebrew-tap/Formula/gogcli.rb` from verifier-bound asset hashes. The caller preserves GogCLI's public artifact contract where applicable: @@ -30,7 +30,7 @@ The caller preserves GogCLI's public artifact contract where applicable: ## Dispatch -From current protected `main`, dispatch the workflow with a SemVer version without a leading `v`: +First run the dry run described below on the protected release-prep merge commit. Once it succeeds, create the SSH-signed annotated `vX.Y.Z` tag with an allowed key at that exact commit, verify it, and push it. From current protected `main`, dispatch the workflow with a SemVer version without a leading `v`: ```sh gh workflow run release-unified.yml \ @@ -51,7 +51,7 @@ exact version match without the development suffix. ## Docker closeout -After the GitHub Release is public and its tag is verified, publish the Docker image separately unless an exact-tag Docker run has already succeeded. The unified workflow creates the tag with `GITHUB_TOKEN`, which does not trigger Docker's tag-push workflow. +After the GitHub Release is public and its tag is verified, publish the Docker image separately unless an exact-tag Docker run has already succeeded. A signed tag pushed by the release operator normally triggers Docker's tag-push workflow; tags created with `GITHUB_TOKEN` do not. ```sh gh workflow run docker.yml \ diff --git a/docs/auth-clients.md b/docs/auth-clients.md index 319e0195d..4b4ed468d 100644 --- a/docs/auth-clients.md +++ b/docs/auth-clients.md @@ -38,6 +38,18 @@ gog --client work auth credentials ~/Downloads/work.json --domain example.com This writes `client_domains` into `config.json` so any `@example.com` account selects the `work` client. +## Token errors + +Command errors, per-item results, backup diagnostics, `auth list --check`, `auth doctor --check`, and watch/verbose error logs omit OAuth provider descriptions, URLs, and response bodies. Recognized errors retain their code and recovery steps. For `invalid_grant`, reauthorize the same account and client with `gog --client auth add `, preserving the services and scopes shown by `gog auth list --json`. + +Automatic reauthorization keeps the command runtime and OAuth client dependencies +when recovering from an expired or revoked token, so it can open the authorization +flow and retry the original request. It preserves stored scope selections. Limited Gmail, +Calendar read-only, and Photos read-only grants omit incremental authorization +so Google does not add permissions from an earlier, broader grant. A Calendar +read-only grant remains narrowed when combined with extra event-write scopes; +a stored full Calendar grant retains incremental authorization. + ## Listing stored credentials ``` @@ -115,6 +127,29 @@ gog auth service-account set admin@example.com --key ~/Downloads/service-account gog auth service-account status admin@example.com ``` +File storage remains the default, and existing service-account key files keep +working. To migrate a configured account to the keyring, pass its original JSON +key file (or the currently stored key file) and add `--keyring`: + +```bash +gog auth service-account set admin@example.com --key ~/Downloads/service-account.json --keyring +gog auth service-account status admin@example.com +``` + +This uses the same configured keyring backend as OAuth secrets. The managed +service-account file becomes a reference; the key itself goes into the keyring. +The generic legacy managed key file is removed after the reference is saved. +Unmanaged input files and separately configured Keep-specific key files are left +untouched. Secure or remove those copies yourself after verifying the migration. +Keyring access is required whenever the account is used, including by Keep. + +To return to file storage, run `set` with the original JSON key and omit +`--keyring`. This also removes the old keyring entry. `unset` removes the managed +reference and its keyring entry. Before using an older gog version or moving to +another machine, restore file storage or provide the original key again; copying +a reference file alone does not migrate its keyring entry. Keep a secure recovery +copy of the original key until the migration is verified. + Cloud Identity Groups commands use the same Workspace service-account setup. Include `https://www.googleapis.com/auth/cloud-identity.groups.readonly` in domain-wide delegation, then run: diff --git a/docs/automation.md b/docs/automation.md index 586a669b6..e7cb75824 100644 --- a/docs/automation.md +++ b/docs/automation.md @@ -63,6 +63,13 @@ system. Chat message and thread listings also wrap flattened sender display names. Raw Chat JSON responses, including those from `gog api call`, wrap `formattedText` too. Without the flag, ordinary JSON strings remain unchanged. +Full Chat list/search output (`--full --json`) and message get/update output +wrap nested rich content, including card subtitles, labels, alt text, filenames, +and button text. Structurally validated resource names and HTTP(S) URLs remain +usable; dotted selections retain these rules. Compact defaults are unchanged. +Full Chat JSON is SDK-typed rather than raw/lossless, and image/attachment bytes +are never fetched. See [Chat rich messages](chat-rich-messages.md). + Use `--readonly` (or `GOG_READONLY=1`) as a runtime backstop. It permits GET, HEAD, OPTIONS, and the small allowlist of Google APIs whose query operations use POST, while rejecting mutating API requests before network dispatch. This guard @@ -164,8 +171,13 @@ least-privilege read against the intended service. ## Exit codes -Google API rate-limit retries honor `Retry-After` delays up to 60 seconds per -retry, including numeric seconds and HTTP dates. Cancelling the command also +Google API rate-limit retries cover HTTP 429 and HTTP 403 responses whose +reason is `rateLimitExceeded` or `userRateLimitExceeded`. Each request is +retried up to six times with exponential backoff and jitter (1s, 2s, 4s, ..., +63s to just under 94.5s in total), long enough for per-minute quotas such as Gmail's "Units per +minute per user" to refill. They honor +`Retry-After` delays up to 60 seconds per retry, including numeric seconds and +HTTP dates. Cancelling the command also cancels a pending retry wait. Upload bodies are closed even when a request is rejected by the circuit breaker or cannot be buffered for retry, so those failures release the associated file or stream resources. diff --git a/docs/backup.md b/docs/backup.md index 51720276e..3844dd50b 100644 --- a/docs/backup.md +++ b/docs/backup.md @@ -3,27 +3,38 @@ summary: "Encrypted Google account backups" read_when: - Adding a new gog backup service adapter - Changing encrypted backup layout, manifest fields, or age identity handling - - Debugging backup-gog push, status, or verify + - Debugging backup push, status, or verify --- # Encrypted Backups `gog backup` writes Google account data into a Git repository as age-encrypted -JSONL gzip shards. The intended repository is private, for example -`https://github.com/steipete/backup-gog`, but service payloads are encrypted -before Git sees them. +JSONL gzip shards. Backups stay local by default: there is no built-in remote. +Service payloads are encrypted before Git sees them. Choose a private repository +you control if you want to push backups. ## Commands -Initialize local config, create an age identity if needed, seed the backup repo, -and print the public recipient: +Initialize local config, create an age identity if needed, seed the local backup +repo, and print the public recipient: ```bash -gog backup init \ - --repo ~/Projects/backup-gog \ - --remote https://github.com/steipete/backup-gog.git +gog backup init --repo ~/Projects/backup-gog ``` +To enable pushing, explicitly configure your own remote: + +```bash +gog backup init --remote https://github.com/your-account/your-private-backup.git +``` + +`init` and `push` commit locally and explain that no upload happened when no +remote is configured. Existing backup configurations keep working after an +upgrade: explicitly saved remotes and existing Git `origin` URLs continue to +work without rewriting them. Configuring a remote after local +initialization adds `origin` only when it is missing. Checkpoint pushes follow +the same rule. + Back up all supported services: ```bash diff --git a/docs/chat-rich-messages.md b/docs/chat-rich-messages.md new file mode 100644 index 000000000..ac7459d1d --- /dev/null +++ b/docs/chat-rich-messages.md @@ -0,0 +1,115 @@ +# Chat rich messages + +Chat requires a Google Workspace account. + +## Read full messages + +```bash +gog --account you@example.com chat messages list spaces/AAA --json --full +gog --account you@example.com chat messages search 'release' --json --full --view full --markup markdown +gog --account you@example.com chat messages get spaces/AAA/messages/BBB --json +gog --account you@example.com chat messages get BBB --space AAA --plain +``` + +List and search keep their compact JSON and TSV defaults. `--full` is an output +mode and requires JSON; invalid combinations fail before credential/service +lookup. `--view full` is a separate **search provider option** for read/mute +metadata, subject to Google's available permissions. `--full` does not enable +that provider view automatically. `--markup chat|markdown` selects the provider's +formatted-text syntax on list, search, and get; omitting it leaves Google's +default unchanged. The syntax changes `formattedText`, which list/get expose +in full JSON; it does not change their plain-text summaries. + +Full list returns `{ "messages": [...], "nextPageToken": "..." }`, using Google's +`name` field instead of the compact `resource` alias. Full search keeps its +`results` envelope and paging aggregates; each result contains a full `message` +and available `read`/`spaceMuteSetting` metadata. Absent read state stays absent, +while explicit `false` stays false. Get and update return `{ "message": {...} }`. +Get/update text and plain output use the concise message summary columns. + +Full output serializes the current Google SDK `Message` type. It includes +SDK-known formatted text, annotations (including rich links), attachments, cards +V1/V2, GIFs, accessory widgets, emoji image references, and other message +metadata when returned by Google. Card-only messages are retained. This is +**typed output, not raw or lossless JSON**: unknown server fields and omitted +zero/empty fields are not preserved by the SDK. The feature does not render +cards, fetch image URLs, or download image/attachment bytes. URLs can expire or +require authorization. Full output makes no additional content-fetch requests. + +Paging options `--page`, `--all`, and `--fail-empty` retain their existing +behavior; exit code 3 reports empty results when requested. Full mode does not +change the server-side search, unread, thread, or ordering filters. + +## Consume content safely + +```bash +gog --readonly --account you@example.com chat messages list spaces/AAA \ + --full --json --wrap-untrusted --results-only \ + --select name,text,cardsV2,attachment +gog --readonly --account you@example.com chat messages get spaces/AAA/messages/BBB \ + --json --wrap-untrusted --results-only \ + --select name,cardsV2.0.card.header.title,cardsV2.0.card.header.imageUrl +``` + +`--wrap-untrusted` treats rich message strings conservatively, including card +text, titles/subtitles, labels, alt text, filenames, and button/action content. +Validated server-assigned resource names, opaque identifiers, and HTTP(S) URL +fields remain usable. Sender-defined card IDs, thread keys, client message IDs +and resource names containing client message IDs stay wrapped. A usable URL is +data, not a recommendation to fetch it or trust its contents. Malformed metadata +strings are wrapped too. Classification is scoped +to full Chat output and survives `--results-only` and dotted `--select` paths; +compact output keeps its existing mention/reaction filtering. Without wrapping, +SDK-known strings are emitted unchanged. + +## Replace text and delete + +```bash +# Preview without credentials or a Google request. +gog chat messages update spaces/AAA/messages/BBB --text='Replacement' --dry-run --json +gog chat messages delete spaces/AAA/messages/BBB --delete-replies --dry-run --json + +# Execute only for the intended account and message. +gog --account you@example.com chat messages update spaces/AAA/messages/BBB --text='Replacement' --json +gog --account you@example.com chat messages delete spaces/AAA/messages/BBB --force --no-input --json +``` + +`update` (alias `edit`) requires the **presence** of `--text`. `--text=''` sends +an explicit empty text field; Google can reject clearing a message if its rules +require content. The command always uses PATCH with `updateMask=text`. It does +not send cards or attachments, accept arbitrary masks, create a missing message, +or edit app cards. + +`delete` (aliases `rm`, `remove`, `del`) requires destructive confirmation. +Noninteractive execution, including `--no-input`, refuses without root `--force`. +Root `--force` only bypasses CLI confirmation. The separate `--delete-replies` +flag sets Google's API `force=true`, which deletes threaded replies as well. +Without it, API `force=false` is sent and Google refuses deletion of a message +with threaded replies. The JSON receipt is +`{ "deleted": "spaces/AAA/messages/BBB", "deleteReplies": false }` after success. +No success receipt is emitted for provider failures. + +After deletion, Google can return HTTP 200 with `deleteTime` and deletion metadata +when you get the message, rather than HTTP 404. That object is a deleted-message +tombstone. Deleted replies can instead return an ambiguous HTTP 403; the smoke +test requires a successful scoped thread listing with the target absent before +accepting that response as deletion evidence. Markdown formatting can wrap hyperlink labels +across lines; the smoke test normalizes whitespace when comparing the label. + +Existing Chat authorization includes `chat.messages`; no new scope is requested. +Google still enforces message ownership, authorization type, and Workspace +permissions. App-authenticated updates/deletions are restricted to messages +created by that app. A resource ID or CLI `--force` grants no additional Google +permission; permission and not-found errors are propagated. `--readonly` blocks +both mutations, and the `agent-safe` and `readonly` safety profiles allow get +and explicitly deny update/delete (including aliases). Dry runs make no Google +calls and never prompt. + +## Verification boundary + +Focused HTTP transport tests cover full/compact output boundaries, cards and +image/attachment metadata, paging, missing read metadata, resource normalization, +markup, cancellation, provider errors, wrapping/projection, exact PATCH bodies, +explicit empty text, confirmation, force separation, dry run, and readonly +blocking. These tests use fake services; they do not establish live Workspace +edit/delete permission or exercise real Google messages. diff --git a/docs/commands.generated.md b/docs/commands.generated.md index 000e1c1bf..183353edb 100644 --- a/docs/commands.generated.md +++ b/docs/commands.generated.md @@ -90,6 +90,7 @@ Generated from `gog schema --json`. - [`gog auth keyring [ []]`](commands/gog-auth-keyring.md) - Configure keyring backend - [`gog auth list [flags]`](commands/gog-auth-list.md) - List stored accounts - [`gog auth manage (login) [flags]`](commands/gog-auth-manage.md) - Open interactive accounts manager in browser + - [`gog auth rekey [flags]`](commands/gog-auth-rekey.md) - Write a verified copy of the file keyring to using GOG_KEYRING_NEW_PASSWORD; leave the live keyring untouched - [`gog auth remove `](commands/gog-auth-remove.md) - Remove a stored refresh token - [`gog auth service-account `](commands/gog-auth-service-account.md) - Configure service account (Workspace only; domain-wide delegation) - [`gog auth service-account set [flags]`](commands/gog-auth-service-account-set.md) - Store a service account key for impersonation @@ -148,6 +149,7 @@ Generated from `gog schema --json`. - [`gog calendar (cal) time [flags]`](commands/gog-calendar-time.md) - Show server time - [`gog calendar (cal) unsubscribe (unsub) `](commands/gog-calendar-unsubscribe.md) - Remove a calendar from your calendar list - [`gog calendar (cal) update (edit,set) [flags]`](commands/gog-calendar-update.md) - Update an event + - [`gog calendar (cal) update-calendar (edit-calendar,set-calendar) [flags]`](commands/gog-calendar-update-calendar.md) - Update calendar-level settings (summary, description, location, timezone) - [`gog calendar (cal) users [flags]`](commands/gog-calendar-users.md) - List workspace users (use their email as calendar ID) - [`gog calendar (cal) working-location (wl) --from=STRING --to=STRING --type=STRING [] [flags]`](commands/gog-calendar-working-location.md) - Set working location (home/office/custom) - [`gog chat [flags]`](commands/gog-chat.md) - Google Chat @@ -155,6 +157,8 @@ Generated from `gog schema --json`. - [`gog chat dm send (create,post) [flags]`](commands/gog-chat-dm-send.md) - Send a direct message - [`gog chat dm space (find,setup) `](commands/gog-chat-dm-space.md) - Find or create a DM space - [`gog chat messages `](commands/gog-chat-messages.md) - Chat messages + - [`gog chat messages delete (rm,remove,del) [flags]`](commands/gog-chat-messages-delete.md) - Delete a message + - [`gog chat messages get [flags]`](commands/gog-chat-messages-get.md) - Get a full message - [`gog chat messages list (ls) [flags]`](commands/gog-chat-messages-list.md) - List messages - [`gog chat messages react [flags]`](commands/gog-chat-messages-react.md) - Add an emoji reaction to a message - [`gog chat messages reactions (reaction) `](commands/gog-chat-messages-reactions.md) - Manage emoji reactions on a message @@ -163,6 +167,7 @@ Generated from `gog schema --json`. - [`gog chat messages reactions (reaction) list (ls) [flags]`](commands/gog-chat-messages-reactions-list.md) - List reactions on a message - [`gog chat messages search (find,query) ... [flags]`](commands/gog-chat-messages-search.md) - Search messages across Chat - [`gog chat messages send (create,post) [flags]`](commands/gog-chat-messages-send.md) - Send a message + - [`gog chat messages update (edit) [flags]`](commands/gog-chat-messages-update.md) - Replace message text - [`gog chat spaces `](commands/gog-chat-spaces.md) - Chat spaces - [`gog chat spaces create (add,new) [flags]`](commands/gog-chat-spaces-create.md) - Create a space - [`gog chat spaces find (search,query) [flags]`](commands/gog-chat-spaces-find.md) - Find spaces by display name diff --git a/docs/commands/README.md b/docs/commands/README.md index 1c05b3f86..e8b195744 100644 --- a/docs/commands/README.md +++ b/docs/commands/README.md @@ -2,7 +2,7 @@ Every `gog` command has a generated docs page. The source of truth is the live CLI schema; run `make docs-commands` after changing command names, flags, help text, aliases, or arguments. -Generated pages: 779. +Generated pages: 784. ## Top-level Commands @@ -144,6 +144,7 @@ Generated pages: 779. - [gog auth keyring](gog-auth-keyring.md) - Configure keyring backend - [gog auth list](gog-auth-list.md) - List stored accounts - [gog auth manage](gog-auth-manage.md) - Open interactive accounts manager in browser + - [gog auth rekey](gog-auth-rekey.md) - Write a verified copy of the file keyring to using GOG_KEYRING_NEW_PASSWORD; leave the live keyring untouched - [gog auth remove](gog-auth-remove.md) - Remove a stored refresh token - [gog auth service-account](gog-auth-service-account.md) - Configure service account (Workspace only; domain-wide delegation) - [gog auth service-account set](gog-auth-service-account-set.md) - Store a service account key for impersonation @@ -202,6 +203,7 @@ Generated pages: 779. - [gog calendar time](gog-calendar-time.md) - Show server time - [gog calendar unsubscribe](gog-calendar-unsubscribe.md) - Remove a calendar from your calendar list - [gog calendar update](gog-calendar-update.md) - Update an event + - [gog calendar update-calendar](gog-calendar-update-calendar.md) - Update calendar-level settings (summary, description, location, timezone) - [gog calendar users](gog-calendar-users.md) - List workspace users (use their email as calendar ID) - [gog calendar working-location](gog-calendar-working-location.md) - Set working location (home/office/custom) - [gog chat](gog-chat.md) - Google Chat @@ -209,6 +211,8 @@ Generated pages: 779. - [gog chat dm send](gog-chat-dm-send.md) - Send a direct message - [gog chat dm space](gog-chat-dm-space.md) - Find or create a DM space - [gog chat messages](gog-chat-messages.md) - Chat messages + - [gog chat messages delete](gog-chat-messages-delete.md) - Delete a message + - [gog chat messages get](gog-chat-messages-get.md) - Get a full message - [gog chat messages list](gog-chat-messages-list.md) - List messages - [gog chat messages react](gog-chat-messages-react.md) - Add an emoji reaction to a message - [gog chat messages reactions](gog-chat-messages-reactions.md) - Manage emoji reactions on a message @@ -217,6 +221,7 @@ Generated pages: 779. - [gog chat messages reactions list](gog-chat-messages-reactions-list.md) - List reactions on a message - [gog chat messages search](gog-chat-messages-search.md) - Search messages across Chat - [gog chat messages send](gog-chat-messages-send.md) - Send a message + - [gog chat messages update](gog-chat-messages-update.md) - Replace message text - [gog chat spaces](gog-chat-spaces.md) - Chat spaces - [gog chat spaces create](gog-chat-spaces-create.md) - Create a space - [gog chat spaces find](gog-chat-spaces-find.md) - Find spaces by display name diff --git a/docs/commands/gog-auth-add.md b/docs/commands/gog-auth-add.md index 9ea038e29..e77bebd66 100644 --- a/docs/commands/gog-auth-add.md +++ b/docs/commands/gog-auth-add.md @@ -48,7 +48,7 @@ gog auth add [flags] | `--remote` | `bool` | | Remote/server-friendly manual flow (print URL, then exchange code) | | `--results-only` | `bool` | | In JSON mode, emit only the primary result (drops envelope fields like nextPageToken) | | `--select`
`--pick`
`--project` | `string` | | In JSON mode, select comma-separated fields (best-effort; supports dot paths). Desire path: use --fields for most commands. | -| `--services` | `string` | user | Services to authorize: user\|all-user or comma-separated gmail,calendar,chat,classroom,drive,driveactivity,drivelabels,docs,slides,contacts,tasks,sheets,people,forms,sites,meet,appscript,analytics,searchconsole,ads,youtube,photos; explicit opt-in: adsense, photospicker; all means all default user OAuth services. Workspace service-account-only services: admin, groups, keep | +| `--services` | `string` | user | Services to authorize: user\|all-user or comma-separated gmail,calendar,chat,classroom,drive,driveactivity,drivelabels,docs,slides,contacts,tasks,sheets,people,forms,sites,meet,appscript,analytics,searchconsole,youtube,photos; explicit opt-in: adsense, ads, photospicker (combine with a preset, e.g. user,ads); all means all default user OAuth services. Workspace service-account-only services: admin, groups, keep | | `--step` | `int` | | Remote auth step: 1=print URL, 2=exchange code | | `--timeout` | `time.Duration` | | Authorization timeout (manual flows default to 5m) | | `-v`
`--verbose` | `bool` | | Enable verbose logging | diff --git a/docs/commands/gog-auth-manage.md b/docs/commands/gog-auth-manage.md index 27e50681c..094c53dad 100644 --- a/docs/commands/gog-auth-manage.md +++ b/docs/commands/gog-auth-manage.md @@ -40,7 +40,7 @@ gog auth manage (login) [flags] | `--redirect-host` | `string` | | Hostname for OAuth callback; builds https://{host}/oauth2/callback | | `--results-only` | `bool` | | In JSON mode, emit only the primary result (drops envelope fields like nextPageToken) | | `--select`
`--pick`
`--project` | `string` | | In JSON mode, select comma-separated fields (best-effort; supports dot paths). Desire path: use --fields for most commands. | -| `--services` | `string` | user | Services to authorize: user\|all-user or comma-separated gmail,calendar,chat,classroom,drive,driveactivity,drivelabels,docs,slides,contacts,tasks,sheets,people,forms,sites,meet,appscript,analytics,searchconsole,ads,youtube,photos; explicit opt-in: adsense, photospicker; all means all default user OAuth services. Workspace service-account-only services: admin, groups, keep | +| `--services` | `string` | user | Services to authorize: user\|all-user or comma-separated gmail,calendar,chat,classroom,drive,driveactivity,drivelabels,docs,slides,contacts,tasks,sheets,people,forms,sites,meet,appscript,analytics,searchconsole,youtube,photos; explicit opt-in: adsense, ads, photospicker (combine with a preset, e.g. user,ads); all means all default user OAuth services. Workspace service-account-only services: admin, groups, keep | | `--timeout` | `time.Duration` | 10m | Server timeout duration | | `-v`
`--verbose` | `bool` | | Enable verbose logging | | `--version` | `kong.VersionFlag` | | Print version and exit | diff --git a/docs/commands/gog-auth-rekey.md b/docs/commands/gog-auth-rekey.md new file mode 100644 index 000000000..e01c9491e --- /dev/null +++ b/docs/commands/gog-auth-rekey.md @@ -0,0 +1,48 @@ +# `gog auth rekey` + +> Generated from `gog schema --json`. Do not edit this page by hand; run `make docs-commands`. + +Write a verified copy of the file keyring to using GOG_KEYRING_NEW_PASSWORD; leave the live keyring untouched + +## Usage + +```bash +gog auth rekey [flags] +``` + +## Parent + +- [gog auth](gog-auth.md) + +## Flags + +| Flag | Type | Default | Help | +| --- | --- | --- | --- | +| `--access-token` | `string` | | Use provided access token directly (bypasses stored refresh tokens; token expires in ~1h) | +| `-a`
`--account`
`--acct` | `string` | | Account email, alias, or auto for authenticated Google API commands | +| `--client` | `string` | | OAuth client name (selects stored credentials + token bucket) | +| `--color` | `string` | auto | Color output: auto\|always\|never | +| `--disable-commands` | `string` | | Comma-separated list of disabled commands; dot paths allowed | +| `-n`
`--dry-run`
`--dryrun`
`--noop`
`--preview` | `bool` | | Do not make changes; print intended actions and exit successfully | +| `--enable-commands` | `string` | | Comma-separated list of enabled command prefixes; dot paths allowed (restricts CLI) | +| `--enable-commands-exact` | `string` | | Comma-separated list of exact enabled commands; dot paths allowed and parent commands do not enable children | +| `-y`
`--force`
`--assume-yes`
`--yes` | `bool` | | Skip confirmations for destructive commands | +| `--gmail-no-send` | `bool` | false | Block Gmail send operations (agent safety) | +| `-h`
`--help` | `kong.helpFlag` | | Show context-sensitive help. | +| `--home` | `string` | | Override gogcli config/data/state/cache root (equivalent to GOG_HOME) | +| `-j`
`--json`
`--machine` | `bool` | false | Output JSON to stdout (best for scripting) | +| `--no-input`
`--non-interactive`
`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) | +| `-p`
`--plain`
`--tsv` | `bool` | false | Output stable, parseable text to stdout (TSV; no colors) | +| `--quota-project` | `string` | | Google Cloud project to bill for API usage (sent as X-Goog-User-Project; some APIs require it with --access-token or ADC) | +| `--readonly` | `bool` | false | Block mutating API requests at runtime; auth add also requests read-only OAuth scopes | +| `--results-only` | `bool` | | In JSON mode, emit only the primary result (drops envelope fields like nextPageToken) | +| `--select`
`--pick`
`--project` | `string` | | In JSON mode, select comma-separated fields (best-effort; supports dot paths). Desire path: use --fields for most commands. | +| `--skip-unreadable` | `bool` | | Omit undecryptable items from output and report their keys; live items remain untouched | +| `-v`
`--verbose` | `bool` | | Enable verbose logging | +| `--version` | `kong.VersionFlag` | | Print version and exit | +| `--wrap-untrusted` | `bool` | false | In JSON/raw output, wrap fetched text fields in external untrusted-content markers | + +## See Also + +- [gog auth](gog-auth.md) +- [Command index](README.md) diff --git a/docs/commands/gog-auth-service-account-set.md b/docs/commands/gog-auth-service-account-set.md index db52f7767..6af527b64 100644 --- a/docs/commands/gog-auth-service-account-set.md +++ b/docs/commands/gog-auth-service-account-set.md @@ -34,6 +34,7 @@ gog auth service-account set [flags] | `--key` | `string` | | Path to service account JSON key file, or '-' for stdin | | `--key-env` | `string` | | Read service account JSON key from the named environment variable | | `--key-stdin` | `bool` | | Read service account JSON key from stdin | +| `--keyring` | `bool` | | Store the key in gog's keyring; the service account file keeps only a reference to it | | `--no-input`
`--non-interactive`
`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) | | `-p`
`--plain`
`--tsv` | `bool` | false | Output stable, parseable text to stdout (TSV; no colors) | | `--quota-project` | `string` | | Google Cloud project to bill for API usage (sent as X-Goog-User-Project; some APIs require it with --access-token or ADC) | diff --git a/docs/commands/gog-auth-setup.md b/docs/commands/gog-auth-setup.md index bd9e38454..c96a2aa0b 100644 --- a/docs/commands/gog-auth-setup.md +++ b/docs/commands/gog-auth-setup.md @@ -45,7 +45,7 @@ gog auth setup [] [flags] | `--readonly` | `bool` | false | Block mutating API requests at runtime; auth add also requests read-only OAuth scopes | | `--results-only` | `bool` | | In JSON mode, emit only the primary result (drops envelope fields like nextPageToken) | | `--select`
`--pick`
`--project` | `string` | | In JSON mode, select comma-separated fields (best-effort; supports dot paths). Desire path: use --fields for most commands. | -| `--services` | `string` | gmail,calendar,drive,docs,sheets,contacts | Services to configure: comma-separated gmail,calendar,chat,classroom,drive,driveactivity,drivelabels,docs,slides,contacts,tasks,sheets,people,forms,sites,meet,appscript,analytics,searchconsole,ads,youtube,photos | +| `--services` | `string` | gmail,calendar,drive,docs,sheets,contacts | Services to configure: comma-separated gmail,calendar,chat,classroom,drive,driveactivity,drivelabels,docs,slides,contacts,tasks,sheets,people,forms,sites,meet,appscript,analytics,searchconsole,youtube,photos | | `-v`
`--verbose` | `bool` | | Enable verbose logging | | `--version` | `kong.VersionFlag` | | Print version and exit | | `--wrap-untrusted` | `bool` | false | In JSON/raw output, wrap fetched text fields in external untrusted-content markers | diff --git a/docs/commands/gog-auth.md b/docs/commands/gog-auth.md index b32255fff..af2137e36 100644 --- a/docs/commands/gog-auth.md +++ b/docs/commands/gog-auth.md @@ -25,6 +25,7 @@ gog auth [flags] - [gog auth keyring](gog-auth-keyring.md) - Configure keyring backend - [gog auth list](gog-auth-list.md) - List stored accounts - [gog auth manage](gog-auth-manage.md) - Open interactive accounts manager in browser +- [gog auth rekey](gog-auth-rekey.md) - Write a verified copy of the file keyring to using GOG_KEYRING_NEW_PASSWORD; leave the live keyring untouched - [gog auth remove](gog-auth-remove.md) - Remove a stored refresh token - [gog auth service-account](gog-auth-service-account.md) - Configure service account (Workspace only; domain-wide delegation) - [gog auth services](gog-auth-services.md) - List supported auth services and scopes diff --git a/docs/commands/gog-calendar-update-calendar.md b/docs/commands/gog-calendar-update-calendar.md new file mode 100644 index 000000000..f77afb7af --- /dev/null +++ b/docs/commands/gog-calendar-update-calendar.md @@ -0,0 +1,52 @@ +# `gog calendar update-calendar` + +> Generated from `gog schema --json`. Do not edit this page by hand; run `make docs-commands`. + +Update calendar-level settings (summary, description, location, timezone) + +## Usage + +```bash +gog calendar (cal) update-calendar (edit-calendar,set-calendar) [flags] +``` + +## Parent + +- [gog calendar](gog-calendar.md) + +## Flags + +| Flag | Type | Default | Help | +| --- | --- | --- | --- | +| `--access-token` | `string` | | Use provided access token directly (bypasses stored refresh tokens; token expires in ~1h) | +| `-a`
`--account`
`--acct` | `string` | | Account email, alias, or auto for authenticated Google API commands | +| `--check` | `bool` | | Read-only: report the calendar and calendarList timezones and whether they diverge | +| `--client` | `string` | | OAuth client name (selects stored credentials + token bucket) | +| `--color` | `string` | auto | Color output: auto\|always\|never | +| `--description` | `*string` | | Calendar description (omit to preserve; pass '' to clear) | +| `--disable-commands` | `string` | | Comma-separated list of disabled commands; dot paths allowed | +| `-n`
`--dry-run`
`--dryrun`
`--noop`
`--preview` | `bool` | | Do not make changes; print intended actions and exit successfully | +| `--enable-commands` | `string` | | Comma-separated list of enabled command prefixes; dot paths allowed (restricts CLI) | +| `--enable-commands-exact` | `string` | | Comma-separated list of exact enabled commands; dot paths allowed and parent commands do not enable children | +| `-y`
`--force`
`--assume-yes`
`--yes` | `bool` | | Skip confirmations for destructive commands | +| `--gmail-no-send` | `bool` | false | Block Gmail send operations (agent safety) | +| `-h`
`--help` | `kong.helpFlag` | | Show context-sensitive help. | +| `--home` | `string` | | Override gogcli config/data/state/cache root (equivalent to GOG_HOME) | +| `-j`
`--json`
`--machine` | `bool` | false | Output JSON to stdout (best for scripting) | +| `--location` | `*string` | | Calendar location (omit to preserve; pass '' to clear) | +| `--no-input`
`--non-interactive`
`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) | +| `-p`
`--plain`
`--tsv` | `bool` | false | Output stable, parseable text to stdout (TSV; no colors) | +| `--quota-project` | `string` | | Google Cloud project to bill for API usage (sent as X-Goog-User-Project; some APIs require it with --access-token or ADC) | +| `--readonly` | `bool` | false | Block mutating API requests at runtime; auth add also requests read-only OAuth scopes | +| `--results-only` | `bool` | | In JSON mode, emit only the primary result (drops envelope fields like nextPageToken) | +| `--select`
`--pick`
`--project` | `string` | | In JSON mode, select comma-separated fields (best-effort; supports dot paths). Desire path: use --fields for most commands. | +| `--summary` | `*string` | | Calendar display name (nonempty; omit to preserve) | +| `--timezone`
`--tz` | `*string` | | IANA timezone for the calendar, e.g. America/Los_Angeles (omit to preserve) | +| `-v`
`--verbose` | `bool` | | Enable verbose logging | +| `--version` | `kong.VersionFlag` | | Print version and exit | +| `--wrap-untrusted` | `bool` | false | In JSON/raw output, wrap fetched text fields in external untrusted-content markers | + +## See Also + +- [gog calendar](gog-calendar.md) +- [Command index](README.md) diff --git a/docs/commands/gog-calendar.md b/docs/commands/gog-calendar.md index 82269a52b..bd3d1760a 100644 --- a/docs/commands/gog-calendar.md +++ b/docs/commands/gog-calendar.md @@ -41,6 +41,7 @@ gog calendar (cal) [flags] - [gog calendar time](gog-calendar-time.md) - Show server time - [gog calendar unsubscribe](gog-calendar-unsubscribe.md) - Remove a calendar from your calendar list - [gog calendar update](gog-calendar-update.md) - Update an event +- [gog calendar update-calendar](gog-calendar-update-calendar.md) - Update calendar-level settings (summary, description, location, timezone) - [gog calendar users](gog-calendar-users.md) - List workspace users (use their email as calendar ID) - [gog calendar working-location](gog-calendar-working-location.md) - Set working location (home/office/custom) diff --git a/docs/commands/gog-chat-messages-delete.md b/docs/commands/gog-chat-messages-delete.md new file mode 100644 index 000000000..7e6c83bad --- /dev/null +++ b/docs/commands/gog-chat-messages-delete.md @@ -0,0 +1,49 @@ +# `gog chat messages delete` + +> Generated from `gog schema --json`. Do not edit this page by hand; run `make docs-commands`. + +Delete a message + +## Usage + +```bash +gog chat messages delete (rm,remove,del) [flags] +``` + +## Parent + +- [gog chat messages](gog-chat-messages.md) + +## Flags + +| Flag | Type | Default | Help | +| --- | --- | --- | --- | +| `--access-token` | `string` | | Use provided access token directly (bypasses stored refresh tokens; token expires in ~1h) | +| `-a`
`--account`
`--acct` | `string` | | Account email, alias, or auto for authenticated Google API commands | +| `--client` | `string` | | OAuth client name (selects stored credentials + token bucket) | +| `--color` | `string` | auto | Color output: auto\|always\|never | +| `--delete-replies` | `bool` | | Also delete threaded replies (Google API force; distinct from CLI --force) | +| `--disable-commands` | `string` | | Comma-separated list of disabled commands; dot paths allowed | +| `-n`
`--dry-run`
`--dryrun`
`--noop`
`--preview` | `bool` | | Do not make changes; print intended actions and exit successfully | +| `--enable-commands` | `string` | | Comma-separated list of enabled command prefixes; dot paths allowed (restricts CLI) | +| `--enable-commands-exact` | `string` | | Comma-separated list of exact enabled commands; dot paths allowed and parent commands do not enable children | +| `-y`
`--force`
`--assume-yes`
`--yes` | `bool` | | Skip confirmations for destructive commands | +| `--gmail-no-send` | `bool` | false | Block Gmail send operations (agent safety) | +| `-h`
`--help` | `kong.helpFlag` | | Show context-sensitive help. | +| `--home` | `string` | | Override gogcli config/data/state/cache root (equivalent to GOG_HOME) | +| `-j`
`--json`
`--machine` | `bool` | false | Output JSON to stdout (best for scripting) | +| `--no-input`
`--non-interactive`
`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) | +| `-p`
`--plain`
`--tsv` | `bool` | false | Output stable, parseable text to stdout (TSV; no colors) | +| `--quota-project` | `string` | | Google Cloud project to bill for API usage (sent as X-Goog-User-Project; some APIs require it with --access-token or ADC) | +| `--readonly` | `bool` | false | Block mutating API requests at runtime; auth add also requests read-only OAuth scopes | +| `--results-only` | `bool` | | In JSON mode, emit only the primary result (drops envelope fields like nextPageToken) | +| `--select`
`--pick`
`--project` | `string` | | In JSON mode, select comma-separated fields (best-effort; supports dot paths). Desire path: use --fields for most commands. | +| `--space` | `string` | | Space name (required when message is a bare ID) | +| `-v`
`--verbose` | `bool` | | Enable verbose logging | +| `--version` | `kong.VersionFlag` | | Print version and exit | +| `--wrap-untrusted` | `bool` | false | In JSON/raw output, wrap fetched text fields in external untrusted-content markers | + +## See Also + +- [gog chat messages](gog-chat-messages.md) +- [Command index](README.md) diff --git a/docs/commands/gog-chat-messages-get.md b/docs/commands/gog-chat-messages-get.md new file mode 100644 index 000000000..fd6631d21 --- /dev/null +++ b/docs/commands/gog-chat-messages-get.md @@ -0,0 +1,49 @@ +# `gog chat messages get` + +> Generated from `gog schema --json`. Do not edit this page by hand; run `make docs-commands`. + +Get a full message + +## Usage + +```bash +gog chat messages get [flags] +``` + +## Parent + +- [gog chat messages](gog-chat-messages.md) + +## Flags + +| Flag | Type | Default | Help | +| --- | --- | --- | --- | +| `--access-token` | `string` | | Use provided access token directly (bypasses stored refresh tokens; token expires in ~1h) | +| `-a`
`--account`
`--acct` | `string` | | Account email, alias, or auto for authenticated Google API commands | +| `--client` | `string` | | OAuth client name (selects stored credentials + token bucket) | +| `--color` | `string` | auto | Color output: auto\|always\|never | +| `--disable-commands` | `string` | | Comma-separated list of disabled commands; dot paths allowed | +| `-n`
`--dry-run`
`--dryrun`
`--noop`
`--preview` | `bool` | | Do not make changes; print intended actions and exit successfully | +| `--enable-commands` | `string` | | Comma-separated list of enabled command prefixes; dot paths allowed (restricts CLI) | +| `--enable-commands-exact` | `string` | | Comma-separated list of exact enabled commands; dot paths allowed and parent commands do not enable children | +| `-y`
`--force`
`--assume-yes`
`--yes` | `bool` | | Skip confirmations for destructive commands | +| `--gmail-no-send` | `bool` | false | Block Gmail send operations (agent safety) | +| `-h`
`--help` | `kong.helpFlag` | | Show context-sensitive help. | +| `--home` | `string` | | Override gogcli config/data/state/cache root (equivalent to GOG_HOME) | +| `-j`
`--json`
`--machine` | `bool` | false | Output JSON to stdout (best for scripting) | +| `--markup` | `string` | | Formatted text syntax: chat or markdown | +| `--no-input`
`--non-interactive`
`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) | +| `-p`
`--plain`
`--tsv` | `bool` | false | Output stable, parseable text to stdout (TSV; no colors) | +| `--quota-project` | `string` | | Google Cloud project to bill for API usage (sent as X-Goog-User-Project; some APIs require it with --access-token or ADC) | +| `--readonly` | `bool` | false | Block mutating API requests at runtime; auth add also requests read-only OAuth scopes | +| `--results-only` | `bool` | | In JSON mode, emit only the primary result (drops envelope fields like nextPageToken) | +| `--select`
`--pick`
`--project` | `string` | | In JSON mode, select comma-separated fields (best-effort; supports dot paths). Desire path: use --fields for most commands. | +| `--space` | `string` | | Space name (required when message is a bare ID) | +| `-v`
`--verbose` | `bool` | | Enable verbose logging | +| `--version` | `kong.VersionFlag` | | Print version and exit | +| `--wrap-untrusted` | `bool` | false | In JSON/raw output, wrap fetched text fields in external untrusted-content markers | + +## See Also + +- [gog chat messages](gog-chat-messages.md) +- [Command index](README.md) diff --git a/docs/commands/gog-chat-messages-list.md b/docs/commands/gog-chat-messages-list.md index e97d3ecdd..1fdd5c462 100644 --- a/docs/commands/gog-chat-messages-list.md +++ b/docs/commands/gog-chat-messages-list.md @@ -29,10 +29,12 @@ gog chat messages list (ls) [flags] | `--enable-commands-exact` | `string` | | Comma-separated list of exact enabled commands; dot paths allowed and parent commands do not enable children | | `--fail-empty`
`--non-empty`
`--require-results` | `bool` | | Exit with code 3 if no results | | `-y`
`--force`
`--assume-yes`
`--yes` | `bool` | | Skip confirmations for destructive commands | +| `--full` | `bool` | | Return full SDK messages (requires --json) | | `--gmail-no-send` | `bool` | false | Block Gmail send operations (agent safety) | | `-h`
`--help` | `kong.helpFlag` | | Show context-sensitive help. | | `--home` | `string` | | Override gogcli config/data/state/cache root (equivalent to GOG_HOME) | | `-j`
`--json`
`--machine` | `bool` | false | Output JSON to stdout (best for scripting) | +| `--markup` | `string` | | Formatted text syntax: chat or markdown | | `--max`
`--limit` | `int64` | 50 | Max results | | `--no-input`
`--non-interactive`
`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) | | `--order` | `string` | | Order by (e.g. createTime desc) | diff --git a/docs/commands/gog-chat-messages-search.md b/docs/commands/gog-chat-messages-search.md index 9eb422c8f..b9e8a93b8 100644 --- a/docs/commands/gog-chat-messages-search.md +++ b/docs/commands/gog-chat-messages-search.md @@ -29,6 +29,7 @@ gog chat messages search (find,query) ... [flags] | `--enable-commands-exact` | `string` | | Comma-separated list of exact enabled commands; dot paths allowed and parent commands do not enable children | | `--fail-empty`
`--non-empty`
`--require-results` | `bool` | | Exit with code 3 if no results | | `-y`
`--force`
`--assume-yes`
`--yes` | `bool` | | Skip confirmations for destructive commands | +| `--full` | `bool` | | Return full SDK messages and search metadata (requires --json) | | `--gmail-no-send` | `bool` | false | Block Gmail send operations (agent safety) | | `-h`
`--help` | `kong.helpFlag` | | Show context-sensitive help. | | `--home` | `string` | | Override gogcli config/data/state/cache root (equivalent to GOG_HOME) | diff --git a/docs/commands/gog-chat-messages-update.md b/docs/commands/gog-chat-messages-update.md new file mode 100644 index 000000000..a57fb561c --- /dev/null +++ b/docs/commands/gog-chat-messages-update.md @@ -0,0 +1,49 @@ +# `gog chat messages update` + +> Generated from `gog schema --json`. Do not edit this page by hand; run `make docs-commands`. + +Replace message text + +## Usage + +```bash +gog chat messages update (edit) [flags] +``` + +## Parent + +- [gog chat messages](gog-chat-messages.md) + +## Flags + +| Flag | Type | Default | Help | +| --- | --- | --- | --- | +| `--access-token` | `string` | | Use provided access token directly (bypasses stored refresh tokens; token expires in ~1h) | +| `-a`
`--account`
`--acct` | `string` | | Account email, alias, or auto for authenticated Google API commands | +| `--client` | `string` | | OAuth client name (selects stored credentials + token bucket) | +| `--color` | `string` | auto | Color output: auto\|always\|never | +| `--disable-commands` | `string` | | Comma-separated list of disabled commands; dot paths allowed | +| `-n`
`--dry-run`
`--dryrun`
`--noop`
`--preview` | `bool` | | Do not make changes; print intended actions and exit successfully | +| `--enable-commands` | `string` | | Comma-separated list of enabled command prefixes; dot paths allowed (restricts CLI) | +| `--enable-commands-exact` | `string` | | Comma-separated list of exact enabled commands; dot paths allowed and parent commands do not enable children | +| `-y`
`--force`
`--assume-yes`
`--yes` | `bool` | | Skip confirmations for destructive commands | +| `--gmail-no-send` | `bool` | false | Block Gmail send operations (agent safety) | +| `-h`
`--help` | `kong.helpFlag` | | Show context-sensitive help. | +| `--home` | `string` | | Override gogcli config/data/state/cache root (equivalent to GOG_HOME) | +| `-j`
`--json`
`--machine` | `bool` | false | Output JSON to stdout (best for scripting) | +| `--no-input`
`--non-interactive`
`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) | +| `-p`
`--plain`
`--tsv` | `bool` | false | Output stable, parseable text to stdout (TSV; no colors) | +| `--quota-project` | `string` | | Google Cloud project to bill for API usage (sent as X-Goog-User-Project; some APIs require it with --access-token or ADC) | +| `--readonly` | `bool` | false | Block mutating API requests at runtime; auth add also requests read-only OAuth scopes | +| `--results-only` | `bool` | | In JSON mode, emit only the primary result (drops envelope fields like nextPageToken) | +| `--select`
`--pick`
`--project` | `string` | | In JSON mode, select comma-separated fields (best-effort; supports dot paths). Desire path: use --fields for most commands. | +| `--space` | `string` | | Space name (required when message is a bare ID) | +| `--text` | `*string` | | Replacement message text (required; empty explicitly clears text) | +| `-v`
`--verbose` | `bool` | | Enable verbose logging | +| `--version` | `kong.VersionFlag` | | Print version and exit | +| `--wrap-untrusted` | `bool` | false | In JSON/raw output, wrap fetched text fields in external untrusted-content markers | + +## See Also + +- [gog chat messages](gog-chat-messages.md) +- [Command index](README.md) diff --git a/docs/commands/gog-chat-messages.md b/docs/commands/gog-chat-messages.md index 503ee6f75..d261b3926 100644 --- a/docs/commands/gog-chat-messages.md +++ b/docs/commands/gog-chat-messages.md @@ -16,11 +16,14 @@ gog chat messages ## Subcommands +- [gog chat messages delete](gog-chat-messages-delete.md) - Delete a message +- [gog chat messages get](gog-chat-messages-get.md) - Get a full message - [gog chat messages list](gog-chat-messages-list.md) - List messages - [gog chat messages react](gog-chat-messages-react.md) - Add an emoji reaction to a message - [gog chat messages reactions](gog-chat-messages-reactions.md) - Manage emoji reactions on a message - [gog chat messages search](gog-chat-messages-search.md) - Search messages across Chat - [gog chat messages send](gog-chat-messages-send.md) - Send a message +- [gog chat messages update](gog-chat-messages-update.md) - Replace message text ## Flags diff --git a/docs/commands/gog-contacts-other-search.md b/docs/commands/gog-contacts-other-search.md index f497569ab..88330da04 100644 --- a/docs/commands/gog-contacts-other-search.md +++ b/docs/commands/gog-contacts-other-search.md @@ -31,7 +31,7 @@ gog contacts (contact) other search ... [flags] | `-h`
`--help` | `kong.helpFlag` | | Show context-sensitive help. | | `--home` | `string` | | Override gogcli config/data/state/cache root (equivalent to GOG_HOME) | | `-j`
`--json`
`--machine` | `bool` | false | Output JSON to stdout (best for scripting) | -| `--max`
`--limit` | `int64` | 50 | Max results | +| `--max`
`--limit` | `int64` | 30 | Max results (Google returns at most 30) | | `--no-input`
`--non-interactive`
`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) | | `-p`
`--plain`
`--tsv` | `bool` | false | Output stable, parseable text to stdout (TSV; no colors) | | `--quota-project` | `string` | | Google Cloud project to bill for API usage (sent as X-Goog-User-Project; some APIs require it with --access-token or ADC) | diff --git a/docs/commands/gog-contacts-search.md b/docs/commands/gog-contacts-search.md index 43062069e..2b1c7b568 100644 --- a/docs/commands/gog-contacts-search.md +++ b/docs/commands/gog-contacts-search.md @@ -31,7 +31,7 @@ gog contacts (contact) search ... [flags] | `-h`
`--help` | `kong.helpFlag` | | Show context-sensitive help. | | `--home` | `string` | | Override gogcli config/data/state/cache root (equivalent to GOG_HOME) | | `-j`
`--json`
`--machine` | `bool` | false | Output JSON to stdout (best for scripting) | -| `--max`
`--limit` | `int64` | 50 | Max results | +| `--max`
`--limit` | `int64` | 30 | Max results (Google returns at most 30) | | `--no-input`
`--non-interactive`
`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) | | `-p`
`--plain`
`--tsv` | `bool` | false | Output stable, parseable text to stdout (TSV; no colors) | | `--quota-project` | `string` | | Google Cloud project to bill for API usage (sent as X-Goog-User-Project; some APIs require it with --access-token or ADC) | diff --git a/docs/commands/gog-gmail-autoreply.md b/docs/commands/gog-gmail-autoreply.md index e925bdfa4..4f5ec0265 100644 --- a/docs/commands/gog-gmail-autoreply.md +++ b/docs/commands/gog-gmail-autoreply.md @@ -36,6 +36,7 @@ gog gmail (mail,email) autoreply ... [flags] | `--gmail-no-send` | `bool` | false | Block Gmail send operations (agent safety) | | `-h`
`--help` | `kong.helpFlag` | | Show context-sensitive help. | | `--home` | `string` | | Override gogcli config/data/state/cache root (equivalent to GOG_HOME) | +| `--html-from-text` | `bool` | | When only a plain body is given, also send it as HTML so Gmail web reflows paragraphs instead of breaking lines about every 70 characters | | `-j`
`--json`
`--machine` | `bool` | false | Output JSON to stdout (best for scripting) | | `--label` | `string` | AutoReplied | Label to add after replying (used for dedupe) | | `--mark-read` | `bool` | | Mark threads as read after auto-replying | diff --git a/docs/commands/gog-gmail-drafts-create.md b/docs/commands/gog-gmail-drafts-create.md index 34d9b0fad..1b71c4312 100644 --- a/docs/commands/gog-gmail-drafts-create.md +++ b/docs/commands/gog-gmail-drafts-create.md @@ -39,6 +39,7 @@ gog gmail (mail,email) drafts (draft) create (add,new) [flags] | `--gmail-no-send` | `bool` | false | Block Gmail send operations (agent safety) | | `-h`
`--help` | `kong.helpFlag` | | Show context-sensitive help. | | `--home` | `string` | | Override gogcli config/data/state/cache root (equivalent to GOG_HOME) | +| `--html-from-text` | `bool` | | When only a plain body is given, also send it as HTML so Gmail web reflows paragraphs instead of breaking lines about every 70 characters | | `-j`
`--json`
`--machine` | `bool` | false | Output JSON to stdout (best for scripting) | | `--no-input`
`--non-interactive`
`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) | | `-p`
`--plain`
`--tsv` | `bool` | false | Output stable, parseable text to stdout (TSV; no colors) | diff --git a/docs/commands/gog-gmail-drafts-forward.md b/docs/commands/gog-gmail-drafts-forward.md index 280a120c5..3d7066a82 100644 --- a/docs/commands/gog-gmail-drafts-forward.md +++ b/docs/commands/gog-gmail-drafts-forward.md @@ -37,6 +37,8 @@ gog gmail (mail,email) drafts (draft) forward (fwd) [flags] | `--no-input`
`--non-interactive`
`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) | | `--note`
`--intro` | `string` | | Introductory text above the forwarded message | | `--note-file` | `string` | | Note file path (plain text; '-' for stdin) | +| `--note-html` | `string` | | Introductory HTML above the forwarded message | +| `--note-html-file` | `string` | | HTML note file path ('-' for stdin) | | `-p`
`--plain`
`--tsv` | `bool` | false | Output stable, parseable text to stdout (TSV; no colors) | | `--quota-project` | `string` | | Google Cloud project to bill for API usage (sent as X-Goog-User-Project; some APIs require it with --access-token or ADC) | | `--readonly` | `bool` | false | Block mutating API requests at runtime; auth add also requests read-only OAuth scopes | diff --git a/docs/commands/gog-gmail-drafts-reply-all.md b/docs/commands/gog-gmail-drafts-reply-all.md index d359eadad..cae26ec85 100644 --- a/docs/commands/gog-gmail-drafts-reply-all.md +++ b/docs/commands/gog-gmail-drafts-reply-all.md @@ -39,6 +39,7 @@ gog gmail (mail,email) drafts (draft) reply-all (replyall) [flags] | `--gmail-no-send` | `bool` | false | Block Gmail send operations (agent safety) | | `-h`
`--help` | `kong.helpFlag` | | Show context-sensitive help. | | `--home` | `string` | | Override gogcli config/data/state/cache root (equivalent to GOG_HOME) | +| `--html-from-text` | `bool` | | When only a plain body is given, also send it as HTML so Gmail web reflows paragraphs instead of breaking lines about every 70 characters | | `-j`
`--json`
`--machine` | `bool` | false | Output JSON to stdout (best for scripting) | | `--missing-inline-images` | `string` | error | Missing quoted CID images: error or visible placeholders (drafts only) | | `--no-input`
`--non-interactive`
`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) | diff --git a/docs/commands/gog-gmail-drafts-reply.md b/docs/commands/gog-gmail-drafts-reply.md index 6a1eff013..8954387eb 100644 --- a/docs/commands/gog-gmail-drafts-reply.md +++ b/docs/commands/gog-gmail-drafts-reply.md @@ -39,6 +39,7 @@ gog gmail (mail,email) drafts (draft) reply [flags] | `--gmail-no-send` | `bool` | false | Block Gmail send operations (agent safety) | | `-h`
`--help` | `kong.helpFlag` | | Show context-sensitive help. | | `--home` | `string` | | Override gogcli config/data/state/cache root (equivalent to GOG_HOME) | +| `--html-from-text` | `bool` | | When only a plain body is given, also send it as HTML so Gmail web reflows paragraphs instead of breaking lines about every 70 characters | | `-j`
`--json`
`--machine` | `bool` | false | Output JSON to stdout (best for scripting) | | `--missing-inline-images` | `string` | error | Missing quoted CID images: error or visible placeholders (drafts only) | | `--no-input`
`--non-interactive`
`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) | diff --git a/docs/commands/gog-gmail-drafts-update.md b/docs/commands/gog-gmail-drafts-update.md index 4f0fd448d..0a7cd0faa 100644 --- a/docs/commands/gog-gmail-drafts-update.md +++ b/docs/commands/gog-gmail-drafts-update.md @@ -41,6 +41,7 @@ gog gmail (mail,email) drafts (draft) update (edit,set) [flags] | `--gmail-no-send` | `bool` | false | Block Gmail send operations (agent safety) | | `-h`
`--help` | `kong.helpFlag` | | Show context-sensitive help. | | `--home` | `string` | | Override gogcli config/data/state/cache root (equivalent to GOG_HOME) | +| `--html-from-text` | `bool` | | When only a plain body is given, also send it as HTML so Gmail web reflows paragraphs instead of breaking lines about every 70 characters | | `-j`
`--json`
`--machine` | `bool` | false | Output JSON to stdout (best for scripting) | | `--no-input`
`--non-interactive`
`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) | | `-p`
`--plain`
`--tsv` | `bool` | false | Output stable, parseable text to stdout (TSV; no colors) | diff --git a/docs/commands/gog-gmail-forward.md b/docs/commands/gog-gmail-forward.md index 9bea9ff86..4cd946047 100644 --- a/docs/commands/gog-gmail-forward.md +++ b/docs/commands/gog-gmail-forward.md @@ -37,6 +37,8 @@ gog gmail (mail,email) forward (fwd) [flags] | `--no-input`
`--non-interactive`
`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) | | `--note`
`--intro` | `string` | | Introductory text above the forwarded message | | `--note-file` | `string` | | Note file path (plain text; '-' for stdin) | +| `--note-html` | `string` | | Introductory HTML above the forwarded message | +| `--note-html-file` | `string` | | HTML note file path ('-' for stdin) | | `-p`
`--plain`
`--tsv` | `bool` | false | Output stable, parseable text to stdout (TSV; no colors) | | `--quota-project` | `string` | | Google Cloud project to bill for API usage (sent as X-Goog-User-Project; some APIs require it with --access-token or ADC) | | `--readonly` | `bool` | false | Block mutating API requests at runtime; auth add also requests read-only OAuth scopes | diff --git a/docs/commands/gog-gmail-messages-search.md b/docs/commands/gog-gmail-messages-search.md index fe40727ea..534b941c4 100644 --- a/docs/commands/gog-gmail-messages-search.md +++ b/docs/commands/gog-gmail-messages-search.md @@ -33,8 +33,10 @@ gog gmail (mail,email) messages (message,msg,msgs) search (find,query,ls,list) < | `-y`
`--force`
`--assume-yes`
`--yes` | `bool` | | Skip confirmations for destructive commands | | `--full` | `bool` | | Show full message bodies without truncation (implies --include-body) | | `--gmail-no-send` | `bool` | false | Block Gmail send operations (agent safety) | +| `--headers` | `string` | | Include up to 50 headers in JSON output under headers (comma-separated, max 256 bytes per name; canonical keys, e.g. Message-ID becomes Message-Id; first value if repeated; no extra API calls) | | `-h`
`--help` | `kong.helpFlag` | | Show context-sensitive help. | | `--home` | `string` | | Override gogcli config/data/state/cache root (equivalent to GOG_HOME) | +| `--ids-only` | `bool` | | Return only message and thread IDs from the list call, skipping the label lookup and per-message fetch (use --max 500 for the largest pages) | | `--include-attachments` | `bool` | | Include each message's attachment metadata | | `--include-body` | `bool` | | Include decoded message body (JSON is full; text output truncates only unusually large bodies) | | `--include-recipients` | `bool` | | Include To, Cc, and Bcc in JSON output (no extra API calls) | diff --git a/docs/commands/gog-gmail-reply-all.md b/docs/commands/gog-gmail-reply-all.md index 0549698dd..b55ef2877 100644 --- a/docs/commands/gog-gmail-reply-all.md +++ b/docs/commands/gog-gmail-reply-all.md @@ -39,6 +39,7 @@ gog gmail (mail,email) reply-all (replyall) [flags] | `--gmail-no-send` | `bool` | false | Block Gmail send operations (agent safety) | | `-h`
`--help` | `kong.helpFlag` | | Show context-sensitive help. | | `--home` | `string` | | Override gogcli config/data/state/cache root (equivalent to GOG_HOME) | +| `--html-from-text` | `bool` | | When only a plain body is given, also send it as HTML so Gmail web reflows paragraphs instead of breaking lines about every 70 characters | | `-j`
`--json`
`--machine` | `bool` | false | Output JSON to stdout (best for scripting) | | `--no-input`
`--non-interactive`
`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) | | `--no-quote` | `bool` | | Do not include the original message below the reply | diff --git a/docs/commands/gog-gmail-reply.md b/docs/commands/gog-gmail-reply.md index 454fade65..dbe1e5c4c 100644 --- a/docs/commands/gog-gmail-reply.md +++ b/docs/commands/gog-gmail-reply.md @@ -39,6 +39,7 @@ gog gmail (mail,email) reply [flags] | `--gmail-no-send` | `bool` | false | Block Gmail send operations (agent safety) | | `-h`
`--help` | `kong.helpFlag` | | Show context-sensitive help. | | `--home` | `string` | | Override gogcli config/data/state/cache root (equivalent to GOG_HOME) | +| `--html-from-text` | `bool` | | When only a plain body is given, also send it as HTML so Gmail web reflows paragraphs instead of breaking lines about every 70 characters | | `-j`
`--json`
`--machine` | `bool` | false | Output JSON to stdout (best for scripting) | | `--no-input`
`--non-interactive`
`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) | | `--no-quote` | `bool` | | Do not include the original message below the reply | diff --git a/docs/commands/gog-gmail-search.md b/docs/commands/gog-gmail-search.md index 8c9e2bc44..9964f205b 100644 --- a/docs/commands/gog-gmail-search.md +++ b/docs/commands/gog-gmail-search.md @@ -34,6 +34,7 @@ gog gmail (mail,email) search (find,query,ls,list) ... [flags] | `--gmail-no-send` | `bool` | false | Block Gmail send operations (agent safety) | | `-h`
`--help` | `kong.helpFlag` | | Show context-sensitive help. | | `--home` | `string` | | Override gogcli config/data/state/cache root (equivalent to GOG_HOME) | +| `--ids-only` | `bool` | | Return only thread IDs from the list call, skipping the label lookup and per-thread fetch (use --max 500 for the largest pages) | | `-j`
`--json`
`--machine` | `bool` | false | Output JSON to stdout (best for scripting) | | `--local` | `bool` | | Use local timezone (default behavior, useful to override --timezone) | | `--max`
`--limit` | `int64` | 10 | Max results | diff --git a/docs/commands/gog-gmail-send.md b/docs/commands/gog-gmail-send.md index 2f02e73a8..61e90977a 100644 --- a/docs/commands/gog-gmail-send.md +++ b/docs/commands/gog-gmail-send.md @@ -38,6 +38,7 @@ gog gmail (mail,email) send [flags] | `--gmail-no-send` | `bool` | false | Block Gmail send operations (agent safety) | | `-h`
`--help` | `kong.helpFlag` | | Show context-sensitive help. | | `--home` | `string` | | Override gogcli config/data/state/cache root (equivalent to GOG_HOME) | +| `--html-from-text` | `bool` | | When only a plain body is given, also send it as HTML so Gmail web reflows paragraphs instead of breaking lines about every 70 characters | | `-j`
`--json`
`--machine` | `bool` | false | Output JSON to stdout (best for scripting) | | `--no-input`
`--non-interactive`
`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) | | `-p`
`--plain`
`--tsv` | `bool` | false | Output stable, parseable text to stdout (TSV; no colors) | diff --git a/docs/commands/gog-gmail-settings-watch-serve.md b/docs/commands/gog-gmail-settings-watch-serve.md index e1b21319c..cd5189f5a 100644 --- a/docs/commands/gog-gmail-settings-watch-serve.md +++ b/docs/commands/gog-gmail-settings-watch-serve.md @@ -35,6 +35,7 @@ gog gmail (mail,email) settings watch serve [flags] | `--history-types` | `[]string` | | History types to include (repeatable, comma-separated: messageAdded,messageDeleted,labelAdded,labelRemoved). Default: messageAdded | | `--home` | `string` | | Override gogcli config/data/state/cache root (equivalent to GOG_HOME) | | `--hook-token` | `string` | | Webhook bearer token | +| `--hook-token-env` | `string` | | Read webhook bearer token from the named environment variable | | `--hook-url` | `string` | | Webhook URL to forward messages | | `--include-body` | `bool` | | Include text/plain body in hook payload | | `-j`
`--json`
`--machine` | `bool` | false | Output JSON to stdout (best for scripting) | @@ -53,6 +54,7 @@ gog gmail (mail,email) settings watch serve [flags] | `--select`
`--pick`
`--project` | `string` | | In JSON mode, select comma-separated fields (best-effort; supports dot paths). Desire path: use --fields for most commands. | | `-z`
`--timezone` | `string` | | Output timezone (IANA name, e.g. America/New_York, UTC). Default: GOG_TIMEZONE, config, then local | | `--token` | `string` | | Shared token for x-gog-token or ?token= | +| `--token-env` | `string` | | Read shared token from the named environment variable | | `-v`
`--verbose` | `bool` | | Enable verbose logging | | `--verify-oidc` | `bool` | | Verify Pub/Sub OIDC tokens | | `--version` | `kong.VersionFlag` | | Print version and exit | diff --git a/docs/commands/gog-login.md b/docs/commands/gog-login.md index a9ba287a1..ecec454a7 100644 --- a/docs/commands/gog-login.md +++ b/docs/commands/gog-login.md @@ -48,7 +48,7 @@ gog login [flags] | `--remote` | `bool` | | Remote/server-friendly manual flow (print URL, then exchange code) | | `--results-only` | `bool` | | In JSON mode, emit only the primary result (drops envelope fields like nextPageToken) | | `--select`
`--pick`
`--project` | `string` | | In JSON mode, select comma-separated fields (best-effort; supports dot paths). Desire path: use --fields for most commands. | -| `--services` | `string` | user | Services to authorize: user\|all-user or comma-separated gmail,calendar,chat,classroom,drive,driveactivity,drivelabels,docs,slides,contacts,tasks,sheets,people,forms,sites,meet,appscript,analytics,searchconsole,ads,youtube,photos; explicit opt-in: adsense, photospicker; all means all default user OAuth services. Workspace service-account-only services: admin, groups, keep | +| `--services` | `string` | user | Services to authorize: user\|all-user or comma-separated gmail,calendar,chat,classroom,drive,driveactivity,drivelabels,docs,slides,contacts,tasks,sheets,people,forms,sites,meet,appscript,analytics,searchconsole,youtube,photos; explicit opt-in: adsense, ads, photospicker (combine with a preset, e.g. user,ads); all means all default user OAuth services. Workspace service-account-only services: admin, groups, keep | | `--step` | `int` | | Remote auth step: 1=print URL, 2=exchange code | | `--timeout` | `time.Duration` | | Authorization timeout (manual flows default to 5m) | | `-v`
`--verbose` | `bool` | | Enable verbose logging | diff --git a/docs/commands/gog-send.md b/docs/commands/gog-send.md index 4e16476c4..f138b00b6 100644 --- a/docs/commands/gog-send.md +++ b/docs/commands/gog-send.md @@ -38,6 +38,7 @@ gog send [flags] | `--gmail-no-send` | `bool` | false | Block Gmail send operations (agent safety) | | `-h`
`--help` | `kong.helpFlag` | | Show context-sensitive help. | | `--home` | `string` | | Override gogcli config/data/state/cache root (equivalent to GOG_HOME) | +| `--html-from-text` | `bool` | | When only a plain body is given, also send it as HTML so Gmail web reflows paragraphs instead of breaking lines about every 70 characters | | `-j`
`--json`
`--machine` | `bool` | false | Output JSON to stdout (best for scripting) | | `--no-input`
`--non-interactive`
`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) | | `-p`
`--plain`
`--tsv` | `bool` | false | Output stable, parseable text to stdout (TSV; no colors) | diff --git a/docs/commands/gog-tasks-update.md b/docs/commands/gog-tasks-update.md index c4f543c0a..1bf05b464 100644 --- a/docs/commands/gog-tasks-update.md +++ b/docs/commands/gog-tasks-update.md @@ -39,7 +39,7 @@ gog tasks (task) update (edit,set) [flags] | `--readonly` | `bool` | false | Block mutating API requests at runtime; auth add also requests read-only OAuth scopes | | `--results-only` | `bool` | | In JSON mode, emit only the primary result (drops envelope fields like nextPageToken) | | `--select`
`--pick`
`--project` | `string` | | In JSON mode, select comma-separated fields (best-effort; supports dot paths). Desire path: use --fields for most commands. | -| `--status` | `string` | | New status: needsAction\|completed (set empty to clear) | +| `--status` | `string` | | New status: needsAction\|completed | | `--title` | `string` | | New title (set empty to clear) | | `-v`
`--verbose` | `bool` | | Enable verbose logging | | `--version` | `kong.VersionFlag` | | Print version and exit | diff --git a/docs/dates.md b/docs/dates.md index 008230a82..921832214 100644 --- a/docs/dates.md +++ b/docs/dates.md @@ -24,6 +24,17 @@ Calendar range flags (`--from` / `--to`) also accept: - `now`, `today`, `tomorrow`, `yesterday` - Weekday names: `monday`, `next friday` +## Calendar windows + +Calendar range commands reject equal or reversed bounds as usage errors before +requesting events. Bounds must span at least one second at the API's precision. +Date-only `--to` values include that whole day. + +`calendar search` defaults to 30 days before now through 90 days after now. A +historical `--from` with no `--to` keeps the end at now + 90 days. If an explicit +start would meet or exceed that default end, the search instead ends 90 days +after the start. Pass both bounds for an exact window. + ## Duration forms Tracking `--since` also accepts `time.ParseDuration` values such as: diff --git a/docs/drive-audits.md b/docs/drive-audits.md index 50377393a..fe3dacff1 100644 --- a/docs/drive-audits.md +++ b/docs/drive-audits.md @@ -94,7 +94,7 @@ gog drive audit sharing --parent --public-only --fail-found Find files shared with a specific user: ```bash -gog drive audit user clawdbot@gmail.com --parent --json +gog drive audit user user@example.com --parent --json ``` Bulk permission operations are intentionally separate from audits and require a diff --git a/docs/examples.md b/docs/examples.md index cafeb7a92..46fa958a5 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -27,11 +27,23 @@ permanent deletion is intentional. ## Calendar +`calendar freebusy` rejects empty or inverted windows before querying Google, +including RFC3339 bounds. Calendar names containing `@` resolve as names, +while email-form IDs and `primary` can be queried directly. For event updates, +an empty `--attendees` clears the list; nonblank input must contain an attendee. + See the [`gog calendar`](commands/gog-calendar.md) reference and [Zoom setup](zoom-auth-setup.md). +Calendar selectors accept names, `primary`, and calendar email IDs. A `--page` +(or `--cursor`) token belongs to one calendar; use `--all-pages` when reading +several calendars. Time sorting interprets all-day dates in the calendar’s +timezone, independently of a display `--timezone` override. Multi-calendar JSON +includes `calendarId` and retains `CalendarID` for existing scripts. + ```bash gog calendar events --today +gog calendar events --cal primary --cal colleague@example.com --all-pages --sort start gog calendar create --summary "Review" \ --from "2026-05-06T10:00:00+02:00" \ --to "2026-05-06T10:30:00+02:00" @@ -43,6 +55,7 @@ gog calendar update primary --with-meet gog calendar update primary \ --attachment 'https://drive.google.com/open?id=' gog calendar update primary --attachment '' +gog calendar update primary --location '' --attendees '' gog zoom auth setup gog calendar create primary --summary "Client sync" \ --from "2026-05-06T11:00:00+02:00" \ @@ -50,15 +63,33 @@ gog calendar create primary --summary "Client sync" \ --with-zoom gog calendar move primary team-calendar@example.com gog calendar create-calendar "Project calendar" --timezone Europe/London +gog calendar update-calendar --timezone America/Los_Angeles +gog calendar update-calendar --check gog calendar delete-calendar --force gog calendar subscribe en.uk#holiday@group.v.calendar.google.com gog calendar unsubscribe en.uk#holiday@group.v.calendar.google.com --force ``` +For event updates, an empty `--summary`, `--description`, or `--location` clears +that field, and `--attendees ''` removes all attendees. Omitted fields stay unchanged. + Repeated `--attachment` values replace all attachments; an empty value clears them. Google Calendar appointment schedules are not exposed by the Calendar API, so `gog` cannot list or manage them. +A calendar's own default timezone (`calendars.get.timeZone`, owner-only) +decides the UTC offset the API serialises for every event on it, so a stale +default makes events report a `dateTime` offset that contradicts their own +`timeZone`. `gog calendar update-calendar` patches the calendar resource, and +`--check` reports its timezone next to your read-only calendar-list copy +without writing anything. + +Calendar setting updates require a nonempty name and a valid timezone when those +fields are supplied. Omit a flag to preserve its field; use `--description ''` +or `--location ''` to clear those optional fields. `--dry-run --json` previews the +exact patch without authentication or API requests; `--check` is a separate +read-only inspection and cannot be combined with setting flags. + ## Drive See [Drive audits](drive-audits.md), [polling](polling.md), and @@ -72,7 +103,7 @@ gog drive tree --parent --depth 2 gog drive du --parent --max 20 --json gog drive inventory --parent --json gog drive audit sharing --parent --internal-domain example.com --json -gog drive audit user clawdbot@gmail.com --parent --json +gog drive audit user user@example.com --parent --json gog drive bulk remove-public --parent --dry-run gog drive share --to user --email person@example.com --notify --dry-run gog drive labels list --json @@ -189,6 +220,11 @@ gog docs raw --pretty ## Sheets +`sheets append --values-json` preserves numeric tokens in its outgoing request; +Google Sheets still applies its own storage precision. Use JSON output to +preserve cell content exactly. Text and `--plain` output keep each row on one +line, displaying embedded newlines as `\n` and tabs as spaces. + See [batch updates](sheets-batch-update.md), [tables](sheets-tables.md), and [formatting](sheets-formatting.md). diff --git a/docs/fork-maintenance.md b/docs/fork-maintenance.md new file mode 100644 index 000000000..d693204b3 --- /dev/null +++ b/docs/fork-maintenance.md @@ -0,0 +1,41 @@ +# Jai's Google Chat fork + +Source: [jai/gogcli](https://github.com/jai/gogcli). Upstream: [openclaw/gogcli](https://github.com/openclaw/gogcli). + +`main` remains pinned to upstream until a validated sync PR. Its active fork ruleset requires signed commits, a PR with resolved threads and the strict checks listed below, in addition to deletion/non-fast-forward protection. No human approvals are required. Development and dogfooding use `jai/chat-rich-messages`, with a personal fork PR kept open. No upstream PR is authorized yet; propose it after dogfooding. + +## Current evidence + +Use the personal fork PR and its exact-head check runs for current validation evidence. The local provenance manifest records the active binary; the parent thread and Brain project page record activation and daily automation state. This document defines the workflow and does not certify that a particular head has passed its gates. + +## Patch contract + +Existing compact JSON and plain output stay compatible. Opt-in `--full` exposes the fields recognized by the pinned Google SDK, including formatted hyperlinks, attachment/image metadata and CardsV2. It is not raw or lossless for unknown future API fields. Native message get returns full JSON; message update/delete follow Google permissions and the CLI's existing mutation safeguards. + +Images in this patch are metadata and references, not downloaded bytes or rendered cards. Do not execute card actions or treat a thumbnail URL as a media-download API. + +## Gates before installation + +Require independent AI review, a clean committed and pushed dogfood branch, local `make ci`, and green hosted checks at the exact branch head. Run the local gate with `env -u GOG_ACCOUNT mise exec go@1.27.1 -- make ci`; inherited account defaults affect existing no-account tests. Inherit upstream CI YAML unchanged: Linux `test`, `minimum-go`, `worker`, `windows`, `darwin-cgo-build`, and Docker `image`. These are strict required checks on fork `main` under ruleset 25208668. The fork's open PR must trigger these checks; confirm their actual names and head SHA in GitHub before installation. A newly created fork may not register workflows until its first PR event; an empty workflow registry is not CI success. + +Keep redacted Workspace evidence for hyperlinks, image metadata and CardsV2 reads. Write tests use synthetic messages only: create, get, update, verify, delete, then verify a deleted tombstone or not-found response. An ambiguous provider 403 requires a successful scoped listing that proves the run-owned target is absent. Never include tokens, customer messages or private card content in evidence. + +CI and Docker workflows are enabled in the fork. Upstream release publishing, Pages deployment, ClawSweeper dispatch and Crabbox hydration are disabled in the fork's Actions settings; their source files remain unchanged. Independent Codex review supplies the review evidence while the upstream reviewer app is absent. + +## Install a validated head + +From the clean dogfood checkout, run: + +```sh +mise exec go@1.27.1 -- scripts/install-fork-build.sh +``` + +This uses the repository Makefile and stamps the version with `jai-chat` and the source SHA. It validates `--version` before atomically switching `~/.local/bin/gog` to `~/.local/share/gogcli-fork/builds//gog`. A text provenance manifest accompanies each build. Existing builds are reused only after provenance and executable validation. Build/validation failures leave the active binary unchanged. + +Homebrew's original `/opt/homebrew/Cellar/gogcli/0.43.0/bin/gog` is never overwritten. Unknown local executables or symlink targets are preserved and reported as an error; inspect them before proceeding. The installer does not run review or CI itself. Verify `command -v gog`, `gog --version` and the provenance manifest after installation; `~/.local/bin` must precede Homebrew in PATH. + +## Daily upstream maintenance + +The thread heartbeat fetches upstream and merges upstream append-only into `jai/chat-rich-messages`; do not rebase or force-push dogfood history, and do not push `main` directly. Advance the `main` mirror only through a separately validated sync PR. Resolve conflicts within the patch scope, rerun independent review and `make ci`, push, wait for the exact-head hosted gates, and install only a green head. If validation fails, keep the last installed build active and report the failing command/check with evidence. No change means no replacement build is needed. + +Keep the personal PR open while dogfooding. Preserve the same capability and upstream defaults as releases evolve. Record actual validation, live proof and installation evidence in the parent task; this file must not turn intended checks into completion claims. diff --git a/docs/gmail-autoreply.md b/docs/gmail-autoreply.md index 91ab2c8c4..b4a96fbf2 100644 --- a/docs/gmail-autoreply.md +++ b/docs/gmail-autoreply.md @@ -13,11 +13,14 @@ Use it on a schedule with `launchd`, cron, or another runner when Gmail's native ## Example -Reply once to mail sent to `security@openclaw.ai`, add a dedupe label, then archive: +Reply once to mail sent to `security@example.com`, add a dedupe label, then archive: + +Replace `bot@example.com` with your authenticated Google account and +`security@example.com` with the recipient address to match. ```bash -gog -a clawdbot@gmail.com gmail autoreply \ - 'to:security@openclaw.ai in:inbox -label:SecurityAutoReplied' \ +gog -a bot@example.com gmail autoreply \ + 'to:security@example.com in:inbox -label:SecurityAutoReplied' \ --body-file ./security-autoreply.txt \ --label SecurityAutoReplied \ --archive \ @@ -41,3 +44,5 @@ If you cannot use GitHub or are unsure which repo is affected, reply to this ema - It sends replies in-thread with `In-Reply-To` and `References`. - It adds `Auto-Submitted: auto-replied` and suppresses common auto-response loops. - By default it skips bulk/list/auto-generated mail. +- It also skips mail from your account or any send-as alias, even if the message has an external `Reply-To`. Use `--allow-self` to allow those replies. +- Without `--allow-self`, a failed send-as lookup stops the run before searching or sending, so an unavailable alias list cannot cause replies to your own addresses. diff --git a/docs/gmail-workflows.md b/docs/gmail-workflows.md index 77433c069..0394cbf44 100644 --- a/docs/gmail-workflows.md +++ b/docs/gmail-workflows.md @@ -24,8 +24,25 @@ gog gmail search --max 2 --json -- '-in:inbox newer_than:7d' gog gmail messages search --max 2 --json -- '-in:inbox newer_than:7d' ``` +Both searches fetch each result's headers and labels with one extra API call +per result. For bulk jobs that only need IDs, `--ids-only` returns what Gmail's +list call already holds (`id` and `threadId` for messages, `id` for threads) and +makes one list call per page. Combine it with `--all --max 500`, Gmail's largest +page, and pass the IDs to `gmail batch modify`, which takes up to 1,000 IDs per call: + +```bash +gog gmail messages search 'list:example.com' --all --max 500 --ids-only --json --results-only | + jq -r '.[].id' | xargs -n 1000 gog gmail batch modify --add-label Newsletters +``` + +`--ids-only` rejects `--include-body`, `--full`, `--include-attachments`, +`--include-recipients`, `--headers`, `--sanitize-content`, and, for `gmail search`, `--oldest`. + Thread searches fail if any thread detail cannot be fetched, without emitting a -partial result list. Retry the search after resolving the reported API error. +partial result list, and stop the detail requests still pending. Retry the +search after resolving the reported API error. + +Quoted operators such as `"is:unread"` are literal phrases and are passed to Gmail without adding a label filter. `gmail thread get` includes nonempty Cc and Bcc headers in its text output. ### Full payloads and raw MIME @@ -98,6 +115,25 @@ sender and recipient display text as untrusted, including with `--results-only` and `--select`. MCP `gmail_search` exposes `include_recipients` and `sanitize_content` with the same behavior. +To include other headers in JSON results, such as mailing-list ones, name them +with `--headers` (up to 50 names, each at most 256 bytes; printable ASCII +without spaces or colons): + +```bash +gog gmail messages search 'newer_than:7d' --headers List-Id,Sender --json | + jq -r '.messages[] | .headers["List-Id"]' +``` + +Each result gets a `headers` object keyed by the canonical header name, whatever +case you typed: `list-id` becomes `List-Id`, and acronyms are not kept, so +`Message-ID` becomes `Message-Id`. These are real header names, unlike the +snake_case keys of the `headers` object in `gmail get`. A header the message +lacks is an empty string, and a repeated one gives its first value. The headers +come from the same per-message read, so there are no extra API calls; +`--sanitize-content` and `--wrap-untrusted` apply to them as to the other header +fields. Combines with `--include-recipients`. MCP `gmail_search` takes the names +as a `headers` array. + Message JSON exposes Reply-To as `headers.reply_to` in both full and default metadata reads. With `--sanitize-content`, use `message.headers.reply_to` (or `headers.reply_to` with `--results-only`); sanitized thread reads expose it in @@ -162,6 +198,30 @@ derived from the original message; explicit values, including empty ones, override that selection. Dry-run output reports which headers will be kept without fetching the draft. +## Plain-Text Bodies in Gmail Web + +gog sends `--body` and `--body-file` as text/plain and preserves long logical +lines. Gmail web still displays a text/plain-only message with its own line +break about every 70 characters, so paragraphs break mid-sentence in a wide +window and wrap again on a phone. Mail written in Gmail's composer always +carries a text/html alternative, which reflows to the window. + +`--html-from-text` adds that alternative when only a plain body is given: the +plain text, HTML-escaped, with each line break kept as `
`. The text/plain +part is unchanged, and an explicit `--body-html` or `--body-html-file` still +wins. It applies to `gmail send`, `reply`, `reply-all`, `autoreply`, and +`drafts create`, `update`, `reply`, and `reply-all`; forwards keep their own +`--note-html` flags. Set `GOG_GMAIL_HTML_FROM_TEXT=1` to turn it on for every +one of those commands. Like other compose flags it cannot be combined with +`--raw-file`; with the environment variable set, pass `--html-from-text=false` +to send or store an exact RFC822 message. + +```bash +gog --account you@example.com gmail send \ + --to recipient@example.com --subject "Update" \ + --body-file update.txt --html-from-text +``` + ## Drafts Sent from Gmail Web gog preserves long logical lines when building a plain-text draft from `--body` @@ -180,7 +240,8 @@ gog --account you@example.com gmail drafts create \ This creates an HTML draft; it does not change plain-text MIME behavior. Check the draft and recipient-client rendering before relying on the workaround for -a particular workflow. +a particular workflow. `--html-from-text` gives a plain `--body` draft the same +kind of HTML part. ## Signatures on drafts @@ -194,6 +255,25 @@ given in that call. An HTML signature adds an HTML alternative when the supplied body is plain text, preserving image-only signatures and escaping the original body text. +## Text direction in HTML messages + +In the HTML part of a message gog sends or saves as a draft, the author's text +is marked `dir="auto"`, so it takes the direction of its first letter, and +English text keeps its direction when a reply written right to left quotes it. +When gog turns plain text into HTML (`--html-from-text`, a `--body` above a quote or beside a +draft's signature, a `--note`, a plain-text `--signature-file`), each line gets +a `
` of its own, as Gmail's mobile apps write it, so a Hebrew +or Arabic line reads right to left among English ones. HTML given through +`--body-html` or `--note-html` (or their `-file` forms) goes into one +`
`, which follows its first letter as a whole; `dir` attributes +inside it still apply, so mark the paragraphs of a mixed-language message, or a +layout table, yourself. A whole HTML document, or HTML that opens with what +belongs in a document's head (a ``, ``, ``, `

Hi

", ""}, + {"meta", `

Hi

`, ""}, + {"self-closing link", `

Hi

`, ""}, + {"header element", "
Hi

Body

", `
Hi

Body

`}, + {"text before an html tag", "Hi there", `
Hi there
`}, + {"paragraph from a file with a byte order mark", byteOrderMark + "

Hi

\n", `

Hi

`}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + svc, got, cleanup := newSignatureComposeService(t, nil, nil) + defer cleanup() + args := []string{"--account", "me@example.com", "gmail", "drafts", "create", "--to", "a@example.com", "--subject", "Hi", "--body-html", tc.html} + if result := executeWithGmailTestService(t, args, svc); result.err != nil { + t.Fatal(result.err) + } + want := tc.want + if want == "" { + want = tc.html + } + if html := composedHTML(t, got.raw); html != want { + t.Errorf("HTML part:\n got %q\nwant %q", html, want) + } + }) + } +} diff --git a/internal/cmd/gmail_concurrent_test.go b/internal/cmd/gmail_concurrent_test.go index a40083e37..28df5c252 100644 --- a/internal/cmd/gmail_concurrent_test.go +++ b/internal/cmd/gmail_concurrent_test.go @@ -8,6 +8,7 @@ import ( "io" "net/http" "net/http/httptest" + "path" "strings" "sync/atomic" "testing" @@ -303,8 +304,8 @@ func TestFetchThreadDetails_ConcurrentError(t *testing.T) { if items != nil { t.Fatalf("expected nil items on error, got %d", len(items)) } - if got := calls.Load(); got != 3 { - t.Errorf("expected 3 concurrent calls and no sequential retry, got %d", got) + if got := calls.Load(); got > 3 { + t.Errorf("expected at most 3 concurrent calls and no sequential retry, got %d", got) } } @@ -341,3 +342,97 @@ func TestFetchThreadDetails_ContextCanceled(t *testing.T) { t.Fatalf("error = %v, want context.Canceled", err) } } + +// newFirstRequestFailsGmailService serves Gmail detail requests. The first one +// fails with 403 rateLimitExceeded; every later one stays in flight until the +// client cancels it, so no slot is freed by anything but the fan-out itself. +// The handlers are released at cleanup, which lets a fan-out that never +// cancels finish after its test has failed. +func newFirstRequestFailsGmailService(t *testing.T) (*gmail.Service, *atomic.Int32) { + t.Helper() + + var calls atomic.Int32 + release := make(chan struct{}) + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + if calls.Add(1) == 1 { + w.WriteHeader(http.StatusForbidden) + _, _ = io.WriteString(w, `{"error":{"code":403,"message":"User-rate limit exceeded.","errors":[{"domain":"usageLimits","reason":"rateLimitExceeded"}]}}`) + return + } + select { + case <-r.Context().Done(): + return + case <-release: + } + id := path.Base(r.URL.Path) + _, _ = fmt.Fprintf(w, `{"id":%q,"threadId":%q,"messages":[]}`, id, id) + })) + t.Cleanup(func() { + close(release) + server.Close() + }) + + return newGoogleTestServiceWithEndpoint(t, server.Client(), server.URL+"/", gmail.NewService), &calls +} + +// awaitFanOut fails the test when fetch is still running after the first +// failure has had ample time to cancel it; it never decides a passing run. +func awaitFanOut(t *testing.T, fetch func() error) error { + t.Helper() + + done := make(chan error, 1) + go func() { done <- fetch() }() + + select { + case err := <-done: + return err + case <-time.After(10 * time.Second): + t.Fatal("the fan-out kept waiting on detail requests after its first failure") + return nil + } +} + +func TestFetchThreadDetails_StopsAfterFirstError(t *testing.T) { + svc, calls := newFirstRequestFailsGmailService(t) + threads := make([]*gmail.Thread, 30) + for i := range threads { + threads[i] = &gmail.Thread{Id: fmt.Sprintf("thread-%02d", i)} + } + + err := awaitFanOut(t, func() error { + _, err := fetchThreadDetails(context.Background(), svc, threads, nil, false, time.UTC) + return err + }) + var apiErr *googleapi.Error + if !errors.As(err, &apiErr) || apiErr.Code != http.StatusForbidden { + t.Fatalf("error = %v, want the thread detail HTTP 403", err) + } + // Only the failed request frees a slot before cancellation: at most the + // 10 requests in flight plus one that took that slot ever reach the server. + if got := calls.Load(); got > 11 { + t.Fatalf("fetched %d of 30 threads after the search had failed, want at most 11", got) + } +} + +func TestFetchMessageDetails_StopsAfterFirstError(t *testing.T) { + svc, calls := newFirstRequestFailsGmailService(t) + messages := make([]*gmail.Message, 30) + for i := range messages { + messages[i] = &gmail.Message{Id: fmt.Sprintf("message-%02d", i)} + } + + err := awaitFanOut(t, func() error { + _, err := fetchMessageDetails(context.Background(), svc, messages, map[string]string{}, time.UTC, false, gmailMessageBodyFormatText, false, false, false, nil, false) + return err + }) + var apiErr *googleapi.Error + if !errors.As(err, &apiErr) || apiErr.Code != http.StatusForbidden { + t.Fatalf("error = %v, want the message detail HTTP 403", err) + } + // Only the failed request frees a slot before cancellation: at most the + // 10 requests in flight plus one that took that slot ever reach the server. + if got := calls.Load(); got > 11 { + t.Fatalf("fetched %d of 30 messages after the search had failed, want at most 11", got) + } +} diff --git a/internal/cmd/gmail_drafts.go b/internal/cmd/gmail_drafts.go index 200291fed..3c1d3026b 100644 --- a/internal/cmd/gmail_drafts.go +++ b/internal/cmd/gmail_drafts.go @@ -313,6 +313,7 @@ type GmailDraftsCreateCmd struct { From string `name:"from" help:"Send from this email address (must be a verified send-as alias)"` AutoFromAddressedAlias bool `name:"auto-from-addressed-alias" help:"When --from is omitted, reply from the verified send-as alias addressed by the original message" env:"GOG_GMAIL_AUTO_FROM_ADDRESSED_ALIAS"` composeSignatureOptions `embed:""` + composeTextHTMLOptions `embed:""` } type draftComposeInput struct { @@ -419,7 +420,7 @@ func buildDraftMessage(ctx context.Context, svc *gmail.Service, account string, if err != nil { return nil, draftThreading{}, nil, err } - body, htmlBody := input.Body, input.BodyHTML + body, htmlBody := input.Body, directedHTML(input.BodyHTML) replyContextSource := "" if strings.TrimSpace(info.InReplyTo) != "" { replyContextSource = replyContextCaller @@ -461,7 +462,7 @@ func buildDraftMessage(ctx context.Context, svc *gmail.Service, account string, return nil, draftThreading{}, nil, err } if htmlBody == "" && signature.htmlBlock() != "" { - htmlBody = escapeTextToHTML(body) + htmlBody = directedTextToHTML(strings.TrimSpace(body)) } body, htmlBody = appendComposeSignature(body, htmlBody, signature) body, htmlBody, err = applyReplyQuote(ctx, input.Quote, info, body, htmlBody) @@ -815,6 +816,7 @@ func (c *GmailDraftsCreateCmd) Run(ctx context.Context, flags *RootFlags) error if err != nil { return err } + htmlBody = c.withTextHTML(body, htmlBody) replyToMessageID := normalizeGmailMessageID(c.ReplyToMessageID) threadID := normalizeGmailThreadID(c.ThreadID) if replyToMessageID != "" && threadID != "" { @@ -921,6 +923,7 @@ type GmailDraftsUpdateCmd struct { From string `name:"from" help:"Send from this email address (must be a verified send-as alias)"` AutoFromAddressedAlias bool `name:"auto-from-addressed-alias" help:"When --from is omitted, reply from the verified send-as alias addressed by the original message" env:"GOG_GMAIL_AUTO_FROM_ADDRESSED_ALIAS"` composeSignatureOptions `embed:""` + composeTextHTMLOptions `embed:""` ccProvided bool bccProvided bool } @@ -952,6 +955,7 @@ func (c *GmailDraftsUpdateCmd) runCompose(ctx context.Context, flags *RootFlags) if err != nil { return err } + htmlBody = c.withTextHTML(body, htmlBody) replyToMessageID := normalizeGmailMessageID(c.ReplyToMessageID) threadID := normalizeGmailThreadID(c.ThreadID) if replyToMessageID != "" && threadID != "" { diff --git a/internal/cmd/gmail_drafts_cmd_test.go b/internal/cmd/gmail_drafts_cmd_test.go index f2115b694..126cf70a6 100644 --- a/internal/cmd/gmail_drafts_cmd_test.go +++ b/internal/cmd/gmail_drafts_cmd_test.go @@ -583,15 +583,12 @@ func TestGmailDraftsCreateCmd_WithQuote(t *testing.T) { if plain := rawTextPart(t, s, "text/plain"); !strings.Contains(plain, "On Mon, Jan 1, 2024 at 12:00\u202fAM Alice wrote:") { t.Fatalf("missing quoted attribution in text/plain part:\n%s", plain) } - if htmlPart := rawTextPart(t, s, "text/html"); !strings.Contains(htmlPart, `On Mon, Jan 1, 2024 at 12:00`+"\u202f"+`AM Alice <alice@example.com> wrote:`) { - t.Fatalf("missing linked HTML attribution in text/html part:\n%s", htmlPart) + if htmlPart := rawTextPart(t, s, "text/html"); !strings.Contains(htmlPart, gmailQuoteOpen+"On "+isolatedHTML("Mon, Jan 1, 2024 at 12:00\u202fAM")+" "+isolatedHTML("Alice")+" "+quoteAddressHTML("alice@example.com")+" wrote:
") { + t.Fatalf("missing quoted HTML block with linked attribution in text/html part:\n%s", htmlPart) } if !strings.Contains(s, "> Original plain line") { t.Fatalf("missing quoted plain body in raw:\n%s", s) } - if !strings.Contains(s, "gmail_quote") { - t.Fatalf("missing quoted html block in raw:\n%s", s) - } writeGmailDraftResponse(w) return default: @@ -1418,8 +1415,8 @@ func TestGmailDraftsUpdateCmd_WithQuoteFromExistingThread(t *testing.T) { if !strings.Contains(s, "> Original thread message") { t.Fatalf("missing quoted plain body in raw:\n%s", s) } - if !strings.Contains(s, "gmail_quote") { - t.Fatalf("missing quoted html block in raw:\n%s", s) + if htmlPart := rawTextPart(t, s, "text/html"); !strings.Contains(htmlPart, gmailQuoteOpen) { + t.Fatalf("missing quoted html block in text/html part:\n%s", htmlPart) } w.Header().Set("Content-Type", "application/json") _ = json.NewEncoder(w).Encode(map[string]any{ @@ -1560,6 +1557,9 @@ func TestGmailDraftsUpdateCmd_WithQuoteAndReplyToMessageID(t *testing.T) { if !strings.Contains(s, "> Quoted from explicit message id") { t.Fatalf("missing quoted plain body in raw:\n%s", s) } + if htmlPart := rawTextPart(t, s, "text/html"); !strings.Contains(htmlPart, gmailQuoteOpen) { + t.Fatalf("missing quoted html block in text/html part:\n%s", htmlPart) + } writeGmailDraftResponse(w) return default: diff --git a/internal/cmd/gmail_drafts_compose_test.go b/internal/cmd/gmail_drafts_compose_test.go index e6b1363c4..c4d622c81 100644 --- a/internal/cmd/gmail_drafts_compose_test.go +++ b/internal/cmd/gmail_drafts_compose_test.go @@ -416,36 +416,6 @@ func TestGmailDraftsReply_NoQuoteOmitsOriginal(t *testing.T) { } } -func TestGmailDraftsForward_BodyFormatAndNoReplyHeaders(t *testing.T) { - t.Setenv("GOG_TIMEZONE", "UTC") - raw, threadID := captureForwardRaw(t, []string{ - "--account", "me@example.com", - "gmail", "drafts", "forward", "orig-msg-1", - "--to", "recipient@example.com", - "--note", "FYI see below", - }, "/gmail/v1/users/me/drafts", mockForwardSourceMessage) - - for _, want := range []string{ - "Subject: Fwd: Original Subject", - "---------- Forwarded message ---------", - "From: Alice ", - "FYI see below", - "Hello, this is the body.", - } { - if !strings.Contains(raw, want) { - t.Fatalf("forward draft missing %q:\n%s", want, raw) - } - } - if threadID != "" { - t.Fatalf("forward draft must not stamp a thread, got %q", threadID) - } - for _, h := range []string{"In-Reply-To:", "References:"} { - if strings.Contains(raw, h) { - t.Fatalf("forward draft unexpectedly contains %q:\n%s", h, raw) - } - } -} - // --- Addressless forward draft: allowed for draft, rejected for send. --- // newForwardDraftCaptureService builds a mock Gmail service for the drafts-forward diff --git a/internal/cmd/gmail_drafts_raw.go b/internal/cmd/gmail_drafts_raw.go index 3fd58ed08..4aced4a1c 100644 --- a/internal/cmd/gmail_drafts_raw.go +++ b/internal/cmd/gmail_drafts_raw.go @@ -53,6 +53,7 @@ func (c *GmailDraftsCreateCmd) rawModeConflict() string { ReplyToMessageID: c.ReplyToMessageID, ReplyAll: c.ReplyAll, ReplyTo: c.ReplyTo, Attach: c.Attach, From: c.From, Quote: c.Quote, composeSignatureOptions: c.composeSignatureOptions, + composeTextHTMLOptions: c.composeTextHTMLOptions, } return compose.rawModeConflict() } @@ -73,6 +74,7 @@ func (c *GmailDraftsUpdateCmd) rawModeConflict() string { ReplyToMessageID: c.ReplyToMessageID, ReplyAll: c.ReplyAll, ReplyTo: c.ReplyTo, Attach: c.Attach, From: c.From, Quote: c.Quote, AutoFromAddressedAlias: c.AutoFromAddressedAlias, composeSignatureOptions: c.composeSignatureOptions, + composeTextHTMLOptions: c.composeTextHTMLOptions, } return compose.rawModeConflict() } diff --git a/internal/cmd/gmail_drafts_raw_test.go b/internal/cmd/gmail_drafts_raw_test.go index 24b9251dd..44e02c112 100644 --- a/internal/cmd/gmail_drafts_raw_test.go +++ b/internal/cmd/gmail_drafts_raw_test.go @@ -206,6 +206,7 @@ func TestGmailDraftsRawRejectsComposeFlags(t *testing.T) { {"--reply-all"}, {"--quote"}, {"--auto-from-addressed-alias"}, + {"--html-from-text"}, } for _, operation := range []string{"create", "update"} { cases := append([][]string(nil), common...) diff --git a/internal/cmd/gmail_drafts_signature_test.go b/internal/cmd/gmail_drafts_signature_test.go index 6481411eb..4f68e878e 100644 --- a/internal/cmd/gmail_drafts_signature_test.go +++ b/internal/cmd/gmail_drafts_signature_test.go @@ -108,7 +108,7 @@ func TestGmailDraftsCreate_AppendsSendAsSignatureToPlainAndHTML(t *testing.T) { if !strings.Contains(got.raw, "Body\r\n\r\n--\r\nKind regards\r\nMe Person") { t.Fatalf("plain signature missing:\n%s", got.raw) } - if !strings.Contains(got.raw, `

Body

`+"\r\n\r\n"+`
Kind regards
Me Person
`) { + if !strings.Contains(got.raw, `

Body

`+"\r\n\r\n"+gmailSignatureOpen+`
Kind regards
Me Person
`) { t.Fatalf("html signature missing:\n%s", got.raw) } } @@ -293,7 +293,7 @@ func TestGmailDraftsForward_SignatureFromAlias(t *testing.T) { if result.err != nil { t.Fatalf("drafts forward: %v", result.err) } - if !strings.Contains(got.raw, "FYI\r\n\r\n--\r\nalias sig\r\n\r\n---------- Forwarded message") || strings.Contains(got.raw, "primary sig") { + if !strings.Contains(got.raw, "FYI\r\n\r\n--\r\nalias sig\r\n\r\n"+forwardedSeparator) || strings.Contains(got.raw, "primary sig") { t.Fatalf("expected only the alias signature:\n%s", got.raw) } } @@ -312,10 +312,10 @@ func TestGmailDraftsForward_ImageOnlySignatureLeavesNoLoneSeparator(t *testing.T if result.err != nil { t.Fatalf("drafts forward: %v", result.err) } - if strings.Contains(got.raw, "--\r\n\r\n---------- Forwarded message") || strings.Contains(got.raw, "\r\n--\r\n") { + if strings.Contains(got.raw, "--\r\n\r\n"+forwardedSeparator) || strings.Contains(got.raw, "\r\n--\r\n") { t.Fatalf("plain part has a lone signature separator:\n%s", got.raw) } - if !strings.Contains(got.raw, `
`) { + if !strings.Contains(got.raw, gmailSignatureOpen+``) { t.Fatalf("html signature block missing:\n%s", got.raw) } } @@ -334,48 +334,27 @@ func TestGmailDraftsUpdate_AppendsSendAsSignatureToNewBody(t *testing.T) { if !strings.Contains(got.raw, "New body\r\n\r\n--\r\nKind regards\r\nMe Person") { t.Fatalf("plain signature missing:\n%s", got.raw) } - if !strings.Contains(got.raw, `
Kind regards
Me Person
`) { + if !strings.Contains(got.raw, gmailSignatureOpen+`
Kind regards
Me Person
`) { t.Fatalf("html signature missing:\n%s", got.raw) } } -func TestGmailDraftsForward_SignatureBetweenNoteAndForwardedMessage(t *testing.T) { - t.Setenv("GOG_TIMEZONE", "UTC") - svc, got, cleanup := newSignatureComposeService(t, primarySignature(), nil) - defer cleanup() - - result := executeWithGmailTestService(t, []string{ - "--account", "me@example.com", "gmail", "drafts", "forward", "orig-msg-1", - "--to", "a@example.com", "--note", "FYI", "--signature", - }, svc) - if result.err != nil { - t.Fatalf("drafts forward: %v", result.err) - } - if !strings.Contains(got.raw, "FYI\r\n\r\n--\r\nKind regards\r\nMe Person\r\n\r\n---------- Forwarded message ---------") { - t.Fatalf("plain signature not between note and forwarded message:\n%s", got.raw) - } - if !strings.Contains(got.raw, `
FYI

Kind regards
Me Person

`) { - t.Fatalf("html signature not between note and forwarded message:\n%s", got.raw) - } -} - func TestGmailForward_SignatureBetweenNoteAndForwardedMessage(t *testing.T) { t.Setenv("GOG_TIMEZONE", "UTC") - svc, got, cleanup := newSignatureComposeService(t, primarySignature(), nil) - defer cleanup() - - result := executeWithGmailTestService(t, []string{ - "--account", "me@example.com", "gmail", "forward", "orig-msg-1", - "--to", "a@example.com", "--note", "FYI", "--signature", - }, svc) - if result.err != nil { - t.Fatalf("forward: %v", result.err) - } - if !strings.Contains(got.raw, "FYI\r\n\r\n--\r\nKind regards\r\nMe Person\r\n\r\n---------- Forwarded message ---------") { - t.Fatalf("plain signature not between note and forwarded message:\n%s", got.raw) - } - if !strings.Contains(got.raw, `
FYI

Kind regards
Me Person

`) { - t.Fatalf("html signature not between note and forwarded message:\n%s", got.raw) + for _, cmd := range forwardCommands { + t.Run(cmd.name, func(t *testing.T) { + svc, got, cleanup := newSignatureComposeService(t, primarySignature(), nil) + defer cleanup() + if result := executeWithGmailTestService(t, forwardArgs(cmd.verb, "--note", "FYI", "--signature"), svc); result.err != nil { + t.Fatalf("forward: %v", result.err) + } + if !strings.Contains(got.raw, "FYI\r\n\r\n--\r\nKind regards\r\nMe Person\r\n\r\n"+forwardedSeparator) { + t.Fatalf("plain signature not between note and forwarded message:\n%s", got.raw) + } + if !strings.Contains(got.raw, `
FYI

`+gmailSignatureOpen+`
Kind regards
Me Person

`+gmailQuoteOpen) { + t.Fatalf("html signature not between note and forwarded message:\n%s", got.raw) + } + }) } } @@ -391,10 +370,10 @@ func TestGmailDraftsForward_SignatureWithoutNote(t *testing.T) { if result.err != nil { t.Fatalf("drafts forward: %v", result.err) } - if !strings.Contains(got.raw, "--\r\nKind regards\r\nMe Person\r\n\r\n---------- Forwarded message ---------") { + if !strings.Contains(got.raw, "--\r\nKind regards\r\nMe Person\r\n\r\n"+forwardedSeparator) { t.Fatalf("plain signature missing above forwarded message:\n%s", got.raw) } - if !strings.Contains(got.raw, `
Kind regards
Me Person

`) { + if !strings.Contains(got.raw, gmailSignatureOpen+`
Kind regards
Me Person

`+gmailQuoteOpen) { t.Fatalf("html signature missing above forwarded message:\n%s", got.raw) } } @@ -447,11 +426,11 @@ func TestGmailForward_PlainOnlyOriginalKeepsHTMLSignature(t *testing.T) { note string wantSig string }{ - {"drafts image no note", imageSig, []string{"drafts", "forward"}, "", `
` + imageSig + `

`}, - {"drafts image with note", imageSig, []string{"drafts", "forward"}, "FYI", `
FYI

` + imageSig + `

`}, - {"send image no note", imageSig, []string{"forward"}, "", `
` + imageSig + `

`}, - {"send image with note", imageSig, []string{"forward"}, "FYI", `
FYI

` + imageSig + `

`}, - {"drafts text signature", textSig, []string{"drafts", "forward"}, "", `
` + textSig + `

`}, + {"drafts image no note", imageSig, []string{"drafts", "forward"}, "", gmailSignatureOpen + imageSig + `

` + gmailQuoteOpen}, + {"drafts image with note", imageSig, []string{"drafts", "forward"}, "FYI", `
FYI

` + gmailSignatureOpen + imageSig + `

` + gmailQuoteOpen}, + {"send image no note", imageSig, []string{"forward"}, "", gmailSignatureOpen + imageSig + `

` + gmailQuoteOpen}, + {"send image with note", imageSig, []string{"forward"}, "FYI", `
FYI

` + gmailSignatureOpen + imageSig + `

` + gmailQuoteOpen}, + {"drafts text signature", textSig, []string{"drafts", "forward"}, "", gmailSignatureOpen + textSig + `

` + gmailQuoteOpen}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { @@ -513,7 +492,7 @@ func TestGmailForward_BodylessOriginalKeepsHTMLSignature(t *testing.T) { if result := executeWithGmailTestService(t, args, svc); result.err != nil { t.Fatalf("forward: %v", result.err) } - if !strings.Contains(got.raw, `
`+imageSig+`

`) { + if !strings.Contains(got.raw, gmailSignatureOpen+imageSig+`

`+gmailQuoteOpen) { t.Fatalf("image signature lost for a bodyless original:\n%s", got.raw) } }) diff --git a/internal/cmd/gmail_forward.go b/internal/cmd/gmail_forward.go index bb592ddbe..c0c24f252 100644 --- a/internal/cmd/gmail_forward.go +++ b/internal/cmd/gmail_forward.go @@ -3,8 +3,6 @@ package cmd import ( "context" "fmt" - "html" - "net/mail" "strings" "time" @@ -25,6 +23,8 @@ type GmailForwardOptions struct { Bcc string `name:"bcc" help:"BCC recipients (comma-separated)"` Note string `name:"note" aliases:"intro" help:"Introductory text above the forwarded message"` NoteFile string `name:"note-file" help:"Note file path (plain text; '-' for stdin)"` + NoteHTML string `name:"note-html" help:"Introductory HTML above the forwarded message"` + NoteHTMLFile string `name:"note-html-file" help:"HTML note file path ('-' for stdin)"` From string `name:"from" help:"Send from this email address (must be a verified send-as alias)"` SkipAttachments bool `name:"skip-attachments" help:"Do not include original attachments"` composeSignatureOptions `embed:""` @@ -45,6 +45,7 @@ const ( type forwardComposeInputs struct { messageID string note string + noteHTML string toRecipients []string ccRecipients []string bccRecipients []string @@ -106,6 +107,7 @@ func (c *GmailForwardOptions) dryRunFields(inputs forwardComposeInputs) map[stri "bcc": inputs.bccRecipients, "from": strings.TrimSpace(c.From), "note_len": len(inputs.note), + "note_html_len": len(inputs.noteHTML), "skip_attachments": c.SkipAttachments, "signature": c.Signature, "signature_from": strings.TrimSpace(c.SignatureFrom), @@ -138,8 +140,9 @@ func (c *GmailForwardOptions) resolveForwardInputs(ctx context.Context, messageI } // Resolve the note after the required-recipient check so a missing --to on - // the send path fails fast without consuming stdin (--note-file -). - note, err := resolveBodyInput(ctx, c.Note, c.NoteFile) + // the send path fails fast without consuming stdin (--note-file - or + // --note-html-file -). + note, noteHTML, err := resolveTextAndHTMLInputs(ctx, "--note", c.Note, c.NoteFile, c.NoteHTML, c.NoteHTMLFile) if err != nil { return forwardComposeInputs{}, err } @@ -147,6 +150,7 @@ func (c *GmailForwardOptions) resolveForwardInputs(ctx context.Context, messageI return forwardComposeInputs{ messageID: messageID, note: note, + noteHTML: noteHTML, toRecipients: toRecipients, ccRecipients: ccRecipients, bccRecipients: bccRecipients, @@ -185,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) @@ -196,19 +205,32 @@ func (c *GmailForwardOptions) buildForwardComposeMessage(ctx context.Context, sv return forwardComposeMessage{}, err } - // Build forwarded body (plain text). - fwdPlain := formatForwardedMessage(inputs.note, signature, origFrom, origDate, origSubject, origTo, origCc, origPlain, loc) + // The note fills in its missing form the way a reply body does. + note := composeText{plain: inputs.note, html: directedHTML(inputs.noteHTML)} + + // The original's header lines, rendered once for both parts. + headers := forwardedMessageHeaders(origFrom, origDate, origSubject, origTo, origCc, loc) + + // Build forwarded body (plain text). A note with no plain rendering (an + // image, say) leaves the plain part out rather than send one without the + // note, as an image-only reply does. A reply's body already includes its + // signature when it makes that check; the note doesn't, so a signature with + // text keeps the plain part here. + var fwdPlain string + if !note.htmlOnlyWithoutText() || signature.plainBlock() != "" { + fwdPlain = formatForwardedMessage(note.plainVersion(), signature, headers, origPlain) + } // Build forwarded body (HTML) if the original had HTML. An original with // only plain text, or no body text at all, still gets one when the - // signature has HTML, so the signature is not lost. + // signature or the note has HTML, so neither is lost. var fwdHTML string - if origHTML != "" || signature.htmlBlock() != "" { + if origHTML != "" || signature.htmlBlock() != "" || note.hasHTML() { htmlContent := origHTML if htmlContent == "" { htmlContent = escapeTextToHTML(origPlain) } - fwdHTML = formatForwardedMessageHTML(inputs.note, signature, origFrom, origDate, origSubject, origTo, origCc, htmlContent, loc) + fwdHTML = formatForwardedMessageHTML(note.htmlVersion(), signature, headers, htmlContent) } // Preserve CID-backed inline resources required by the forwarded HTML and, @@ -242,19 +264,56 @@ func (c *GmailForwardOptions) buildForwardComposeMessage(ctx context.Context, sv }, nil } +// forwardedSeparator opens the forwarded-message header block in both parts, +// in Gmail's words. +const forwardedSeparator = "---------- Forwarded message ---------" + +// forwardedHeader is one line of the forwarded-message header block, with its +// value rendered for each MIME part. type forwardedHeader struct { label string - value string + plain string + html string } +// forwardedMessageHeaders renders the original's headers in line with Gmail +// Web's forwards: the sender and each recipient as "Name " or +// "", with each address linked and the sender's name in bold in HTML; a +// value that doesn't parse is shown as is, unlinked. In HTML every value taken +// from the original keeps its own direction (see isolateDirection). A blank +// header gets no line. A To or Cc that renders empty keeps an empty line, as +// Gmail Web does for a To of only "undisclosed-recipients:;". func forwardedMessageHeaders(from, date, subject, to, cc string, loc *time.Location) []forwardedHeader { - return []forwardedHeader{ - {"From", from}, - {"Date", formatQuoteDate(date, loc)}, - {"Subject", subject}, - {"To", to}, - {"Cc", cc}, + headers := make([]forwardedHeader, 0, 5) + add := func(label, value string, render func(string) (string, string)) { + if strings.TrimSpace(value) != "" { + plain, htmlValue := render(value) + headers = append(headers, forwardedHeader{label, plain, htmlValue}) + } } + add("From", from, forwardedSender) + add("Date", formatQuoteDate(date, loc), forwardedText) + add("Subject", subject, forwardedText) + add("To", to, forwardedRecipients) + add("Cc", cc, forwardedRecipients) + return headers +} + +// forwardedSender renders the From value, with the name in bold in HTML. +func forwardedSender(from string) (plain, htmlValue string) { + return formatQuoteMailbox(from), formatQuoteMailboxHTML(from, boldName) +} + +// forwardedRecipients renders a To or Cc value. +func forwardedRecipients(value string) (plain, htmlValue string) { + return formatQuoteMailboxList(value), formatQuoteMailboxListHTML(value) +} + +// forwardedText renders the Date or Subject value: as is, and escaped for +// HTML, where it keeps its own direction (see isolateDirection). A subject can +// be in any script, and a Date that doesn't parse is shown as it came. +func forwardedText(value string) (plain, htmlValue string) { + return value, isolateTextDirection(value) } // buildForwardSubject prepends "Fwd: " to the subject, avoiding duplication. @@ -287,7 +346,7 @@ func stripForwardPrefix(subject string) string { } // formatForwardedMessage builds the plain-text forwarded body. -func formatForwardedMessage(note string, signature composeSignature, from, date, subject, to, cc, body string, loc *time.Location) string { +func formatForwardedMessage(note string, signature composeSignature, headers []forwardedHeader, body string) string { var sb strings.Builder if strings.TrimSpace(note) != "" { @@ -299,15 +358,14 @@ func formatForwardedMessage(note string, signature composeSignature, from, date, sb.WriteString("\n\n") } - sb.WriteString("---------- Forwarded message ---------\n") - for _, h := range forwardedMessageHeaders(from, date, subject, to, cc, loc) { - if h.value != "" { - fmt.Fprintf(&sb, "%s: %s\n", h.label, h.value) - } + sb.WriteString(forwardedSeparator + "\n") + for _, h := range headers { + fmt.Fprintf(&sb, "%s: %s\n", h.label, h.plain) } - sb.WriteString("\n") + // Gmail leaves two blank lines between the headers and the body. if body != "" { + sb.WriteString("\n\n") sb.WriteString(body) if !strings.HasSuffix(body, "\n") { sb.WriteString("\n") @@ -317,41 +375,36 @@ func formatForwardedMessage(note string, signature composeSignature, from, date, return sb.String() } -// formatForwardedMessageHTML builds the HTML forwarded body. -func formatForwardedMessageHTML(note string, signature composeSignature, from, date, subject, to, cc, htmlContent string, loc *time.Location) string { +// formatForwardedMessageHTML builds the HTML forwarded body. noteHTML is the +// note as composeText.htmlVersion returns it, written trimmed and with no +// wrapper of its own. +func formatForwardedMessageHTML(noteHTML string, signature composeSignature, headers []forwardedHeader, htmlContent string) string { var sb strings.Builder - if strings.TrimSpace(note) != "" { - sb.WriteString("
") - sb.WriteString(html.EscapeString(strings.TrimSpace(note))) - sb.WriteString("

") + if note := strings.TrimSpace(noteHTML); note != "" { + sb.WriteString(note) + sb.WriteString(breakAfter(note)) } if block := signature.htmlBlock(); block != "" { sb.WriteString(block) sb.WriteString("
") } - sb.WriteString(`
`) - sb.WriteString(`
---------- Forwarded message ---------
`) - sb.WriteString(`
`) - - for _, h := range forwardedMessageHeaders(from, date, subject, to, cc, loc) { - if h.value != "" { - displayName := html.EscapeString(h.value) - // Format the From address more nicely if it has a name part. - if h.label == "From" { - if addr, err := mail.ParseAddress(h.value); err == nil && addr.Name != "" { - displayName = html.EscapeString(addr.Name) + " <" + html.EscapeString(addr.Address) + ">" - } - } - fmt.Fprintf(&sb, "%s: %s
", h.label, displayName) - } + // Like Gmail's, the header block has no inline styles and its labels aren't + // bold; only the sender's name is (see nameStyle). Bold labels would come + // out as *From:* in the text part Gmail rebuilds on send. + sb.WriteString(gmailQuoteOpen + forwardedSeparator + "
") + for _, h := range headers { + fmt.Fprintf(&sb, "%s: %s
", h.label, h.html) } sb.WriteString("
") - sb.WriteString(`
`) - sb.WriteString(htmlContent) - sb.WriteString("
") + // Gmail leaves two blank lines between the headers and the body. + if htmlContent != "" { + sb.WriteString("

") + sb.WriteString(htmlContent) + } + sb.WriteString("
") return sb.String() } diff --git a/internal/cmd/gmail_forward_header_test.go b/internal/cmd/gmail_forward_header_test.go new file mode 100644 index 000000000..52664f5bb --- /dev/null +++ b/internal/cmd/gmail_forward_header_test.go @@ -0,0 +1,252 @@ +package cmd + +import ( + "strings" + "testing" + "time" +) + +// forwardHeaderBlocks renders a forward of an original with these headers in +// both parts, with no note and a one-line body. +func forwardHeaderBlocks(from, date, subject, to, cc string) (plain, html string) { + headers := forwardedMessageHeaders(from, date, subject, to, cc, time.UTC) + plain = formatForwardedMessage("", composeSignature{}, headers, "Body.") + html = formatForwardedMessageHTML("", composeSignature{}, headers, "

Body.

") + return plain, html +} + +// TestForwardedHeaderLines checks each header line as a reader sees it in both +// parts. The inputs are header values as the Gmail API returns them. +func TestForwardedHeaderLines(t *testing.T) { + const ( + from = `"Sender, Example" ` + date = "Mon, 10 Mar 2026 09:00:00 -0400" + subject = "Original Subject" + to = `Alice Example , bob@example.com, "Carol, Quoted" ` + cc = `"Dave, Encoded" , ` + ) + cases := []struct { + name string + from, date, subject string + to, cc string + wantPlain, wantHTML []string // whole lines + absent []string // labels with no line in either part + }{ + { + name: "named sender and several recipients", + from: from, subject: subject, to: to, cc: cc, + wantPlain: []string{ + "From: Sender, Example ", + "To: Alice Example , , Carol, Quoted ", + "Cc: Dave, Encoded , ", + }, + wantHTML: []string{ + "From: " + forwardSenderNameHTML("Sender, Example") + " " + quoteAddressHTML("sender@example.com"), + "To: " + isolatedHTML("Alice Example") + " " + quoteAddressHTML("alice@example.com") + ", " + + quoteAddressHTML("bob@example.com") + ", " + isolatedHTML("Carol, Quoted") + " " + quoteAddressHTML("carol@example.org"), + "Cc: " + isolatedHTML("Dave, Encoded") + " " + quoteAddressHTML("dave@example.com") + ", " + quoteAddressHTML("erin@example.com"), + }, + }, + { + name: "nameless sender, no Cc", + from: "sender@example.com", subject: subject, to: "recipient@example.com", + wantPlain: []string{"From: ", "To: "}, + wantHTML: []string{"From: " + quoteAddressHTML("sender@example.com"), "To: " + quoteAddressHTML("recipient@example.com")}, + absent: []string{"Cc"}, + }, + { + name: "groups list their members, as in Gmail", + from: from, subject: subject, + to: "Team:a@example.com, b@example.com;, c@example.com", + cc: "undisclosed-recipients:;, John Smith ", + wantPlain: []string{ + "To: , , ", + "Cc: John Smith ", + }, + wantHTML: []string{ + "To: " + quoteAddressHTML("a@example.com") + ", " + quoteAddressHTML("b@example.com") + ", " + quoteAddressHTML("c@example.com"), + "Cc: " + isolatedHTML("John Smith") + " " + quoteAddressHTML("john@example.com"), + }, + }, + { + // Gmail Web keeps the line and leaves it empty. + name: "a group with no members leaves the line empty", + from: from, subject: subject, to: "undisclosed-recipients:;", cc: " ", + wantPlain: []string{"To: "}, + wantHTML: []string{"To: "}, + absent: []string{"Cc"}, + }, + { + // The Gmail API turns a CRLF inside an encoded display name into ", " + // and leaves the name unquoted, so these do not parse. + name: "unparseable values are shown trimmed but as is, unlinked", + from: "Evil, Name ", subject: subject, + to: " Evil, Name , other@example.com ", + wantPlain: []string{ + "From: Evil, Name ", + "To: Evil, Name , other@example.com", + }, + wantHTML: []string{ + "From: " + isolatedHTML("Evil, Name <evil@example.com>"), + "To: " + isolatedHTML("Evil, Name <evil@example.com>, other@example.com"), + }, + }, + { + // An unparseable Date is shown as it came, so it is escaped too. + name: "names, date, subject and addresses are escaped in HTML", + from: `"Eve" `, date: "soon & later", subject: "Hi & co", + to: `<"john smith"@example.com>, "R&D " `, + wantPlain: []string{ + "From: Eve ", + "Date: soon & later", + "Subject: Hi & co", + `To: <"john smith"@example.com>, R&D `, + }, + wantHTML: []string{ + "From: " + forwardSenderNameHTML("<b>Eve</b>") + " " + quoteAddressHTML("eve@example.com"), + "Date: " + isolatedHTML("<b>soon</b> & later"), + "Subject: " + isolatedHTML("<i>Hi</i> & co"), + "To: " + isolatedHTML(`<"john smith"@example.com>`) + ", " + + isolatedHTML("R&D <Team>") + " " + isolatedHTML(`<user?bcc=x@example.com>`), + }, + }, + { + name: "a blank display name counts as none", + from: `" " `, subject: subject, to: `" " `, + wantPlain: []string{"From: ", "To: "}, + wantHTML: []string{"From: " + quoteAddressHTML("sender@example.com"), "To: " + quoteAddressHTML("recipient@example.com")}, + }, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + if tc.date == "" { + tc.date = date + } + plain, html := forwardHeaderBlocks(tc.from, tc.date, tc.subject, tc.to, tc.cc) + for _, want := range tc.wantPlain { + if !strings.Contains(plain, "\n"+want+"\n") { + t.Errorf("text/plain has no line %q:\n%s", want, plain) + } + } + for _, want := range tc.wantHTML { + if !strings.Contains(html, "
"+want+"
") { + t.Errorf("text/html has no line %q:\n%s", want, html) + } + } + for _, label := range tc.absent { + if strings.Contains(plain, "\n"+label+":") || strings.Contains(html, "
"+label+":") { + t.Errorf("unexpected %s line:\n%s\n%s", label, plain, html) + } + } + }) + } +} + +// TestForwardedHeaderLayout checks the block's layout: the separator runs +// straight into the headers, which carry no styling beyond the sender's name +// in bold, and two blank lines separate them from a body. +func TestForwardedHeaderLayout(t *testing.T) { + t.Run("with a body", func(t *testing.T) { + plain, html := forwardHeaderBlocks("Alice ", "Mon, 10 Mar 2026 09:00:00 -0400", + "Original Subject", "Bob ", "carol@example.com") + + // Gmail's separator text is pinned here; other tests find the block by + // forwardedSeparator. + if !strings.HasPrefix(plain, "---------- Forwarded message ---------\nFrom: Alice \n") { + t.Errorf("text/plain separator is not followed by the From line:\n%s", plain) + } + if !strings.HasSuffix(plain, "\nCc: \n\n\nBody.\n") { + t.Errorf("text/plain wants two blank lines between the headers and the body:\n%q", plain) + } + + // The block runs from the quote's opening markup to the first . + block, body, found := strings.Cut(html, "") + if !found { + t.Fatalf("text/html has no header block:\n%s", html) + } + if !strings.HasPrefix(block, gmailQuoteOpen+forwardedSeparator+"
From: ") { + t.Errorf("text/html separator is not followed by the From line:\n%s", block) + } + // Check only the header block (opening markup included): the + // original's own markup may be bold or styled. + for _, markup := range []string{"", "style=", "color"} { + if strings.Contains(block, markup) { + t.Errorf("text/html header block contains %q:\n%s", markup, block) + } + } + if strings.Count(block, "\nSubject: Subject\n"; plain != want { + t.Errorf("text/plain = %q, want %q", plain, want) + } + if html := formatForwardedMessageHTML("", composeSignature{}, headers, ""); !strings.HasSuffix(html, "Subject: "+isolatedHTML("Subject")+"
") { + t.Errorf("text/html ends with blank lines: %q", html) + } + }) +} + +// TestGmailForward_HeaderBlockLikeGmail runs both forward commands and checks +// that the original's headers reach both decoded parts of the message they +// build: the plain block exactly, as a plain-text reader sees it, and in HTML +// each header line in order inside the block, then the original's body. +func TestGmailForward_HeaderBlockLikeGmail(t *testing.T) { + t.Setenv("GOG_TIMEZONE", "UTC") + source := func() map[string]any { + msg := mockOriginalMessage(false) + payload := msg["payload"].(map[string]any) + payload["headers"] = []map[string]any{ + {"name": "From", "value": `"Sender, Example" `}, + {"name": "To", "value": `Alice Example , bob@example.com`}, + {"name": "Cc", "value": `"Carol, Quoted" `}, + {"name": "Date", "value": "Mon, 10 Mar 2026 09:00:00 -0400"}, + {"name": "Subject", "value": "Original Subject"}, + } + return msg + } + wantPlain := forwardedSeparator + "\n" + + "From: Sender, Example \n" + + "Date: Tue, Mar 10, 2026 at 1:00\u202fPM\n" + + "Subject: Original Subject\n" + + "To: Alice Example , \n" + + "Cc: Carol, Quoted \n\n\n" + + "Hello, this is the body." + wantHTML := []string{ + "From: " + forwardSenderNameHTML("Sender, Example") + " " + quoteAddressHTML("sender@example.com"), + "Date: " + isolatedHTML("Tue, Mar 10, 2026 at 1:00\u202fPM"), + "Subject: " + isolatedHTML("Original Subject"), + "To: " + isolatedHTML("Alice Example") + " " + quoteAddressHTML("alice@example.com") + ", " + quoteAddressHTML("bob@example.com"), + "Cc: " + isolatedHTML("Carol, Quoted") + " " + quoteAddressHTML("carol@example.org"), + } + for _, cmd := range forwardCommands { + t.Run(cmd.name, func(t *testing.T) { + plain, html := forwardTextParts(t, forwardArgs(cmd.verb, "--note", "FYI"), cmd.finalizePath, source) + if !strings.Contains(plain, wantPlain) { + t.Errorf("text/plain header block:\n got %q\nwant %q", plain, wantPlain) + } + _, rest, found := strings.Cut(html, gmailQuoteOpen+forwardedSeparator) + block, after, closed := strings.Cut(rest, "") + if !found || !closed { + t.Fatalf("text/html has no header block:\n%s", html) + } + for _, line := range wantHTML { + _, next, found := strings.Cut(block, "
"+line+"
") + if !found { + t.Fatalf("text/html header block has no line %q after the lines before it:\n%s", line, html) + } + block = "
" + next + } + if block != "
" || !strings.HasPrefix(after, "

Hello, this is the body.

") { + t.Errorf("text/html wants the header block, two blank lines, then the original's body:\n%s", html) + } + }) + } +} diff --git a/internal/cmd/gmail_forward_html_original_test.go b/internal/cmd/gmail_forward_html_original_test.go new file mode 100644 index 000000000..41212e3eb --- /dev/null +++ b/internal/cmd/gmail_forward_html_original_test.go @@ -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 "}, + {"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("

Quarterly numbers attached.

"), + }, + } +} + +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("

Quarterly numbers attached.

")}, + }, + }, + } +} + +// 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, "") { + t.Errorf("plain part carries raw HTML:\n%s", plain) + } + if !strings.Contains(html, "

Quarterly numbers attached.

") { + t.Errorf("HTML part lacks the original:\n%s", html) + } + }) + } + } +} diff --git a/internal/cmd/gmail_forward_note_test.go b/internal/cmd/gmail_forward_note_test.go new file mode 100644 index 000000000..5c5c14fbd --- /dev/null +++ b/internal/cmd/gmail_forward_note_test.go @@ -0,0 +1,282 @@ +package cmd + +import ( + "io" + "net/http" + "strings" + "testing" +) + +// noteRegion returns the part of a forward body above the forwarded message. +func noteRegion(t *testing.T, body, marker string) string { + t.Helper() + before, _, found := strings.Cut(body, marker) + if !found { + t.Fatalf("no %q in forward body:\n%s", marker, body) + } + return before +} + +func TestGmailForward_PlainNoteKeepsLineBreaksInHTML(t *testing.T) { + t.Setenv("GOG_TIMEZONE", "UTC") + const note = "First paragraph.\n\nSecond paragraph, with & ampersands." + for _, cmd := range forwardCommands { + t.Run(cmd.name, func(t *testing.T) { + plain, html := forwardTextParts(t, forwardArgs(cmd.verb, "--note", note), cmd.finalizePath, mockForwardSourceMessage) + + if got := strings.TrimSpace(noteRegion(t, plain, forwardedSeparator)); got != note { + t.Errorf("plain note = %q, want %q", got, note) + } + const wantHTML = "
First paragraph.
\n

\n
Second paragraph, with <tags> & ampersands.

" + if got := noteRegion(t, html, gmailQuoteOpen); got != wantHTML { + t.Errorf("HTML note = %q, want each line escaped in its own div:\n%q", got, wantHTML) + } + }) + } +} + +func TestGmailForward_HTMLNote(t *testing.T) { + t.Setenv("GOG_TIMEZONE", "UTC") + const noteHTML = "

First bold paragraph.

Second paragraph.

" + cases := []struct { + name string + source func() map[string]any + flags []string + wantPlain string // the whole plain note + wantHTML string // contained in the HTML note + notInHTML string // the plain note, which must not reach the HTML part + original string // the forwarded original in the HTML part + }{ + { + name: "HTML original", + source: mockForwardSourceMessage, + flags: []string{"--note-html", noteHTML}, + wantPlain: "First bold paragraph.\nSecond paragraph.", + wantHTML: noteHTML, + original: "

Hello, this is the body.

", + }, + { + name: "plain-only original", + source: mockPlainOnlyForwardSource, + flags: []string{"--note-html", noteHTML}, + wantPlain: "First bold paragraph.\nSecond paragraph.", + wantHTML: noteHTML, + original: "1 <b> & 2
\nsecond line", + }, + { + name: "plain and HTML notes", + source: mockForwardSourceMessage, + flags: []string{"--note", "Plain twin.", "--note-html", "

HTML twin.

"}, + wantPlain: "Plain twin.", + wantHTML: "

HTML twin.

", + notInHTML: "Plain twin.", + original: "

Hello, this is the body.

", + }, + } + for _, cmd := range forwardCommands { + for _, tc := range cases { + t.Run(cmd.name+"/"+tc.name, func(t *testing.T) { + plain, html := forwardTextParts(t, forwardArgs(cmd.verb, tc.flags...), cmd.finalizePath, tc.source) + + if got := strings.TrimSpace(noteRegion(t, plain, forwardedSeparator)); got != tc.wantPlain { + t.Errorf("plain note = %q, want %q", got, tc.wantPlain) + } + htmlNote := noteRegion(t, html, gmailQuoteOpen) + if !strings.Contains(htmlNote, tc.wantHTML) { + t.Errorf("HTML note missing %q:\n%s", tc.wantHTML, htmlNote) + } + if tc.notInHTML != "" && strings.Contains(htmlNote, tc.notInHTML) { + t.Errorf("plain note leaked into the HTML part:\n%s", htmlNote) + } + if !strings.Contains(html, tc.original) { + t.Errorf("forwarded original missing from the HTML part; want %q in:\n%s", tc.original, html) + } + }) + } + } +} + +func TestGmailForward_WithoutNoteKeepsPlainPart(t *testing.T) { + t.Setenv("GOG_TIMEZONE", "UTC") + for _, cmd := range forwardCommands { + t.Run(cmd.name, func(t *testing.T) { + plain, _ := forwardTextParts(t, forwardArgs(cmd.verb), cmd.finalizePath, mockForwardSourceMessage) + if !strings.HasPrefix(plain, forwardedSeparator) || !strings.Contains(plain, "Hello, this is the body.") { + t.Errorf("plain part should be the forwarded message alone:\n%s", plain) + } + }) + } +} + +// An HTML note file holding only whitespace (a template's trailing newline, +// say) counts as no HTML note. +func TestGmailForward_WhitespaceOnlyHTMLNoteCountsAsMissing(t *testing.T) { + t.Setenv("GOG_TIMEZONE", "UTC") + blank := writeTempFile(t, "note.html", " \n") + for _, cmd := range forwardCommands { + t.Run(cmd.name+"/alone", func(t *testing.T) { + plain, html := forwardTextParts(t, forwardArgs(cmd.verb, "--note-html-file", blank), cmd.finalizePath, mockForwardSourceMessage) + if !strings.HasPrefix(plain, forwardedSeparator) { + t.Errorf("plain part should be the forwarded message alone:\n%s", plain) + } + if got := noteRegion(t, html, gmailQuoteOpen); got != "" { + t.Errorf("HTML note = %q, want none", got) + } + }) + t.Run(cmd.name+"/beside a plain note", func(t *testing.T) { + plain, html := forwardTextParts(t, forwardArgs(cmd.verb, "--note", "FYI", "--note-html-file", blank), cmd.finalizePath, mockForwardSourceMessage) + if got := strings.TrimSpace(noteRegion(t, plain, forwardedSeparator)); got != "FYI" { + t.Errorf("plain note = %q, want %q", got, "FYI") + } + if got := noteRegion(t, html, gmailQuoteOpen); got != `
FYI

` { + t.Errorf("HTML note = %q, want the plain note escaped", got) + } + }) + } +} + +// An image-only HTML note has no plain-text rendering. Like an image-only reply, +// the forward then has no plain part, rather than one without the note, unless +// a plain note or a signature with text gives the plain part text of its own. +func TestGmailForward_ImageOnlyHTMLNote(t *testing.T) { + t.Setenv("GOG_TIMEZONE", "UTC") + const image = `` + cases := []struct { + name string + plainNote string + signature string + wantPlain string // how the plain part opens; "" for no plain part + }{ + {name: "no signature"}, + {name: "image signature", signature: ``}, + {name: "text signature", signature: "
Kind regards
", wantPlain: "--\nKind regards\n\n" + forwardedSeparator}, + {name: "plain note too", plainNote: "Plain twin.", wantPlain: "Plain twin.\n\n" + forwardedSeparator}, + } + for _, cmd := range forwardCommands { + for _, tc := range cases { + t.Run(cmd.name+"/"+tc.name, func(t *testing.T) { + svc, got, cleanup := newSignatureComposeService(t, map[string]string{"me@example.com": tc.signature}, nil) + defer cleanup() + flags := []string{"--note-html", image} + if tc.plainNote != "" { + flags = append(flags, "--note", tc.plainNote) + } + if tc.signature != "" { + flags = append(flags, "--signature") + } + if result := executeWithGmailTestService(t, forwardArgs(cmd.verb, flags...), svc); result.err != nil { + t.Fatalf("forward: %v", result.err) + } + + if hasPlain := strings.Contains(got.raw, "Content-Type: text/plain"); hasPlain != (tc.wantPlain != "") { + t.Fatalf("text/plain part present = %v, want %v:\n%s", hasPlain, tc.wantPlain != "", got.raw) + } + if tc.wantPlain != "" { + plain := strings.ReplaceAll(rawTextPart(t, got.raw, "text/plain"), "\r\n", "\n") + if !strings.HasPrefix(plain, tc.wantPlain) { + t.Errorf("plain part should open with %q; got:\n%s", tc.wantPlain, plain) + } + } + if html := rawTextPart(t, got.raw, "text/html"); !strings.Contains(noteRegion(t, html, gmailQuoteOpen), image) { + t.Errorf("image note missing above the forwarded message:\n%s", html) + } + }) + } + } +} + +func TestGmailForward_HTMLNoteSitsAboveSignature(t *testing.T) { + t.Setenv("GOG_TIMEZONE", "UTC") + for _, cmd := range forwardCommands { + t.Run(cmd.name, func(t *testing.T) { + svc, got, cleanup := newSignatureComposeService(t, map[string]string{"me@example.com": "
Kind regards
"}, nil) + defer cleanup() + args := forwardArgs(cmd.verb, "--note-html", "

See below.

", "--signature") + if result := executeWithGmailTestService(t, args, svc); result.err != nil { + t.Fatalf("forward: %v", result.err) + } + + plain := strings.ReplaceAll(rawTextPart(t, got.raw, "text/plain"), "\r\n", "\n") + if want := "See below.\n\n--\nKind regards\n\n" + forwardedSeparator; !strings.Contains(plain, want) { + t.Errorf("plain part not note, signature, forward; want %q in:\n%s", want, plain) + } + html := rawTextPart(t, got.raw, "text/html") + if want := `

See below.


` + gmailSignatureOpen + `
Kind regards

` + gmailQuoteOpen; !strings.Contains(html, want) { + t.Errorf("HTML part not note, signature, forward; want %q in:\n%s", want, html) + } + }) + } +} + +// A note given as a whole HTML document goes in as given, with two
after +// it: a document may end inline, where one would leave no blank line above the +// forwarded message. +func TestGmailForward_HTMLDocumentNote(t *testing.T) { + t.Setenv("GOG_TIMEZONE", "UTC") + const note = "FYI" + for _, cmd := range forwardCommands { + t.Run(cmd.name, func(t *testing.T) { + _, html := forwardTextParts(t, forwardArgs(cmd.verb, "--note-html", note), cmd.finalizePath, mockForwardSourceMessage) + if got := noteRegion(t, html, gmailQuoteOpen); got != note+"

" { + t.Errorf("HTML note = %q, want the document as given and two
", got) + } + }) + } +} + +func TestGmailForward_NoteFlagConflictsFailBeforeAPICalls(t *testing.T) { + notePath := writeTempFile(t, "note.txt", "Note from a file") + cases := []struct { + name string + flags []string + want string + }{ + {"note and note-file", []string{"--note", "x", "--note-file", notePath}, "use only one of --note or --note-file"}, + {"note-html and note-html-file", []string{"--note-html", "

x

", "--note-html-file", notePath}, "use only one of --note-html or --note-html-file"}, + {"both files from stdin", []string{"--note-file", "-", "--note-html-file", "-"}, "use stdin for only one of --note-file or --note-html-file"}, + } + for _, cmd := range forwardCommands { + for _, tc := range cases { + t.Run(cmd.name+"/"+tc.name, func(t *testing.T) { + setTestConfigHome(t) + requests := 0 + svc, cleanup := newGmailServiceForTest(t, func(w http.ResponseWriter, r *http.Request) { + requests++ + http.NotFound(w, r) + }) + defer cleanup() + + result := executeWithGmailTestService(t, forwardArgs(cmd.verb, tc.flags...), svc) + if result.err == nil || !strings.Contains(result.err.Error(), tc.want) { + t.Fatalf("error = %v, want %q", result.err, tc.want) + } + if requests != 0 { + t.Fatalf("expected no Gmail API requests, got %d", requests) + } + }) + } + } +} + +func TestGmailDraftsForward_NoteHTMLFileStdin(t *testing.T) { + t.Setenv("GOG_TIMEZONE", "UTC") + svc, cleanup, created, rawPtr := newForwardDraftCaptureService(t) + defer cleanup() + + ctx := withGmailTestService( + newCmdRuntimeIOContext(t, strings.NewReader("

Note from stdin

\n"), io.Discard, io.Discard), + svc, + ) + if err := runKong(t, &GmailDraftsForwardCmd{}, []string{"orig-msg-1", "--to", "r@example.com", "--note-html-file", "-"}, ctx, &RootFlags{Account: "me@example.com"}); err != nil { + t.Fatalf("execute: %v", err) + } + if !*created { + t.Fatal("expected Drafts.Create to be called") + } + if html := rawTextPart(t, *rawPtr, "text/html"); !strings.Contains(html, `

Note from stdin

`) { + t.Fatalf("expected stdin HTML note in the HTML part:\n%s", html) + } + if plain := rawTextPart(t, *rawPtr, "text/plain"); !strings.Contains(plain, "Note from stdin") { + t.Fatalf("expected the derived plain note in the plain part:\n%s", plain) + } +} diff --git a/internal/cmd/gmail_labels.go b/internal/cmd/gmail_labels.go index 19720e08c..5129901ff 100644 --- a/internal/cmd/gmail_labels.go +++ b/internal/cmd/gmail_labels.go @@ -7,6 +7,7 @@ import ( "google.golang.org/api/gmail/v1" + "github.com/openclaw/gogcli/internal/errfmt" "github.com/openclaw/gogcli/internal/outfmt" "github.com/openclaw/gogcli/internal/ui" ) @@ -368,9 +369,9 @@ func (c *GmailLabelsModifyCmd) Run(ctx context.Context, flags *RootFlags) error RemoveLabelIds: removeIDs, }).Context(ctx).Do() if err != nil { - results = append(results, result{ThreadID: tid, Success: false, Error: err.Error()}) + results = append(results, result{ThreadID: tid, Success: false, Error: errfmt.FormatDiagnostic(err)}) if !outfmt.IsJSON(ctx) { - u.Err().Errorf("%s: %s", tid, err.Error()) + u.Err().Errorf("%s: %s", tid, errfmt.FormatDiagnostic(err)) } continue } diff --git a/internal/cmd/gmail_messages.go b/internal/cmd/gmail_messages.go index 7135e484e..949610d33 100644 --- a/internal/cmd/gmail_messages.go +++ b/internal/cmd/gmail_messages.go @@ -3,6 +3,8 @@ package cmd import ( "context" "fmt" + "net/textproto" + "slices" "strings" "sync" "time" @@ -34,6 +36,7 @@ type GmailMessagesSearchCmd struct { All bool `name:"all" aliases:"all-pages,allpages" help:"Fetch all pages"` FailEmpty bool `name:"fail-empty" aliases:"non-empty,require-results" help:"Exit with code 3 if no results"` Count bool `name:"count" help:"Report the whole-query count as totalMatches (exact) or totalMatchesAtLeast (lower bound); free with --all unless --page is set; unavailable with --results-only"` + IDsOnly bool `name:"ids-only" help:"Return only message and thread IDs from the list call, skipping the label lookup and per-message fetch (use --max 500 for the largest pages)"` Timezone string `name:"timezone" short:"z" help:"Output timezone (IANA name, e.g. America/New_York, UTC). Default: GOG_TIMEZONE, config, then local"` Local bool `name:"local" help:"Use local timezone (default behavior, useful to override --timezone)"` IncludeBody bool `name:"include-body" help:"Include decoded message body (JSON is full; text output truncates only unusually large bodies)"` @@ -41,6 +44,7 @@ type GmailMessagesSearchCmd struct { Full bool `name:"full" help:"Show full message bodies without truncation (implies --include-body)"` IncludeAttachments bool `name:"include-attachments" env:"GOG_GMAIL_INCLUDE_ATTACHMENTS" help:"Include each message's attachment metadata"` IncludeRecipients bool `name:"include-recipients" help:"Include To, Cc, and Bcc in JSON output (no extra API calls)"` + Headers string `name:"headers" help:"Include up to 50 headers in JSON output under headers (comma-separated, max 256 bytes per name; canonical keys, e.g. Message-ID becomes Message-Id; first value if repeated; no extra API calls)"` SanitizeContent bool `name:"sanitize-content" aliases:"sanitize,safe" help:"Emit agent-oriented sanitized content, as in gmail get: strip HTML, remove HTTP(S) URLs, and sanitize header text"` } @@ -51,6 +55,13 @@ func (c *GmailMessagesSearchCmd) Run(ctx context.Context, flags *RootFlags) erro if c.SanitizeContent && c.IncludeBody && c.BodyFormat == gmailMessageBodyFormatHTML { return usage("--sanitize-content cannot be used with --body-format html") } + if c.IDsOnly && (c.IncludeBody || c.IncludeAttachments || c.IncludeRecipients || c.Headers != "" || c.SanitizeContent) { + return usage("--ids-only cannot be used with --include-body, --full, --include-attachments, --include-recipients, --headers, or --sanitize-content") + } + headerNames, headerErr := gmailSearchHeaderNames(c.Headers) + if headerErr != nil { + return headerErr + } u := ui.FromContext(ctx) if err := validateGmailMaxResults(c.Max); err != nil { return err @@ -116,23 +127,18 @@ func (c *GmailMessagesSearchCmd) Run(ctx context.Context, flags *RootFlags) erro return failEmptyExit(c.FailEmpty) } - idToName, err := fetchLabelIDToName(svc) - if err != nil { - return err - } - - loc, err := resolveOutputLocation(ctx, c.Timezone, c.Local, stderrWriter(ctx)) - if err != nil { - return err - } - - items, err := fetchMessageDetails(ctx, svc, messages, idToName, loc, c.IncludeBody, c.BodyFormat, c.IncludeAttachments, c.UseIndexedAttachmentIDs, c.IncludeRecipients, c.SanitizeContent) - if err != nil { - return err + var items []messageItem + if c.IDsOnly { + items = messageIDItems(messages) + } else { + items, err = c.fetchDetails(ctx, svc, messages, headerNames) + if err != nil { + return err + } } if outfmt.IsJSON(ctx) { - ctx = outfmt.WithUntrustedContentKeys(ctx, "from", "to", "cc", "bcc") + ctx = outfmt.WithUntrustedContentKeys(ctx, append([]string{"from", "to", "cc", "bcc"}, headerNames...)...) payload := map[string]any{ "messages": items, "nextPageToken": nextPageToken, @@ -148,11 +154,15 @@ func (c *GmailMessagesSearchCmd) Run(ctx context.Context, flags *RootFlags) erro return failEmptyExit(c.FailEmpty) } + columns := gmailMessageColumns(c.IncludeBody, c.IncludeAttachments, c.Full) + if c.IDsOnly { + columns = gmailMessageIDColumns() + } if err := outfmt.WriteTable( ctx, stdoutWriter(ctx), items, - gmailMessageColumns(c.IncludeBody, c.IncludeAttachments, c.Full), + columns, ); err != nil { return err } @@ -164,6 +174,29 @@ func (c *GmailMessagesSearchCmd) Run(ctx context.Context, flags *RootFlags) erro return nil } +func (c *GmailMessagesSearchCmd) fetchDetails(ctx context.Context, svc *gmail.Service, messages []*gmail.Message, headerNames []string) ([]messageItem, error) { + idToName, err := fetchLabelIDToName(svc) + if err != nil { + return nil, err + } + loc, err := resolveOutputLocation(ctx, c.Timezone, c.Local, stderrWriter(ctx)) + if err != nil { + return nil, err + } + return fetchMessageDetails(ctx, svc, messages, idToName, loc, c.IncludeBody, c.BodyFormat, c.IncludeAttachments, c.UseIndexedAttachmentIDs, c.IncludeRecipients, headerNames, c.SanitizeContent) +} + +func messageIDItems(messages []*gmail.Message) []messageItem { + items := make([]messageItem, 0, len(messages)) + for _, m := range messages { + if m == nil || m.Id == "" { + continue + } + items = append(items, messageItem{ID: m.Id, ThreadID: m.ThreadId}) + } + return items +} + type GmailMessagesModifyCmd struct { MessageID string `arg:"" name:"messageId" help:"Message ID"` Add []string `name:"add" sep:"none" help:"Labels to add (comma-separated or repeated; name or ID)"` @@ -242,18 +275,23 @@ type messageItem struct { To string `json:"to,omitempty"` Cc string `json:"cc,omitempty"` Bcc string `json:"bcc,omitempty"` + Headers map[string]string `json:"headers,omitempty"` Subject string `json:"subject,omitempty"` Labels []string `json:"labels,omitempty"` Body string `json:"body,omitempty"` Attachments []attachmentOutput `json:"attachments,omitempty"` } -func fetchMessageDetails(ctx context.Context, svc *gmail.Service, messages []*gmail.Message, idToName map[string]string, loc *time.Location, includeBody bool, bodyFormat string, includeAttachments bool, useIndexedAttachmentIDs bool, includeRecipients bool, sanitize bool) ([]messageItem, error) { +func fetchMessageDetails(ctx context.Context, svc *gmail.Service, messages []*gmail.Message, idToName map[string]string, loc *time.Location, includeBody bool, bodyFormat string, includeAttachments bool, useIndexedAttachmentIDs bool, includeRecipients bool, headerNames []string, sanitize bool) ([]messageItem, error) { preferHTML := bodyFormat == gmailMessageBodyFormatHTML if len(messages) == 0 { return nil, nil } + // The first failure fails the whole listing, so stop the remaining fetches. + ctx, cancel := context.WithCancel(ctx) + defer cancel() + const maxConcurrency = 10 sem := make(chan struct{}, maxConcurrency) @@ -291,6 +329,11 @@ func fetchMessageDetails(ctx context.Context, svc *gmail.Service, messages []*gm if includeRecipients { headers = append(headers, "To", "Cc", "Bcc") } + for _, name := range headerNames { + if !hasHeaderName(headers, name) { + headers = append(headers, name) + } + } call = call.Format("metadata"). MetadataHeaders(headers...). Fields(gmailMessageSummaryFields) @@ -320,6 +363,12 @@ func fetchMessageDetails(ctx context.Context, svc *gmail.Service, messages []*gm item.Cc = header("Cc") item.Bcc = header("Bcc") } + if len(headerNames) > 0 { + item.Headers = make(map[string]string, len(headerNames)) + for _, name := range headerNames { + item.Headers[name] = header(name) + } + } item.Date = formatGmailDateInLocation(headerValue(msg.Payload, "Date"), loc) item.InternalDateISO = formatGmailDateISO(msg.InternalDate, loc) if includeBody { @@ -364,6 +413,7 @@ func fetchMessageDetails(ctx context.Context, svc *gmail.Service, messages []*gm if r.err != nil { if firstErr == nil { firstErr = r.err + cancel() } ordered[r.index] = messageItem{} continue @@ -383,6 +433,32 @@ func fetchMessageDetails(ctx context.Context, svc *gmail.Service, messages []*gm return items, nil } +// gmailSearchHeaderNames canonicalizes and dedupes --headers names, so JSON keys +// do not depend on how they were typed and never collide with messageItem's +// lower-camel fields when they are marked as untrusted content. +func gmailSearchHeaderNames(raw string) ([]string, error) { + entries := splitCSV(raw) + if len(entries) > 50 { + return nil, usage("--headers accepts at most 50 names") + } + var names []string + for _, name := range entries { + if len(name) > 256 { + return nil, usage("--headers names must be at most 256 bytes") + } + for _, ch := range name { + if ch < 33 || ch > 126 || ch == ':' { + return nil, usage("--headers requires printable ASCII field names without spaces or colons") + } + } + name = textproto.CanonicalMIMEHeaderKey(name) + if !slices.Contains(names, name) { + names = append(names, name) + } + } + return names, nil +} + func sanitizeMessageBody(body string, full bool) string { if body == "" { return "" diff --git a/internal/cmd/gmail_messages_search_headers_test.go b/internal/cmd/gmail_messages_search_headers_test.go new file mode 100644 index 000000000..afb14b4d7 --- /dev/null +++ b/internal/cmd/gmail_messages_search_headers_test.go @@ -0,0 +1,203 @@ +package cmd + +import ( + "encoding/json" + "maps" + "slices" + "strings" + "testing" + + "github.com/mark3labs/mcp-go/mcp" +) + +func searchHeadersOf(t *testing.T, msg map[string]any) map[string]any { + t.Helper() + headers, ok := msg["headers"].(map[string]any) + if !ok { + t.Fatalf("headers missing or not an object: %#v", msg["headers"]) + } + return headers +} + +func TestGmailMessagesSearch_HeadersMetadataUsesSameGet(t *testing.T) { + svc, stub := newSearchStub(t, []string{"m1", "m2", "m3"}, searchTestHTMLBody, searchTestPlainBody) + raw, stdout := runSearchJSON(t, svc, "--headers", "list-id, Sender,LIST-ID,X-Missing,Message-ID") + + if got := stub.gets(); got != 3 { + t.Fatalf("message gets = %d, want exactly one per result (3)", got) + } + for i, set := range stub.getHeaderSets { + if stub.getFormats[i] != "metadata" { + t.Fatalf("format = %q, want metadata", stub.getFormats[i]) + } + want := []string{"From", "Subject", "Date", "List-Id", "Sender", "X-Missing", "Message-Id"} + if !slices.Equal(set, want) { + t.Fatalf("metadataHeaders = %v, want %v", set, want) + } + } + + got := searchHeadersOf(t, raw["messages"][0]) + want := map[string]any{ + "List-Id": "Some Pub ", + "Sender": "Group ", + "X-Missing": "", + // Canonical keys rewrite acronyms: Message-ID comes back as Message-Id. + "Message-Id": "", + } + if !maps.Equal(got, want) { + t.Fatalf("headers = %#v, want %#v", got, want) + } + for _, key := range []string{`"to"`, `"body"`} { + if strings.Contains(stdout, key) { + t.Fatalf("--headers must not add %s: %s", key, stdout) + } + } +} + +func TestGmailMessagesSearch_HeadersFullReadsExistingPayload(t *testing.T) { + svc, stub := newSearchStub(t, []string{"m1"}, searchTestHTMLBody, searchTestPlainBody) + raw, _ := runSearchJSON(t, svc, "--include-body", "--headers", "List-Id,Received,message-id") + + if got := stub.gets(); got != 1 || stub.getFormats[0] != "full" { + t.Fatalf("gets=%d formats=%v, want one full get", got, stub.getFormats) + } + if len(stub.getHeaderSets[0]) != 0 { + t.Fatalf("full get must not send metadataHeaders: %v", stub.getHeaderSets[0]) + } + headers := searchHeadersOf(t, raw["messages"][0]) + if headers["List-Id"] != "Some Pub " { + t.Fatalf("List-Id = %q", headers["List-Id"]) + } + if headers["Message-Id"] != "" { + t.Fatalf("Message-Id = %q", headers["Message-Id"]) + } + // Repeated headers keep the first occurrence, as everywhere else in gog. + if headers["Received"] != "first hop" { + t.Fatalf("Received = %q, want the first occurrence", headers["Received"]) + } +} + +func TestGmailMessagesSearch_HeadersWithRecipientsShareOneRequest(t *testing.T) { + svc, stub := newSearchStub(t, []string{"m1"}, searchTestHTMLBody, searchTestPlainBody) + raw, _ := runSearchJSON(t, svc, "--include-recipients", "--headers", "to,List-Id") + + want := []string{"From", "Subject", "Date", "To", "Cc", "Bcc", "List-Id"} + if got := stub.getHeaderSets[0]; !slices.Equal(got, want) { + t.Fatalf("metadataHeaders = %v, want %v", got, want) + } + msg := raw["messages"][0] + if headers := searchHeadersOf(t, msg); headers["To"] != msg["to"] || msg["to"] == "" { + t.Fatalf("headers.To = %q, to = %q", headers["To"], msg["to"]) + } +} + +func TestGmailMessagesSearch_HeadersAreSanitized(t *testing.T) { + svc, stub := newSearchStub(t, []string{"m1"}, searchTestHTMLBody, searchTestPlainBody) + stub.mu.Lock() + stub.headerOverrides = map[string]string{"List-Id": "Pub https://list.example/x "} + stub.mu.Unlock() + + raw, stdout := runSearchJSON(t, svc, "--sanitize-content", "--headers", "List-Id") + if got := searchHeadersOf(t, raw["messages"][0])["List-Id"]; got != "Pub [url removed] " { + t.Fatalf("sanitized List-Id = %q", got) + } + if strings.Contains(stdout, "list.example/x") { + t.Fatalf("url leaked: %s", stdout) + } +} + +func TestGmailMessagesSearch_WrapsSelectedHeaders(t *testing.T) { + const marker = "<<"}, {"name": "Subject", "value": "See https://subject.example/x"}, {"name": "Date", "value": "Tue, 28 Jul 2026 03:36:00 +0000"}, + {"name": "List-Id", "value": "Some Pub "}, + {"name": "Sender", "value": "Group "}, + {"name": "Received", "value": "first hop"}, + {"name": "Received", "value": "second hop"}, + {"name": "Message-ID", "value": ""}, } srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { path := r.URL.Path @@ -73,7 +78,7 @@ func newSearchStub(t *testing.T, ids []string, htmlBody, plainBody string) (*gma if ok { h = map[string]string{"name": h["name"], "value": override} } - if format == "metadata" && !slices.Contains(wanted, h["name"]) { + if format == "metadata" && !slices.ContainsFunc(wanted, func(name string) bool { return strings.EqualFold(name, h["name"]) }) { continue } headers = append(headers, h) @@ -130,7 +135,7 @@ func TestGmailMessagesSearch_DefaultOmitsRecipientsAndAsksForSummaryHeadersOnly( if len(raw["messages"]) != 2 { t.Fatalf("messages = %d, want 2", len(raw["messages"])) } - for _, key := range []string{`"to"`, `"cc"`, `"bcc"`, `"body"`} { + for _, key := range []string{`"to"`, `"cc"`, `"bcc"`, `"body"`, `"headers"`} { if strings.Contains(stdout, key) { t.Fatalf("default output must not contain %s: %s", key, stdout) } diff --git a/internal/cmd/gmail_messages_test.go b/internal/cmd/gmail_messages_test.go index 3e30662f8..f3a5cb2e6 100644 --- a/internal/cmd/gmail_messages_test.go +++ b/internal/cmd/gmail_messages_test.go @@ -55,17 +55,12 @@ func TestFetchMessageDetails_NoRetryOnError(t *testing.T) { var calls int32 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if !strings.Contains(r.URL.Path, "/users/me/messages/") { + if !strings.Contains(r.URL.Path, "/users/me/messages/m1") { http.NotFound(w, r) return } atomic.AddInt32(&calls, 1) - if strings.Contains(r.URL.Path, "/users/me/messages/m1") { - http.Error(w, "boom", http.StatusInternalServerError) - return - } - w.Header().Set("Content-Type", "application/json") - _, _ = w.Write([]byte(`{"id":"m2","threadId":"t2","payload":{"headers":[{"name":"From","value":"me@example.com"}]}}`)) + http.Error(w, "boom", http.StatusInternalServerError) })) defer srv.Close() @@ -78,12 +73,12 @@ func TestFetchMessageDetails_NoRetryOnError(t *testing.T) { t.Fatalf("NewService: %v", err) } - messages := []*gmail.Message{{Id: "m1"}, {Id: "m2"}} - _, err = fetchMessageDetails(context.Background(), svc, messages, map[string]string{}, time.UTC, false, gmailMessageBodyFormatText, false, false, false, false) + messages := []*gmail.Message{{Id: "m1"}} + _, err = fetchMessageDetails(context.Background(), svc, messages, map[string]string{}, time.UTC, false, gmailMessageBodyFormatText, false, false, false, nil, false) if err == nil || !strings.Contains(err.Error(), "message m1") { t.Fatalf("expected message error, got %v", err) } - if got := atomic.LoadInt32(&calls); got != 2 { - t.Fatalf("expected 2 calls, got %d", got) + if got := atomic.LoadInt32(&calls); got != 1 { + t.Fatalf("expected 1 call without retry, got %d", got) } } diff --git a/internal/cmd/gmail_presentation.go b/internal/cmd/gmail_presentation.go index c59424f77..c14f6ce9a 100644 --- a/internal/cmd/gmail_presentation.go +++ b/internal/cmd/gmail_presentation.go @@ -76,6 +76,19 @@ func sanitizeGmailTableValue(value string) string { }, value) } +func gmailMessageIDColumns() []outfmt.Column[messageItem] { + return []outfmt.Column[messageItem]{ + {Header: "ID", Value: func(item messageItem) string { return item.ID }}, + {Header: "THREAD", Value: func(item messageItem) string { return item.ThreadID }}, + } +} + +func gmailThreadIDColumns() []outfmt.Column[threadItem] { + return []outfmt.Column[threadItem]{ + {Header: "ID", Value: func(item threadItem) string { return item.ID }}, + } +} + func gmailThreadColumns() []outfmt.Column[threadItem] { return []outfmt.Column[threadItem]{ {Header: "ID", Value: func(item threadItem) string { return item.ID }}, diff --git a/internal/cmd/gmail_quote_mailbox.go b/internal/cmd/gmail_quote_mailbox.go new file mode 100644 index 000000000..528535dab --- /dev/null +++ b/internal/cmd/gmail_quote_mailbox.go @@ -0,0 +1,160 @@ +package cmd + +import ( + "html" + "net/mail" + "strings" +) + +// parseQuoteMailbox splits a header holding one mailbox, such as From, into its +// display name and address. ok is false when the value is not a single +// parseable mailbox. +func parseQuoteMailbox(value string) (name, address string, ok bool) { + addr, err := mail.ParseAddress(strings.TrimSpace(value)) + if err != nil { + return "", "", false + } + name, address = quoteMailboxParts(addr) + return name, address, true +} + +// quoteMailboxParts returns a parsed mailbox's display name and addr-spec. +// net/mail's parsers unquote a quoted local part ("john smith"@example.com). A +// nameless Address's String is "" with the local part re-quoted +// where needed, so trimming the brackets leaves a valid addr-spec. +func quoteMailboxParts(addr *mail.Address) (name, address string) { + address = strings.TrimSuffix(strings.TrimPrefix((&mail.Address{Address: addr.Address}).String(), "<"), ">") + return strings.TrimSpace(addr.Name), address +} + +// formatQuoteMailbox renders a header holding one mailbox the way Gmail shows +// a sender in a reply's attribution line or a forward's header block: +// "Name " with a display name, "" without one. A value that is +// not a single parseable mailbox is returned trimmed and otherwise unchanged. +// (formatMailbox, in gmail_recipients.go, writes the wire form of an outgoing +// recipient instead.) +func formatQuoteMailbox(value string) string { + name, address, ok := parseQuoteMailbox(value) + if !ok { + return strings.TrimSpace(value) + } + return quoteMailboxText(name, address) +} + +// formatQuoteMailboxHTML is formatQuoteMailbox for HTML: the same text, +// escaped, with a parsed address linked via mailto: and the name bold or not, +// per style. A value that does not parse is escaped but not linked, and keeps +// its own direction as a whole. +func formatQuoteMailboxHTML(value string, style nameStyle) string { + name, address, ok := parseQuoteMailbox(value) + if !ok { + return isolateTextDirection(strings.TrimSpace(value)) + } + return quoteMailboxHTML(name, address, style) +} + +// formatQuoteMailboxList renders a header holding a list of mailboxes, such as +// To or Cc: each mailbox as formatQuoteMailbox renders one, joined by ", ". +// Like Gmail, it lists a group's members without the group's name, so a group +// with none ("undisclosed-recipients:;") renders empty. A value that is not a +// parseable address list is returned trimmed and otherwise unchanged. +func formatQuoteMailboxList(value string) string { + addrs, err := mail.ParseAddressList(value) + if err != nil { + return strings.TrimSpace(value) + } + mailboxes := make([]string, len(addrs)) + for i, addr := range addrs { + mailboxes[i] = quoteMailboxText(quoteMailboxParts(addr)) + } + return strings.Join(mailboxes, ", ") +} + +// formatQuoteMailboxListHTML is formatQuoteMailboxList for HTML: each mailbox +// as formatQuoteMailboxHTML renders one, with the name not bold. A value that +// does not parse is escaped but not linked, and keeps its own direction as a +// whole. +func formatQuoteMailboxListHTML(value string) string { + addrs, err := mail.ParseAddressList(value) + if err != nil { + return isolateTextDirection(strings.TrimSpace(value)) + } + mailboxes := make([]string, len(addrs)) + for i, addr := range addrs { + name, address := quoteMailboxParts(addr) + mailboxes[i] = quoteMailboxHTML(name, address, plainName) + } + return strings.Join(mailboxes, ", ") +} + +// quoteMailboxText renders one mailbox: "Name ", or "" when name +// is empty. +func quoteMailboxText(name, address string) string { + if name == "" { + return "<" + address + ">" + } + return name + " <" + address + ">" +} + +// nameStyle says how quoteMailboxHTML sets a display name. Gmail Web bolds +// the sender's name in a forward's header block, with the gmail_sendername +// class, but not in a reply's attribution line. The class matters: when Gmail +// rebuilds the text part of a message sent through the API, it turns bold into +// *asterisks* but leaves a gmail_sendername name as it is. (Only the delivered +// copy shows this; the Sent copy keeps the text part gog wrote.) +type nameStyle bool + +const ( + plainName nameStyle = false + boldName nameStyle = true +) + +// quoteMailboxHTML is quoteMailboxText for HTML: the name escaped and bold or +// not, per style, the address linked via mailto:. The name and the bracketed +// address each keep their own direction (see isolateDirection); a bold name +// carries dir="auto" on its . Gmail Web marks only a forward's sender +// this way; gog marks every name and address. +func quoteMailboxHTML(name, address string, style nameStyle) string { + link := isolateDirection(`<` + html.EscapeString(address) + `>`) + switch { + case name == "": + return link + case style == boldName: + return `` + html.EscapeString(name) + " " + link + default: + return isolateTextDirection(name) + " " + link + } +} + +// mailtoURI returns a mailto: URI for an addr-spec (RFC 6068). Both sides of +// the final "@" are percent-encoded except for unreserved characters and "+". +// Otherwise characters that are valid in a mailbox would change the link: "?" +// would start header fields, "#" a fragment that cuts the address short, and +// "," or a quoted "@" would split it. "+" stays raw so plus-addressed hrefs +// remain readable. +func mailtoURI(addrSpec string) string { + at := strings.LastIndexByte(addrSpec, '@') + if at < 0 { + // A parsed addr-spec always has an "@"; escape anything else whole + // rather than slicing at -1. + return "mailto:" + mailtoEscape(addrSpec) + } + return "mailto:" + mailtoEscape(addrSpec[:at]) + "@" + mailtoEscape(addrSpec[at+1:]) +} + +func mailtoEscape(s string) string { + const hexDigits = "0123456789ABCDEF" + var b strings.Builder + for i := 0; i < len(s); i++ { + c := s[i] + switch { + case 'a' <= c && c <= 'z', 'A' <= c && c <= 'Z', '0' <= c && c <= '9', strings.IndexByte("-._~+", c) >= 0: + b.WriteByte(c) + default: + b.WriteByte('%') + b.WriteByte(hexDigits[c>>4]) + b.WriteByte(hexDigits[c&0x0f]) + } + } + return b.String() +} diff --git a/internal/cmd/gmail_quote_mailbox_test.go b/internal/cmd/gmail_quote_mailbox_test.go new file mode 100644 index 000000000..209017651 --- /dev/null +++ b/internal/cmd/gmail_quote_mailbox_test.go @@ -0,0 +1,69 @@ +package cmd + +import ( + "net/mail" + "net/url" + "strings" + "testing" +) + +func TestFormatQuoteMailboxHTMLEscapesNameAndAddress(t *testing.T) { + got := formatQuoteMailboxHTML(`"Eve" <"x\"onclick=\"alert(1)"@example.com>`, plainName) + want := isolatedHTML("<b>Eve</b>") + " " + + isolatedHTML(`<"x\"onclick=\"alert(1)"@example.com>`) + if got != want { + t.Fatalf("formatQuoteMailboxHTML:\n got %q\nwant %q", got, want) + } +} + +func TestQuoteMailboxLinkResolvesToTheSameMailbox(t *testing.T) { + for _, from := range []string{ + "first.last+tag@example.com", + "user?bcc=copy@example.com", + "support#us@example.com", + "100%@example.com", + "jΓΆrg@example.com", + `Alice <"not@me"@example.org>`, + `<"a,b"@example.com>`, + `<"john smith"@example.com>`, + `<"oh\\no"@example.org>`, + } { + t.Run(from, func(t *testing.T) { + want, err := mail.ParseAddress(from) + if err != nil { + t.Fatal(err) + } + _, addrSpec, ok := parseQuoteMailbox(from) + if !ok { + t.Fatalf("parseQuoteMailbox(%q) failed", from) + } + href := mailtoURI(addrSpec) + u, err := url.Parse(href) + if err != nil { + t.Fatalf("url.Parse(%q): %v", href, err) + } + if u.Scheme != "mailto" || u.RawQuery != "" || u.Fragment != "" || strings.Contains(u.Opaque, ",") { + t.Fatalf("%q: link carries more than the mailbox (query, fragment, or second address): %+v", href, u) + } + target, err := url.PathUnescape(u.Opaque) + if err != nil { + t.Fatalf("%q: %v", href, err) + } + got, err := mail.ParseAddress(target) + if err != nil || got.Address != want.Address { + t.Fatalf("%q targets %q (%v), want mailbox %q", href, target, err, want.Address) + } + }) + } + for _, tc := range []struct{ in, want string }{ + // Ordinary addresses, including plus-addressed ones, keep a readable href. + {"first.last+tag@example.com", "mailto:first.last+tag@example.com"}, + // The first two examples in RFC 6068 section 6.2. + {`"not@me"@example.org`, "mailto:%22not%40me%22@example.org"}, + {`"oh\\no"@example.org`, "mailto:%22oh%5C%5Cno%22@example.org"}, + } { + if got := mailtoURI(tc.in); got != tc.want { + t.Fatalf("mailtoURI(%q) = %q, want %q", tc.in, got, tc.want) + } + } +} diff --git a/internal/cmd/gmail_quote_markup.go b/internal/cmd/gmail_quote_markup.go new file mode 100644 index 000000000..557a7ec1e --- /dev/null +++ b/internal/cmd/gmail_quote_markup.go @@ -0,0 +1,35 @@ +package cmd + +import "html" + +// Markup for the lines that introduce a quote: a reply's attribution and a +// forward's header block. + +// gmailQuoteOpen opens a quote as Gmail Web does: the outer div with Gmail's +// quote classes, then the div that holds the line introducing the quote, a +// reply's attribution or a forward's header block. Callers close both. gog +// writes that line in English, so it is marked left-to-right; otherwise, +// inside right-to-left text such as a Hebrew reply quoting this message, its +// words and punctuation would reorder. +const gmailQuoteOpen = `
` + +// isolateDirection wraps HTML taken from the original message, such as a +// linked address, in a span with dir="auto". The span gives the text the +// direction of its first strong character and isolates it from the line +// around it, so a right-to-left name can't pull a neighboring address or +// punctuation into its own order (next to a Hebrew name, +// "<0501234567@example.com>" renders as "0501234567> NAME@example.com>"). +// Empty text stays empty, so formatQuoteAttribution still sees a missing +// sender or date. +func isolateDirection(htmlText string) string { + if htmlText == "" { + return "" + } + return `` + htmlText + "" +} + +// isolateTextDirection escapes text taken from the original message, such as +// a name, a subject or a date, for HTML and wraps it as isolateDirection does. +func isolateTextDirection(text string) string { + return isolateDirection(html.EscapeString(text)) +} diff --git a/internal/cmd/gmail_quote_markup_test.go b/internal/cmd/gmail_quote_markup_test.go new file mode 100644 index 000000000..5579d3e9e --- /dev/null +++ b/internal/cmd/gmail_quote_markup_test.go @@ -0,0 +1,81 @@ +package cmd + +import ( + "strings" + "testing" + "time" +) + +// TestQuoteLinesKeepTheirDirection pins the exact direction markup of a +// reply's quote and a forward's header block around a Hebrew sender whose +// address starts with digits (see gmailQuoteOpen and isolateDirection). The +// quoted message passes through untouched, and the text/plain lines carry no +// direction marks. +func TestQuoteLinesKeepTheirDirection(t *testing.T) { + const ( + sender = "Χ™Χ©Χ¨ΧΧœ Χ™Χ©Χ¨ΧΧœΧ™ <0501234567@example.com>" + date = "Tue, 20 Oct 2026 12:30:00 -0700" + quoted = `
Earlier reply
On … wrote:
Original
` + open = `
` + name = `Χ™Χ©Χ¨ΧΧœ Χ™Χ©Χ¨ΧΧœΧ™` + address = `<0501234567@example.com>` + dateHTML = `Tue, Oct 20, 2026 at 12:30` + "\u202f" + `PM` + ) + la, err := time.LoadLocation("America/Los_Angeles") + if err != nil { + t.Fatal(err) + } + + t.Run("reply", func(t *testing.T) { + html := formatQuotedMessageHTMLWithContent(sender, date, quoted, la) + want := open + "On " + dateHTML + " " + name + " " + address + ` wrote:
` + quoted + `
` + if html != want { + t.Errorf("reply quote:\n got %q\nwant %q", html, want) + } + plain := formatQuotedMessage(sender, date, "Original", la) + if want := "On Tue, Oct 20, 2026 at 12:30\u202fPM Χ™Χ©Χ¨ΧΧœ Χ™Χ©Χ¨ΧΧœΧ™ <0501234567@example.com> wrote:"; !strings.Contains(plain, "\n"+want+"\n") { + t.Errorf("plain attribution:\n got %q\nwant line %q", plain, want) + } + }) + + t.Run("forward", func(t *testing.T) { + headers := forwardedMessageHeaders(sender, date, "Χ©ΧœΧ•Χ!", "Χ“Χ Χ” Χ›Χ”ΧŸ <42@example.com>, Bob ", "", la) + html := formatForwardedMessageHTML("", composeSignature{}, headers, quoted) + want := open + forwardedSeparator + "
" + + `From: Χ™Χ©Χ¨ΧΧœ Χ™Χ©Χ¨ΧΧœΧ™ ` + address + "
" + + "Date: " + dateHTML + "
" + + `Subject: Χ©ΧœΧ•Χ!
` + + `To: Χ“Χ Χ” Χ›Χ”ΧŸ <42@example.com>, ` + + `Bob <bob@example.com>
` + + "


" + quoted + "
" + if html != want { + t.Errorf("forward block:\n got %q\nwant %q", html, want) + } + plain := formatForwardedMessage("", composeSignature{}, headers, "Original") + for _, line := range []string{"From: Χ™Χ©Χ¨ΧΧœ Χ™Χ©Χ¨ΧΧœΧ™ <0501234567@example.com>", "Subject: Χ©ΧœΧ•Χ!", "To: Χ“Χ Χ” Χ›Χ”ΧŸ <42@example.com>, Bob "} { + if !strings.Contains(plain, "\n"+line+"\n") { + t.Errorf("text/plain has no line %q:\n%s", line, plain) + } + } + }) +} + +// The helpers below build expected HTML for a reply's attribution line or a +// forward's header block, independently of the code under test; +// TestQuoteLinesKeepTheirDirection pins the same markup literally. Their +// arguments are already escaped. + +// isolatedHTML is text from the original (a name, a date, a subject, a value +// that doesn't parse) keeping its own direction. +func isolatedHTML(text string) string { return `` + text + "" } + +// forwardSenderNameHTML is a forwarded message's sender name, in bold. +func forwardSenderNameHTML(name string) string { + return `` + name + "" +} + +// quoteAddressHTML is an address linked in brackets. It links the address as +// is, so it suits only addresses with nothing to percent-encode. +func quoteAddressHTML(address string) string { + return isolatedHTML(`<` + address + ">") +} diff --git a/internal/cmd/gmail_reply.go b/internal/cmd/gmail_reply.go index 515b0a3b7..ed4632ea2 100644 --- a/internal/cmd/gmail_reply.go +++ b/internal/cmd/gmail_reply.go @@ -3,7 +3,6 @@ package cmd import ( "context" "fmt" - "html" "net/mail" "strings" "time" @@ -14,10 +13,11 @@ import ( "github.com/openclaw/gogcli/internal/mailmime" ) -// buildReplyAllRecipients constructs To and Cc lists for a reply-all. +// buildReplyAllRecipients constructs To and Cc lists for a reply-all, +// leaving out every one of selfEmails. // Per RFC 5322: if Reply-To header is present, use it instead of From. -func buildReplyAllRecipients(info *replyInfo, selfEmail string) (to, cc []string) { - recipients, err := buildReplyRecipients(info, []string{selfEmail}, true, nil, nil, nil, nil) +func buildReplyAllRecipients(info *replyInfo, selfEmails ...string) (to, cc []string) { + recipients, err := buildReplyRecipients(info, selfEmails, true, nil, nil, nil, nil) if err != nil { return nil, nil } @@ -293,29 +293,20 @@ func deduplicateAddresses(addresses []string) []string { return result } -func escapeTextToHTML(value string) string { - value = html.EscapeString(value) - return strings.ReplaceAll(value, "\n", "
\n") -} - func applyQuoteToBodies(plainBody string, htmlBody string, quote bool, info *replyInfo, loc *time.Location) (string, string) { if !quote || !info.hasQuotableText() { return plainBody, htmlBody } - userPlain := plainBody - hasHTMLReply := strings.TrimSpace(htmlBody) != "" - if strings.TrimSpace(userPlain) == "" && hasHTMLReply { - userPlain = htmlToPlainText(htmlBody) - } + reply := composeText{plain: plainBody, html: htmlBody} quotedPlain := info.Body if strings.TrimSpace(quotedPlain) == "" && strings.TrimSpace(info.BodyHTML) != "" { quotedPlain = htmlToPlainText(info.BodyHTML) } - outPlain := userPlain - if quotedPlain != "" && (!hasHTMLReply || strings.TrimSpace(userPlain) != "") { + outPlain := reply.plainVersion() + if quotedPlain != "" && !reply.htmlOnlyWithoutText() { outPlain += formatQuotedMessage(info.FromAddr, info.Date, quotedPlain, loc) } @@ -329,14 +320,8 @@ func applyQuoteToBodies(plainBody string, htmlBody string, quote bool, info *rep quoteHTML := formatQuotedMessageHTMLWithContent(info.FromAddr, info.Date, quoteContent, loc) - outHTML := htmlBody - if strings.TrimSpace(outHTML) == "" { - outHTML = escapeTextToHTML(strings.TrimSpace(userPlain)) + quoteHTML - } else { - outHTML += quoteHTML - } - - return outPlain, outHTML + replyHTML := reply.htmlVersion() + return outPlain, replyHTML + breakAfter(replyHTML) + quoteHTML } // formatQuotedMessage formats the original message as a quoted reply. @@ -347,7 +332,7 @@ func formatQuotedMessage(from, date, body string, loc *time.Location) string { var sb strings.Builder sb.WriteString("\n\n") - sb.WriteString(formatQuoteAttribution(formatQuoteDate(date, loc), formatQuoteSender(from))) + sb.WriteString(formatQuoteAttribution(formatQuoteDate(date, loc), formatQuoteMailbox(from))) sb.WriteString("\n") lines := strings.Split(body, "\n") @@ -360,18 +345,23 @@ func formatQuotedMessage(from, date, body string, loc *time.Location) string { return sb.String() } +// formatQuotedMessageHTMLWithContent renders a reply's HTML quote: the +// attribution line, then htmlContent unchanged inside Gmail's blockquote. +// Gmail Web keeps one gmail_quote_container per message, its outermost, and +// removes the class from a message it quotes; a nested one renders the same, +// so the original's markup is left as it came. func formatQuotedMessageHTMLWithContent(from, date, htmlContent string, loc *time.Location) string { - attribution := formatQuoteAttribution(html.EscapeString(formatQuoteDate(date, loc)), formatQuoteSenderHTML(from)) - return fmt.Sprintf(`

%s
%s
`, - attribution, - htmlContent) + attribution := formatQuoteAttribution(isolateTextDirection(formatQuoteDate(date, loc)), formatQuoteMailboxHTML(from, plainName)) + return gmailQuoteOpen + attribution + "" + + `
` + + htmlContent + "
" } // formatQuoteAttribution renders the line that introduces a quoted reply. With // both a date and a sender it is Gmail Web's "On " + date + " " + sender + // " wrote:"; without a date it falls back to sender + " wrote:", and without a // sender to "Original message:". date and sender arrive already rendered (and -// escaped, for HTML). +// escaped and direction-isolated, for HTML), with a missing value empty. func formatQuoteAttribution(date, sender string) string { switch { case date != "" && sender != "": @@ -382,80 +372,3 @@ func formatQuoteAttribution(date, sender string) string { return "Original message:" } } - -// parseQuoteSender splits a From header into its display name and address. -// ok is false when the value is not a single parseable mailbox. -func parseQuoteSender(from string) (name, address string, ok bool) { - addr, err := mail.ParseAddress(strings.TrimSpace(from)) - if err != nil { - return "", "", false - } - // ParseAddress unquotes a quoted local part ("john smith"@example.com). A - // nameless Address's String is "" with the local part re-quoted - // where needed, so trimming the brackets leaves a valid addr-spec. - address = strings.TrimSuffix(strings.TrimPrefix((&mail.Address{Address: addr.Address}).String(), "<"), ">") - return strings.TrimSpace(addr.Name), address, true -} - -// formatQuoteSender renders a From header the way Gmail shows a sender in a -// quote attribution: "Name " with a display name, "" without -// one. A value that is not a single parseable mailbox is returned trimmed and -// otherwise unchanged. -func formatQuoteSender(from string) string { - name, address, ok := parseQuoteSender(from) - if !ok { - return strings.TrimSpace(from) - } - if name == "" { - return "<" + address + ">" - } - return name + " <" + address + ">" -} - -// formatQuoteSenderHTML is formatQuoteSender for HTML: the same text, escaped, -// with a parsed address linked via mailto:. A value that does not parse is -// escaped but not linked. -func formatQuoteSenderHTML(from string) string { - name, address, ok := parseQuoteSender(from) - if !ok { - return html.EscapeString(strings.TrimSpace(from)) - } - link := `<` + html.EscapeString(address) + `>` - if name == "" { - return link - } - return html.EscapeString(name) + " " + link -} - -// mailtoURI returns a mailto: URI for an addr-spec (RFC 6068). Both sides of -// the final "@" are percent-encoded except for unreserved characters and "+". -// Otherwise characters that are valid in a mailbox would change the link: "?" -// would start header fields, "#" a fragment that cuts the address short, and -// "," or a quoted "@" would split it. "+" stays raw so plus-addressed hrefs -// remain readable. -func mailtoURI(addrSpec string) string { - at := strings.LastIndexByte(addrSpec, '@') - if at < 0 { - // A parsed addr-spec always has an "@"; escape anything else whole - // rather than slicing at -1. - return "mailto:" + mailtoEscape(addrSpec) - } - return "mailto:" + mailtoEscape(addrSpec[:at]) + "@" + mailtoEscape(addrSpec[at+1:]) -} - -func mailtoEscape(s string) string { - const hexDigits = "0123456789ABCDEF" - var b strings.Builder - for i := 0; i < len(s); i++ { - c := s[i] - switch { - case 'a' <= c && c <= 'z', 'A' <= c && c <= 'Z', '0' <= c && c <= '9', strings.IndexByte("-._~+", c) >= 0: - b.WriteByte(c) - default: - b.WriteByte('%') - b.WriteByte(hexDigits[c>>4]) - b.WriteByte(hexDigits[c&0x0f]) - } - } - return b.String() -} diff --git a/internal/cmd/gmail_reply_commands.go b/internal/cmd/gmail_reply_commands.go index ec223bb31..0eff39081 100644 --- a/internal/cmd/gmail_reply_commands.go +++ b/internal/cmd/gmail_reply_commands.go @@ -37,6 +37,7 @@ type GmailReplyOptions struct { From string `name:"from" help:"Send from this email address (must be a verified send-as alias)"` AutoFromAddressedAlias bool `name:"auto-from-addressed-alias" help:"When --from is omitted, reply from the verified send-as alias addressed by the original message" env:"GOG_GMAIL_AUTO_FROM_ADDRESSED_ALIAS"` composeSignatureOptions `embed:""` + composeTextHTMLOptions `embed:""` } func (c *GmailReplyCmd) Run(ctx context.Context, flags *RootFlags) error { @@ -146,6 +147,7 @@ func (c *GmailReplyOptions) resolveReplyInputs(ctx context.Context, messageID st if err != nil { return replyComposeInputs{}, err } + htmlBody = c.withTextHTML(body, htmlBody) if strings.TrimSpace(body) == "" && strings.TrimSpace(htmlBody) == "" { return replyComposeInputs{}, usage("required: --body, --body-file, --body-html, or --body-html-file") } @@ -184,7 +186,7 @@ func (c *GmailReplyOptions) resolveReplyInputs(ctx context.Context, messageID st // builds the reply recipients and body, and returns the message without sending // so the caller controls how it is dispatched. func (c *GmailReplyOptions) buildReplyComposeMessage(ctx context.Context, svc *gmail.Service, account string, inputs replyComposeInputs, replyAll bool) (replyComposeMessage, error) { - body, htmlBody := inputs.body, inputs.htmlBody + body, htmlBody := inputs.body, directedHTML(inputs.htmlBody) sendAs, sendAsErr := listSendAs(ctx, svc) from, err := resolveComposeFrom(ctx, svc, account, c.From, sendAs, sendAsErr) diff --git a/internal/cmd/gmail_search.go b/internal/cmd/gmail_search.go index d59166d57..84b4719ed 100644 --- a/internal/cmd/gmail_search.go +++ b/internal/cmd/gmail_search.go @@ -20,6 +20,7 @@ type GmailSearchCmd struct { All bool `name:"all" aliases:"all-pages,allpages" help:"Fetch all pages"` FailEmpty bool `name:"fail-empty" aliases:"non-empty,require-results" help:"Exit with code 3 if no results"` Count bool `name:"count" help:"Report the whole-query count as totalMatches (exact) or totalMatchesAtLeast (lower bound); free with --all unless --page is set; unavailable with --results-only"` + IDsOnly bool `name:"ids-only" help:"Return only thread IDs from the list call, skipping the label lookup and per-thread fetch (use --max 500 for the largest pages)"` Oldest bool `name:"oldest" help:"Show first message date instead of last"` Timezone string `name:"timezone" short:"z" help:"Output timezone (IANA name, e.g. America/New_York, UTC). Default: GOG_TIMEZONE, config, then local"` Local bool `name:"local" help:"Use local timezone (default behavior, useful to override --timezone)"` @@ -27,6 +28,9 @@ type GmailSearchCmd struct { func (c *GmailSearchCmd) Run(ctx context.Context, flags *RootFlags) error { u := ui.FromContext(ctx) + if c.IDsOnly && c.Oldest { + return usage("--ids-only cannot be used with --oldest") + } if err := validateGmailMaxResults(c.Max); err != nil { return err } @@ -96,19 +100,14 @@ func (c *GmailSearchCmd) Run(ctx context.Context, flags *RootFlags) error { return failEmptyExit(c.FailEmpty) } - idToName, err := fetchLabelIDToName(svc) - if err != nil { - return err - } - - loc, err := resolveOutputLocation(ctx, c.Timezone, c.Local, stderrWriter(ctx)) - if err != nil { - return err - } - - items, err := fetchThreadDetails(ctx, svc, threads, idToName, c.Oldest, loc) - if err != nil { - return err + var items []threadItem + if c.IDsOnly { + items = threadIDItems(threads) + } else { + items, err = c.fetchDetails(ctx, svc, threads) + if err != nil { + return err + } } if outfmt.IsJSON(ctx) { @@ -127,7 +126,11 @@ func (c *GmailSearchCmd) Run(ctx context.Context, flags *RootFlags) error { return failEmptyExit(c.FailEmpty) } - if err := outfmt.WriteTable(ctx, stdoutWriter(ctx), items, gmailThreadColumns()); err != nil { + columns := gmailThreadColumns() + if c.IDsOnly { + columns = gmailThreadIDColumns() + } + if err := outfmt.WriteTable(ctx, stdoutWriter(ctx), items, columns); err != nil { return err } // stderr, so the table on stdout stays parseable. @@ -138,6 +141,29 @@ func (c *GmailSearchCmd) Run(ctx context.Context, flags *RootFlags) error { return nil } +func (c *GmailSearchCmd) fetchDetails(ctx context.Context, svc *gmail.Service, threads []*gmail.Thread) ([]threadItem, error) { + idToName, err := fetchLabelIDToName(svc) + if err != nil { + return nil, err + } + loc, err := resolveOutputLocation(ctx, c.Timezone, c.Local, stderrWriter(ctx)) + if err != nil { + return nil, err + } + return fetchThreadDetails(ctx, svc, threads, idToName, c.Oldest, loc) +} + +func threadIDItems(threads []*gmail.Thread) []threadItem { + items := make([]threadItem, 0, len(threads)) + for _, t := range threads { + if t == nil || t.Id == "" { + continue + } + items = append(items, threadItem{ID: t.Id}) + } + return items +} + func gmailFromContactQuery(ctx context.Context, account, selector string) (string, error) { selector = strings.TrimSpace(selector) if selector == "" { diff --git a/internal/cmd/gmail_search_ids_only_test.go b/internal/cmd/gmail_search_ids_only_test.go new file mode 100644 index 000000000..01fe662e2 --- /dev/null +++ b/internal/cmd/gmail_search_ids_only_test.go @@ -0,0 +1,145 @@ +package cmd + +import ( + "encoding/json" + "net/http" + "net/http/httptest" + "strings" + "sync" + "testing" +) + +// idsOnlyGmailServer serves list pages of two items each and records every +// other request, which --ids-only must never make. +func idsOnlyGmailServer(t *testing.T, resource string) (*httptest.Server, func() []string) { + t.Helper() + + var mu sync.Mutex + var unexpected []string + listPath := "/users/me/" + resource + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if !strings.HasSuffix(r.URL.Path, listPath) { + mu.Lock() + unexpected = append(unexpected, r.URL.Path) + mu.Unlock() + http.NotFound(w, r) + return + } + page := map[string]any{ + resource: []map[string]any{{"id": "a1", "threadId": "t1"}, {"id": "a2", "threadId": "t2"}}, + "nextPageToken": "p2", + } + if r.URL.Query().Get("pageToken") == "p2" { + page = map[string]any{resource: []map[string]any{{"id": "a3", "threadId": "t3"}}} + } + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(page) + })) + t.Cleanup(srv.Close) + + return srv, func() []string { + mu.Lock() + defer mu.Unlock() + return append([]string(nil), unexpected...) + } +} + +func TestExecute_GmailMessagesSearch_IDsOnlySkipsMessageFetches(t *testing.T) { + srv, unexpected := idsOnlyGmailServer(t, "messages") + + result := executeWithGmailTestService( + t, + []string{"--json", "--account", "a@b.com", "gmail", "messages", "search", "list:example.com", "--all", "--ids-only"}, + newGmailServiceFromServer(t, srv), + ) + if result.err != nil { + t.Fatalf("Execute: %v\nstderr=%q", result.err, result.stderr) + } + if got := unexpected(); len(got) > 0 { + t.Fatalf("--ids-only made non-list requests: %v", got) + } + + var payload struct { + Messages []messageItem `json:"messages"` + } + if err := json.Unmarshal([]byte(result.stdout), &payload); err != nil { + t.Fatalf("decode stdout %q: %v", result.stdout, err) + } + want := []messageItem{{ID: "a1", ThreadID: "t1"}, {ID: "a2", ThreadID: "t2"}, {ID: "a3", ThreadID: "t3"}} + if len(payload.Messages) != len(want) { + t.Fatalf("messages = %+v, want %+v", payload.Messages, want) + } + for i := range want { + if payload.Messages[i].ID != want[i].ID || payload.Messages[i].ThreadID != want[i].ThreadID || payload.Messages[i].From != "" { + t.Fatalf("messages = %+v, want %+v", payload.Messages, want) + } + } +} + +func TestExecute_GmailMessagesSearch_IDsOnlyPlainPrintsIDColumns(t *testing.T) { + srv, _ := idsOnlyGmailServer(t, "messages") + + result := executeWithGmailTestService( + t, + []string{"--plain", "--account", "a@b.com", "gmail", "messages", "search", "list:example.com", "--ids-only"}, + newGmailServiceFromServer(t, srv), + ) + if result.err != nil { + t.Fatalf("Execute: %v\nstderr=%q", result.err, result.stderr) + } + if want := "ID\tTHREAD\na1\tt1\na2\tt2\n"; result.stdout != want { + t.Fatalf("stdout = %q, want %q", result.stdout, want) + } +} + +func TestExecute_GmailMessagesSearch_IDsOnlyRejectsContentFlags(t *testing.T) { + for _, flag := range []string{"--include-body", "--headers=List-Id"} { + t.Run(flag, func(t *testing.T) { + result := executeWithGmailTestService( + t, + []string{"--json", "--account", "a@b.com", "gmail", "messages", "search", "list:example.com", "--ids-only", flag}, + nil, + ) + if result.err == nil || !strings.Contains(result.err.Error(), "--ids-only cannot be used with") { + t.Fatalf("expected --ids-only usage error, got %v", result.err) + } + }) + } +} + +func TestExecute_GmailSearch_IDsOnlyRejectsOldest(t *testing.T) { + result := executeWithGmailTestService( + t, + []string{"--json", "--account", "a@b.com", "gmail", "search", "list:example.com", "--ids-only", "--oldest"}, + nil, + ) + if result.err == nil || !strings.Contains(result.err.Error(), "--ids-only cannot be used with --oldest") { + t.Fatalf("expected --ids-only usage error, got %v", result.err) + } +} + +func TestExecute_GmailSearch_IDsOnlySkipsThreadFetches(t *testing.T) { + srv, unexpected := idsOnlyGmailServer(t, "threads") + + result := executeWithGmailTestService( + t, + []string{"--json", "--account", "a@b.com", "gmail", "search", "list:example.com", "--all", "--ids-only"}, + newGmailServiceFromServer(t, srv), + ) + if result.err != nil { + t.Fatalf("Execute: %v\nstderr=%q", result.err, result.stderr) + } + if got := unexpected(); len(got) > 0 { + t.Fatalf("--ids-only made non-list requests: %v", got) + } + + var payload struct { + Threads []threadItem `json:"threads"` + } + if err := json.Unmarshal([]byte(result.stdout), &payload); err != nil { + t.Fatalf("decode stdout %q: %v", result.stdout, err) + } + if len(payload.Threads) != 3 || payload.Threads[0].ID != "a1" || payload.Threads[2].ID != "a3" { + t.Fatalf("threads = %+v, want a1, a2, a3", payload.Threads) + } +} diff --git a/internal/cmd/gmail_search_labels.go b/internal/cmd/gmail_search_labels.go index 93ff65d0d..f13221c86 100644 --- a/internal/cmd/gmail_search_labels.go +++ b/internal/cmd/gmail_search_labels.go @@ -96,7 +96,9 @@ func gmailQuerySystemLabelIDs(query string) []string { // NOT(in:inbox): the operand is complete in this field. } } else { - token := strings.ToLower(strings.Trim(field.text, gmailQueryBracketChars)) + // Quoted spans are already gone from unquoted. Trimming quotes off + // the raw field turned `"is:unread"` into the label UNREAD. + token := strings.ToLower(strings.Trim(field.unquoted, gmailQueryBracketChars)) negated := negateNext || negatedDepth >= 0 || strings.HasPrefix(token, "-") negateNext = false if negated && negatedDepth < 0 && opens > closes { diff --git a/internal/cmd/gmail_search_labels_test.go b/internal/cmd/gmail_search_labels_test.go index abd7a974d..0c857b059 100644 --- a/internal/cmd/gmail_search_labels_test.go +++ b/internal/cmd/gmail_search_labels_test.go @@ -29,6 +29,10 @@ func TestGmailQuerySystemLabelIDs(t *testing.T) { {name: "quoted phrase containing OR and a pipe", query: `subject:"a OR b | c" in:inbox`, want: []string{"INBOX"}}, {name: "quoted phrase with brackets", query: `subject:"(draft" in:inbox`, want: []string{"INBOX"}}, {name: "quoted negation phrase", query: `"not in:inbox" is:unread`, want: []string{"UNREAD"}}, + {name: "quoted operator alone", query: `"is:unread"`, want: nil}, + {name: "quoted operator before a real label", query: `"in:spam" is:unread`, want: []string{"UNREAD"}}, + {name: "quoted operator inside brackets", query: `("is:unread")`, want: nil}, + {name: "real label before a quoted operator", query: `in:spam "is:unread"`, want: []string{"SPAM"}}, {name: "word starting with not", query: "nothing in:inbox", want: []string{"INBOX"}}, {name: "unterminated quote", query: `subject:"oops in:inbox`, want: nil}, {name: "negated group", query: "-(zzqx in:inbox) in:sent", want: []string{"SENT"}}, diff --git a/internal/cmd/gmail_send.go b/internal/cmd/gmail_send.go index 78681b3ab..b2637eb2b 100644 --- a/internal/cmd/gmail_send.go +++ b/internal/cmd/gmail_send.go @@ -34,6 +34,7 @@ type GmailSendCmd struct { Attach []string `name:"attach" help:"Attachment file path (repeatable)"` From string `name:"from" help:"Send from this email address (must be a verified send-as alias)"` composeSignatureOptions `embed:""` + composeTextHTMLOptions `embed:""` Track bool `name:"track" help:"Enable open tracking (requires tracking setup)"` TrackSplit bool `name:"track-split" help:"Send tracked messages separately per recipient"` Quote bool `name:"quote" help:"Include quoted original message in reply (requires --reply-to-message-id or --thread-id)"` @@ -75,6 +76,8 @@ type sendMessageOptions struct { Attachments []mailmime.Attachment Track bool TrackingCfg *tracking.Config + // AllowMissingTo lets a message go out with only Cc or Bcc recipients. + AllowMissingTo bool } func (c *GmailSendCmd) Run(ctx context.Context, flags *RootFlags) error { @@ -91,6 +94,7 @@ func (c *GmailSendCmd) Run(ctx context.Context, flags *RootFlags) error { if err != nil { return err } + htmlBodyInput = c.withTextHTML(body, htmlBodyInput) if replyToMessageID != "" && threadID != "" { return usage("use only one of --reply-to-message-id or --thread-id") @@ -171,7 +175,8 @@ func (c *GmailSendCmd) Run(ctx context.Context, flags *RootFlags) error { return err } - from, err := resolveComposeSender(ctx, svc, account, c.From) + sendAs, sendAsErr := listSendAs(ctx, svc) + from, err := resolveComposeFrom(ctx, svc, account, c.From, sendAs, sendAsErr) if err != nil { return err } @@ -179,7 +184,7 @@ func (c *GmailSendCmd) Run(ctx context.Context, flags *RootFlags) error { if err != nil { return err } - body, htmlBodyInput = appendComposeSignature(body, htmlBodyInput, signature) + body, htmlBodyInput = appendComposeSignature(body, directedHTML(htmlBodyInput), signature) replyInfo, body, htmlBody, err := prepareComposeReply(ctx, svc, replyToMessageID, threadID, c.Quote, body, htmlBodyInput) if err != nil { return err @@ -192,7 +197,8 @@ func (c *GmailSendCmd) Run(ctx context.Context, flags *RootFlags) error { var toRecipients, ccRecipients []string if c.ReplyAll { // Auto-populate recipients from original message - toRecipients, ccRecipients = buildReplyAllRecipients(replyInfo, from.sendingEmail) + // Leave out the account and every send-as alias, as gmail reply-all does. + toRecipients, ccRecipients = buildReplyAllRecipients(replyInfo, selfEmailsForReply(account, from.sendingEmail, sendAs)...) } // Explicit --to and --cc override (not merge with) auto-populated @@ -207,8 +213,11 @@ func (c *GmailSendCmd) Run(ctx context.Context, flags *RootFlags) error { ccRecipients = explicitCc } - // Final validation: we must have at least one recipient - if len(toRecipients) == 0 { + // Final validation: we must have at least one recipient. A reply-all may + // leave only Cc recipients once the user's own addresses are dropped, which + // gmail reply-all also sends. + allowMissingTo := c.ReplyAll && strings.TrimSpace(c.To) == "" && len(ccRecipients)+len(explicitBcc) > 0 + if len(toRecipients) == 0 && !allowMissingTo { return usage("no recipients: specify --to or use --reply-all with a message that has recipients") } @@ -237,6 +246,8 @@ func (c *GmailSendCmd) Run(ctx context.Context, flags *RootFlags) error { Attachments: atts, Track: c.Track, TrackingCfg: trackingCfg, + + AllowMissingTo: allowMissingTo, }, batches) if err != nil { return err @@ -293,6 +304,7 @@ func (c *GmailSendCmd) rawModeConflict() string { {strings.TrimSpace(c.BodyFile) != "", "--body-file"}, {c.BodyHTML != "", "--body-html"}, {strings.TrimSpace(c.BodyHTMLFile) != "", "--body-html-file"}, + {c.HTMLFromText, "--html-from-text"}, {strings.TrimSpace(c.ReplyToMessageID) != "", "--reply-to-message-id"}, {c.ReplyAll, "--reply-all"}, {strings.TrimSpace(c.ReplyTo) != "", "--reply-to"}, @@ -439,7 +451,7 @@ func sendGmailBatches(ctx context.Context, svc *gmail.Service, opts sendMessageO messageOpts := opts messageOpts.BodyHTML = htmlBody - msg, err := buildGmailMessage(ctx, messageOpts, batch, false) + msg, err := buildGmailMessage(ctx, messageOpts, batch, opts.AllowMissingTo) if err != nil { return nil, err } diff --git a/internal/cmd/gmail_send_quote_test.go b/internal/cmd/gmail_send_quote_test.go index 538fdd70f..6fc119588 100644 --- a/internal/cmd/gmail_send_quote_test.go +++ b/internal/cmd/gmail_send_quote_test.go @@ -2,8 +2,6 @@ package cmd import ( "encoding/base64" - "net/mail" - "net/url" "strings" "testing" "time" @@ -43,20 +41,20 @@ func TestQuoteAttribution(t *testing.T) { from: `"Example Sender" `, date: date, wantPlain: "On Fri, Aug 14, 2026 at 4:01\u202fPM Example Sender wrote:", - wantHTML: `On Fri, Aug 14, 2026 at 4:01` + "\u202f" + `PM Example Sender <sender@example.com> wrote:`, + wantHTML: "On " + isolatedHTML("Fri, Aug 14, 2026 at 4:01\u202fPM") + " " + isolatedHTML("Example Sender") + " " + quoteAddressHTML("sender@example.com") + " wrote:", }, { name: "nameless sender", from: "sender@example.com", date: date, wantPlain: "On Fri, Aug 14, 2026 at 4:01\u202fPM wrote:", - wantHTML: `On Fri, Aug 14, 2026 at 4:01` + "\u202f" + `PM <sender@example.com> wrote:`, + wantHTML: "On " + isolatedHTML("Fri, Aug 14, 2026 at 4:01\u202fPM") + " " + quoteAddressHTML("sender@example.com") + " wrote:", }, { name: "no date", from: "Example Sender ", wantPlain: "Example Sender wrote:", - wantHTML: `Example Sender <sender@example.com> wrote:`, + wantHTML: isolatedHTML("Example Sender") + " " + quoteAddressHTML("sender@example.com") + " wrote:", }, { name: "no sender", @@ -64,19 +62,34 @@ func TestQuoteAttribution(t *testing.T) { wantPlain: "Original message:", wantHTML: "Original message:", }, + { + name: "blank sender", + from: " ", + date: date, + wantPlain: "Original message:", + wantHTML: "Original message:", + }, { name: "quoted local part keeps its quotes", from: `Alice <"john smith"@example.com>`, date: date, wantPlain: "On Fri, Aug 14, 2026 at 4:01\u202fPM Alice <\"john smith\"@example.com> wrote:", - wantHTML: `On Fri, Aug 14, 2026 at 4:01` + "\u202f" + `PM Alice <"john smith"@example.com> wrote:`, + wantHTML: "On " + isolatedHTML("Fri, Aug 14, 2026 at 4:01\u202fPM") + " " + isolatedHTML("Alice") + " " + + isolatedHTML(`<"john smith"@example.com>`) + " wrote:", }, { name: "unparseable sender shown as is, unlinked", from: "Example Sender, Team ", date: date, wantPlain: "On Fri, Aug 14, 2026 at 4:01\u202fPM Example Sender, Team wrote:", - wantHTML: `On Fri, Aug 14, 2026 at 4:01` + "\u202f" + `PM Example Sender, Team <sender@example.com> wrote:`, + wantHTML: "On " + isolatedHTML("Fri, Aug 14, 2026 at 4:01\u202fPM") + " " + isolatedHTML("Example Sender, Team <sender@example.com>") + " wrote:", + }, + { + name: "markup in an unparseable sender and date is escaped", + from: `">`, + date: "bad", + wantPlain: `On bad "> wrote:`, + wantHTML: "On " + isolatedHTML("<b>bad</b>") + " " + isolatedHTML(""><script>alert(1)</script>") + " wrote:", }, } for _, tc := range cases { @@ -85,73 +98,13 @@ func TestQuoteAttribution(t *testing.T) { if got := formatQuotedMessage(tc.from, tc.date, "body", la); !strings.Contains(got, "\n"+tc.wantPlain+"\n") { t.Errorf("plain attribution:\n got %q\nwant line %q", got, tc.wantPlain) } - if got := formatQuotedMessageHTMLWithContent(tc.from, tc.date, "

body

", la); !strings.Contains(got, `
`+tc.wantHTML+`
`) { + if got := formatQuotedMessageHTMLWithContent(tc.from, tc.date, "

body

", la); !strings.Contains(got, gmailQuoteOpen+tc.wantHTML+"") { t.Errorf("HTML attribution:\n got %q\nwant line %q", got, tc.wantHTML) } }) } } -func TestFormatQuoteSenderHTMLEscapesNameAndAddress(t *testing.T) { - got := formatQuoteSenderHTML(`"Eve" <"x\"onclick=\"alert(1)"@example.com>`) - want := `<b>Eve</b> <"x\"onclick=\"alert(1)"@example.com>` - if got != want { - t.Fatalf("formatQuoteSenderHTML:\n got %q\nwant %q", got, want) - } -} - -func TestQuoteSenderLinkResolvesToTheSameMailbox(t *testing.T) { - for _, from := range []string{ - "first.last+tag@example.com", - "user?bcc=copy@example.com", - "support#us@example.com", - "100%@example.com", - "jΓΆrg@example.com", - `Alice <"not@me"@example.org>`, - `<"a,b"@example.com>`, - `<"john smith"@example.com>`, - `<"oh\\no"@example.org>`, - } { - t.Run(from, func(t *testing.T) { - want, err := mail.ParseAddress(from) - if err != nil { - t.Fatal(err) - } - _, addrSpec, ok := parseQuoteSender(from) - if !ok { - t.Fatalf("parseQuoteSender(%q) failed", from) - } - href := mailtoURI(addrSpec) - u, err := url.Parse(href) - if err != nil { - t.Fatalf("url.Parse(%q): %v", href, err) - } - if u.Scheme != "mailto" || u.RawQuery != "" || u.Fragment != "" || strings.Contains(u.Opaque, ",") { - t.Fatalf("%q: link carries more than the mailbox (query, fragment, or second address): %+v", href, u) - } - target, err := url.PathUnescape(u.Opaque) - if err != nil { - t.Fatalf("%q: %v", href, err) - } - got, err := mail.ParseAddress(target) - if err != nil || got.Address != want.Address { - t.Fatalf("%q targets %q (%v), want mailbox %q", href, target, err, want.Address) - } - }) - } - for _, tc := range []struct{ in, want string }{ - // Ordinary addresses, including plus-addressed ones, keep a readable href. - {"first.last+tag@example.com", "mailto:first.last+tag@example.com"}, - // The first two examples in RFC 6068 section 6.2. - {`"not@me"@example.org`, "mailto:%22not%40me%22@example.org"}, - {`"oh\\no"@example.org`, "mailto:%22oh%5C%5Cno%22@example.org"}, - } { - if got := mailtoURI(tc.in); got != tc.want { - t.Fatalf("mailtoURI(%q) = %q, want %q", tc.in, got, tc.want) - } - } -} - func TestFormatQuoteDate(t *testing.T) { cases := []struct { name string @@ -178,27 +131,6 @@ func TestFormatQuoteDate(t *testing.T) { } } -func TestFormatQuotedMessageHTMLWithContent_EscapesHeader_NotBody(t *testing.T) { - out := formatQuotedMessageHTMLWithContent(`">`, `bad`, `ok`, time.UTC) - if strings.Contains(out, "