gmail +watch
PREREQUISITE: Read ../gws-shared/SKILL.md for auth, global flags, and security rules. If missing, run gws generate-skills to create it.
Watch for new emails and stream them as NDJSON
Usage
CODEBLOCK0
Flags
| Flag | Required | Default | Description |
|---|
| INLINECODE2 | — | — | GCP project ID for Pub/Sub resources |
| INLINECODE3 |
— | — | Existing Pub/Sub subscription name (skip setup) |
|
--topic | — | — | Existing Pub/Sub topic with Gmail push permission already granted |
|
--label-ids | — | — | Comma-separated Gmail label IDs to filter (e.g., INBOX,UNREAD) |
|
--max-messages | — | 10 | Max messages per pull batch |
|
--poll-interval | — | 5 | Seconds between pulls |
|
--msg-format | — | full | Gmail message format: full, metadata, minimal, raw |
|
--once | — | — | Pull once and exit |
|
--cleanup | — | — | Delete created Pub/Sub resources on exit |
|
--output-dir | — | — | Write each message to a separate JSON file in this directory |
Examples
CODEBLOCK1
Tips
- - Gmail watch expires after 7 days — re-run to renew.
- Without --cleanup, Pub/Sub resources persist for reconnection.
- Press Ctrl-C to stop gracefully.
See Also
技能名称: gws-gmail-watch
详细描述:
gmail +watch
前置条件: 请阅读 ../gws-shared/SKILL.md 了解认证、全局标志和安全规则。如果该文件缺失,请运行 gws generate-skills 创建。
监听新邮件并以 NDJSON 格式输出流
用法
bash
gws gmail +watch
标志
| 标志 | 必需 | 默认值 | 描述 |
|---|
| --project | — | — | Pub/Sub 资源的 GCP 项目 ID |
| --subscription |
— | — | 现有的 Pub/Sub 订阅名称(跳过设置) |
| --topic | — | — | 已授予 Gmail 推送权限的现有 Pub/Sub 主题 |
| --label-ids | — | — | 用于筛选的 Gmail 标签 ID(逗号分隔,例如 INBOX,UNREAD) |
| --max-messages | — | 10 | 每次拉取的最大消息数 |
| --poll-interval | — | 5 | 拉取间隔(秒) |
| --msg-format | — | full | Gmail 消息格式:full、metadata、minimal、raw |
| --once | — | — | 仅拉取一次后退出 |
| --cleanup | — | — | 退出时删除已创建的 Pub/Sub 资源 |
| --output-dir | — | — | 将每条消息写入此目录下的独立 JSON 文件 |
示例
bash
gws gmail +watch --project my-gcp-project
gws gmail +watch --project my-project --label-ids INBOX --once
gws gmail +watch --subscription projects/p/subscriptions/my-sub
gws gmail +watch --project my-project --cleanup --output-dir ./emails
提示
- - Gmail 监听在 7 天后过期——重新运行以续期。
- 不使用 --cleanup 时,Pub/Sub 资源会保留以便重新连接。
- 按 Ctrl-C 可优雅停止。
另请参阅