From 50f2da6282798e58ad14c6e311a2a89e8a1b7621 Mon Sep 17 00:00:00 2001 From: Lev <3114081+ldub@users.noreply.github.com> Date: Tue, 21 Apr 2026 10:41:04 -0700 Subject: [PATCH] Add recipe-apply-filter-to-existing-emails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a recipe for applying a Gmail filter's label/archive actions to existing messages via messages.batchModify — the API equivalent of the Gmail UI's "also apply filter to matching conversations" checkbox, which has no parameter on filters.create. --- .../recipe-apply-filter-to-existing-emails.md | 5 +++ .../registry/recipes.toml | 14 +++++++++ docs/skills.md | 1 + .../SKILL.md | 31 +++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 .changeset/recipe-apply-filter-to-existing-emails.md create mode 100644 skills/recipe-apply-filter-to-existing-emails/SKILL.md diff --git a/.changeset/recipe-apply-filter-to-existing-emails.md b/.changeset/recipe-apply-filter-to-existing-emails.md new file mode 100644 index 00000000..a5b02a0f --- /dev/null +++ b/.changeset/recipe-apply-filter-to-existing-emails.md @@ -0,0 +1,5 @@ +--- +"@googleworkspace/cli": patch +--- + +Add `recipe-apply-filter-to-existing-emails` skill for applying a Gmail filter's actions to existing messages — the API equivalent of the UI's "also apply to matching conversations" checkbox. diff --git a/crates/google-workspace-cli/registry/recipes.toml b/crates/google-workspace-cli/registry/recipes.toml index 8440ca1b..f413b82f 100644 --- a/crates/google-workspace-cli/registry/recipes.toml +++ b/crates/google-workspace-cli/registry/recipes.toml @@ -494,3 +494,17 @@ steps = [ "Write the report: `gws docs +write --document-id DOC_ID --text '## Sales Report - January 2025\n\n### Summary\nTotal deals: 45\nRevenue: $125,000\n\n### Top Deals\n1. Acme Corp - $25,000\n2. Widget Inc - $18,000'`", "Share with stakeholders: `gws drive permissions create --params '{\"fileId\": \"DOC_ID\"}' --json '{\"role\": \"reader\", \"type\": \"user\", \"emailAddress\": \"cfo@company.com\"}'`" ] + +[[recipes]] +name = "apply-filter-to-existing-emails" +title = "Apply a Gmail Filter to Existing Messages" +description = "Apply a Gmail filter's actions to existing messages (API equivalent of the UI 'apply to matching conversations' box)." +category = "productivity" +services = [ "gmail" ] +steps = [ + "Read the filter's criteria and action: `gws gmail users settings filters get --params '{\"userId\": \"me\", \"id\": \"FILTER_ID\"}'`", + "List matching messages, translating the criteria to a Gmail query (e.g. `subject:\"...\"`, `from:...`): `gws gmail users messages list --params '{\"userId\": \"me\", \"q\": \"subject:\\\"invoice\\\" in:anywhere\", \"maxResults\": 500}'`", + "Apply the filter's actions in bulk: `gws gmail users messages batchModify --params '{\"userId\": \"me\"}' --json '{\"ids\": [\"MSG_ID_1\", \"MSG_ID_2\"], \"addLabelIds\": [\"LABEL_ID\"], \"removeLabelIds\": [\"INBOX\", \"UNREAD\"]}'`", + "Verify the inbox is clear of matches: `gws gmail users messages list --params '{\"userId\": \"me\", \"q\": \"subject:\\\"invoice\\\" in:inbox\"}' --format table`" +] +caution = "batchModify accepts up to 1000 ids per request — paginate list and modify for larger result sets. `forward` actions on a filter cannot be replayed against past messages." diff --git a/docs/skills.md b/docs/skills.md index 96fcae2e..e185ea88 100644 --- a/docs/skills.md +++ b/docs/skills.md @@ -124,4 +124,5 @@ Multi-step task sequences with real commands. | [recipe-batch-invite-to-event](../skills/recipe-batch-invite-to-event/SKILL.md) | Add a list of attendees to an existing Google Calendar event and send notifications. | | [recipe-forward-labeled-emails](../skills/recipe-forward-labeled-emails/SKILL.md) | Find Gmail messages with a specific label and forward them to another address. | | [recipe-generate-report-from-sheet](../skills/recipe-generate-report-from-sheet/SKILL.md) | Read data from a Google Sheet and create a formatted Google Docs report. | +| [recipe-apply-filter-to-existing-emails](../skills/recipe-apply-filter-to-existing-emails/SKILL.md) | Apply a Gmail filter's actions to existing messages (API equivalent of the UI 'apply to matching conversations' box). | diff --git a/skills/recipe-apply-filter-to-existing-emails/SKILL.md b/skills/recipe-apply-filter-to-existing-emails/SKILL.md new file mode 100644 index 00000000..d7f35e82 --- /dev/null +++ b/skills/recipe-apply-filter-to-existing-emails/SKILL.md @@ -0,0 +1,31 @@ +--- +name: recipe-apply-filter-to-existing-emails +description: "Apply a Gmail filter's actions to existing messages (API equivalent of the UI 'apply to matching conversations' box)." +metadata: + version: 0.22.5 + openclaw: + category: "recipe" + domain: "productivity" + requires: + bins: + - gws + skills: + - gws-gmail +--- + +# Apply a Gmail Filter to Existing Messages + +> **PREREQUISITE:** Load the following skills to execute this recipe: `gws-gmail` + +Apply a Gmail filter's actions to existing messages (API equivalent of the UI 'apply to matching conversations' box). + +> [!CAUTION] +> batchModify accepts up to 1000 ids per request — paginate list and modify for larger result sets. `forward` actions on a filter cannot be replayed against past messages. + +## Steps + +1. Read the filter's criteria and action: `gws gmail users settings filters get --params '{"userId": "me", "id": "FILTER_ID"}'` +2. List matching messages, translating the criteria to a Gmail query (e.g. `subject:"..."`, `from:...`): `gws gmail users messages list --params '{"userId": "me", "q": "subject:\"invoice\" in:anywhere", "maxResults": 500}'` +3. Apply the filter's actions in bulk: `gws gmail users messages batchModify --params '{"userId": "me"}' --json '{"ids": ["MSG_ID_1", "MSG_ID_2"], "addLabelIds": ["LABEL_ID"], "removeLabelIds": ["INBOX", "UNREAD"]}'` +4. Verify the inbox is clear of matches: `gws gmail users messages list --params '{"userId": "me", "q": "subject:\"invoice\" in:inbox"}' --format table` +