gmail-safe-batch-ops
Use this when you need Gmail search, inbox triage, or cautious batch cleanup without jumping straight into destructive mailbox changes.
What this bundle gives you
- fast read-only Gmail search via
gog - a bundled Python helper for preview-first mailbox filtering
- guarded batch archive mode with message-count and ratio safety caps
- JSON summaries that are easy to inspect, save, or review before applying changes
Requirements
goginstalled and authenticated for Gmailpython3available- Gmail OAuth credentials already set up through
gog - in headless environments,
GOG_KEYRING_PASSWORDmust be available or stored at the defaultgogkeyring password path
Read-only first
Use plain gog when you only need quick search results.
gog gmail search 'newer_than:7d' --max 10
gog gmail messages search 'in:inbox from:[email protected]' --max 20Use the bundled helper when you need stricter local filters, previews, exportable JSON, or guarded archive actions.
Bundled helper
Run from this skill directory:
python3 scripts/gmail_mail_tool.py --helpCommon preview flows
Preview GitHub notifications older than 14 days:
python3 scripts/gmail_mail_tool.py \
--account [email protected] \
--from-email [email protected] \
--older-than-days 14Preview newsletters by subject text and keep only inbox mail missing a label:
python3 scripts/gmail_mail_tool.py \
--account [email protected] \
--subject-contains newsletter \
--missing-label IMPORTANTPreview with a Gmail query plus local sender filtering, then save JSON:
python3 scripts/gmail_mail_tool.py \
--account [email protected] \
--query 'category:promotions newer_than:30d' \
--from-contains digest \
--out ./preview.jsonApply archive after preview
Only archive after checking the preview summary first.
python3 scripts/gmail_mail_tool.py \
--account [email protected] \
--from-email [email protected] \
--older-than-days 30 \
--max-apply-messages 100 \
--applyArchive from all mail only when you truly mean it:
python3 scripts/gmail_mail_tool.py \
--account [email protected] \
--all-mail \
--query 'label:newsletters older_than:90d' \
--has-label INBOX \
--applySafety rules
- default mode is preview only
--applyremoves theINBOXlabel from selected messages; it does not delete mail- the helper refuses empty-filter runs unless you explicitly pass
--allow-empty-filter - the helper refuses oversized apply runs unless you raise the caps or pass
--force-unsafe-apply - for risky cleanups, save the preview JSON before applying changes
Useful flags
--queryfor Gmail-native filtering--from-email,--from-contains,--subject-contains,--snippet-containsfor local filtering--has-labeland--missing-labelfor label-aware cleanup--older-than-days/--newer-than-daysfor age windows--sample-limitto control preview size--outto persist the JSON summary
Environment overrides
The helper supports these optional environment variables:
GMAIL_TOOL_ACCOUNTGOG_ACCOUNTGMAIL_TOOL_GOG_CREDENTIALSGMAIL_TOOL_GOG_KEYRING_PASSWORD_FILEGMAIL_TOOL_LOG_FILEGOG_KEYRING_PASSWORD
Recommended agent behavior
- Start with read-only search or preview.
- Inspect sender, subject, date, labels, and sample output.
- Apply only after the preview matches the intended cleanup scope.
- For large mailboxes, narrow the query first instead of forcing a huge apply.