Summary
Add an --exclude-labels flag to gog gmail watch serve to filter out messages with specific Gmail labels (e.g., SPAM, TRASH) before forwarding to the webhook.
Problem
When using watch serve for agentic workflows (like OpenClaw), spam emails trigger the webhook before Gmail's spam filter has a chance to move them to the SPAM folder. This causes the agent to process spam messages unnecessarily.
The timing issue:
- Email arrives →
messageAdded event fires → webhook triggered
- Gmail's spam filter runs (async) → message moved to SPAM
- Agent has already received and potentially acted on the spam
Proposed Solution
Add --exclude-labels flag that accepts a comma-separated list of Gmail label IDs to exclude:
gog gmail watch serve --exclude-labels SPAM,TRASH --hook-url ...
When a message is fetched, check its labelIds - if any match the exclude list, skip forwarding to the webhook.
Default behavior
Consider defaulting to --exclude-labels SPAM,TRASH for safety, with --exclude-labels="" to disable.
Use Case
This is particularly important for agentic AI workflows where:
- Emails can trigger automated actions
- Processing spam wastes resources and could be a security risk (prompt injection via spam)
- Defense-in-depth: filter at multiple layers (gog + application)
Related
Summary
Add an
--exclude-labelsflag togog gmail watch serveto filter out messages with specific Gmail labels (e.g., SPAM, TRASH) before forwarding to the webhook.Problem
When using
watch servefor agentic workflows (like OpenClaw), spam emails trigger the webhook before Gmail's spam filter has a chance to move them to the SPAM folder. This causes the agent to process spam messages unnecessarily.The timing issue:
messageAddedevent fires → webhook triggeredProposed Solution
Add
--exclude-labelsflag that accepts a comma-separated list of Gmail label IDs to exclude:When a message is fetched, check its
labelIds- if any match the exclude list, skip forwarding to the webhook.Default behavior
Consider defaulting to
--exclude-labels SPAM,TRASHfor safety, with--exclude-labels=""to disable.Use Case
This is particularly important for agentic AI workflows where:
Related
--history-typesfiltering (complementary feature)