email-imap-fetch
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseEmail IMAP Fetch
邮件IMAP获取工具
Core Goal
核心目标
- Wait for new mail with IMAP IDLE.
- Fetch unread messages after each wake-up.
- Support multiple mailbox accounts configured with env.
- Control IDLE support strictly with env mode (or
idle) without runtime probing.poll - Forward each fetched email to OpenClaw webhooks.
- Emit machine-readable JSON lines for downstream steps.
- 利用IMAP IDLE等待新邮件。
- 每次唤醒后获取未读消息。
- 支持通过环境变量配置多个邮箱账户。
- 通过环境变量模式(或
idle)严格控制IDLE支持,无需运行时探测。poll - 将每封获取到的邮件转发至OpenClaw webhooks。
- 输出机器可读的JSON行,供下游步骤使用。
Workflow
工作流程
- Configure account env variables and OpenClaw webhook env variables (see and
references/env.md).assets/config.example.env - Validate configuration:
bash
python3 scripts/imap_idle_fetch.py check-config- Run one IDLE cycle per account (smoke test):
bash
python3 scripts/imap_idle_fetch.py listen --cycles 1 --idle-seconds 120 --max-messages 10- Run continuously (default resident mode):
bash
python3 scripts/imap_idle_fetch.py listen- 配置账户环境变量和OpenClaw webhook环境变量(详见和
references/env.md)。assets/config.example.env - 验证配置:
bash
python3 scripts/imap_idle_fetch.py check-config- 为每个账户运行一次IDLE周期(冒烟测试):
bash
python3 scripts/imap_idle_fetch.py listen --cycles 1 --idle-seconds 120 --max-messages 10- 持续运行(默认常驻模式):
bash
python3 scripts/imap_idle_fetch.py listenRuntime Model
运行时模型
- Skill files are installed locally, but the listener is not auto-started.
- In mode, IMAP IDLE receives push events only while listener process and IMAP connection are alive.
idle - In mode, listener sleeps for poll interval and then fetches unread messages.
poll - If the process exits, push events are missed; next run can still fetch existing unread emails with .
UNSEEN - Default runtime is resident mode (by default).
IMAP_CYCLES=0 - Default IDLE mode is (safe for servers without IDLE support).
poll - For always-on behavior in production, manage the process with ,
systemd,launchd, or an equivalent daemon manager.supervisor
- 技能文件本地安装,但监听器不会自动启动。
- 在模式下,仅当监听器进程和IMAP连接保持活跃时,IMAP IDLE才能接收推送事件。
idle - 在模式下,监听器会在轮询间隔内休眠,之后获取未读消息。
poll - 若进程退出,推送事件会丢失;下次运行时仍可通过标记获取已存在的未读邮件。
UNSEEN - 默认运行模式为常驻模式(默认)。
IMAP_CYCLES=0 - 默认IDLE模式为(对不支持IDLE的服务器更安全)。
poll - 若要在生产环境中实现始终在线的运行状态,可使用、
systemd、launchd或类似的守护进程管理器来管理该进程。supervisor
Output Contract
输出约定
- Output format is JSONL (one JSON object per line).
- for lifecycle events.
type=status - for fetched emails with:
type=message- ,
account,mailbox,sequid - ,
subject,from,to,datemessage_id - (plain-text preview)
snippet
- is
wait_modeoridlein cycle status output.poll - records the active wait strategy details.
wait_events - status events when OpenClaw webhook POST succeeds.
event=webhook_delivered - for account-level failures.
type=error - error events when OpenClaw webhook POST fails.
event=webhook_failed
- 输出格式为JSONL(每行一个JSON对象)。
- 生命周期事件使用标记。
type=status - 获取到的邮件使用标记,包含:
type=message- ,
account,mailbox,sequid - ,
subject,from,to,datemessage_id - (纯文本预览)
snippet
- 周期状态输出中的为
wait_mode或idle。poll - 记录当前等待策略的详细信息。
wait_events - OpenClaw webhook POST请求成功时,会输出状态事件。
event=webhook_delivered - 账户级失败使用标记。
type=error - OpenClaw webhook POST请求失败时,会输出错误事件。
event=webhook_failed
Parameters
参数
- : IDLE cycles per account (
--cyclesmeans forever).0 - : max wait time for each IDLE call.
--idle-seconds - : interval used when polling mode is active.
--poll-seconds - :
--idle-modeoridle.poll - : max unread emails fetched each cycle.
--max-messages - /
--mark-seen: control unread state updates.--no-mark-seen - : preview length limit.
--snippet-chars - : connection timeout seconds.
--connect-timeout - : retry delay after failure.
--retry-seconds
Environment defaults:
IMAP_CYCLESIMAP_IDLE_MODEIMAP_IDLE_SECONDSIMAP_POLL_SECONDSIMAP_MAX_MESSAGESIMAP_MARK_SEENIMAP_SNIPPET_CHARSIMAP_CONNECT_TIMEOUTIMAP_RETRY_SECONDS
OpenClaw webhooks forwarding:
OPENCLAW_WEBHOOKS_ENABLEDOPENCLAW_WEBHOOKS_TOKENOPENCLAW_WEBHOOKS_BASE_URL- (
OPENCLAW_WEBHOOKS_MODEoragent)wake - (optional endpoint override)
OPENCLAW_WEBHOOKS_ENDPOINT OPENCLAW_WEBHOOKS_PATHOPENCLAW_WEBHOOKS_WAKE_MODEOPENCLAW_WEBHOOKS_DELIVEROPENCLAW_WEBHOOKS_TIMEOUTOPENCLAW_WEBHOOKS_NAMEOPENCLAW_WEBHOOKS_AGENT_IDOPENCLAW_WEBHOOKS_CHANNELOPENCLAW_WEBHOOKS_TOOPENCLAW_WEBHOOKS_MODELOPENCLAW_WEBHOOKS_THINKINGOPENCLAW_WEBHOOKS_AGENT_TIMEOUT_SECONDSOPENCLAW_WEBHOOKS_SESSION_KEY_PREFIX
- :每个账户的IDLE周期数(
--cycles表示无限循环)。0 - :每次IDLE调用的最长等待时间。
--idle-seconds - :轮询模式下的间隔时间。
--poll-seconds - :模式选项,可选
--idle-mode或idle。poll - :每个周期获取的未读邮件最大数量。
--max-messages - /
--mark-seen:控制是否更新邮件的未读状态。--no-mark-seen - :预览内容的长度限制。
--snippet-chars - :连接超时时间(秒)。
--connect-timeout - :失败后的重试延迟时间。
--retry-seconds
环境变量默认值:
IMAP_CYCLESIMAP_IDLE_MODEIMAP_IDLE_SECONDSIMAP_POLL_SECONDSIMAP_MAX_MESSAGESIMAP_MARK_SEENIMAP_SNIPPET_CHARSIMAP_CONNECT_TIMEOUTIMAP_RETRY_SECONDS
OpenClaw webhooks转发相关变量:
OPENCLAW_WEBHOOKS_ENABLEDOPENCLAW_WEBHOOKS_TOKENOPENCLAW_WEBHOOKS_BASE_URL- (可选
OPENCLAW_WEBHOOKS_MODE或agent)wake - (可选的端点覆盖配置)
OPENCLAW_WEBHOOKS_ENDPOINT OPENCLAW_WEBHOOKS_PATHOPENCLAW_WEBHOOKS_WAKE_MODEOPENCLAW_WEBHOOKS_DELIVEROPENCLAW_WEBHOOKS_TIMEOUTOPENCLAW_WEBHOOKS_NAMEOPENCLAW_WEBHOOKS_AGENT_IDOPENCLAW_WEBHOOKS_CHANNELOPENCLAW_WEBHOOKS_TOOPENCLAW_WEBHOOKS_MODELOPENCLAW_WEBHOOKS_THINKINGOPENCLAW_WEBHOOKS_AGENT_TIMEOUT_SECONDSOPENCLAW_WEBHOOKS_SESSION_KEY_PREFIX
Error Handling
错误处理
- Invalid env configuration exits with code .
2 - In mode, unsupported IDLE returns explicit error and suggests
idle.IMAP_IDLE_MODE=poll - Runtime failures are emitted as .
type=error - Command exits non-zero when account processing errors occur.
- 无效的环境变量配置会以退出码终止程序。
2 - 在模式下,若服务器不支持IDLE,会返回明确错误并建议设置
idle。IMAP_IDLE_MODE=poll - 运行时失败会以的形式输出。
type=error - 当账户处理出现错误时,命令会以非零状态码退出。
References
参考文档
references/env.md
references/env.md
Assets
资源文件
assets/config.example.env
assets/config.example.env
Scripts
脚本文件
scripts/imap_idle_fetch.py
scripts/imap_idle_fetch.py