Skip to content

feat(gmail): add --exclude-labels flag to watch serve for spam filtering #178

@niemesrw

Description

@niemesrw

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:

  1. Email arrives → messageAdded event fires → webhook triggered
  2. Gmail's spam filter runs (async) → message moved to SPAM
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions