Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/recipe-apply-filter-to-existing-emails.md
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 14 additions & 0 deletions crates/google-workspace-cli/registry/recipes.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
1 change: 1 addition & 0 deletions docs/skills.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). |

31 changes: 31 additions & 0 deletions skills/recipe-apply-filter-to-existing-emails/SKILL.md
Original file line number Diff line number Diff line change
@@ -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`

Loading