fix(mail-operations): 按 v10.0.180 起的邮件服务行为更新技能说明(1.2.0) (#233)

- save_to 可保存任意 JSON 响应;超过输出上限时的提示与做法;messages/fetch 拿不到完整结果时改读本地缓存
- 等待上限 20 分钟,失败按请求是否送达区分;写操作失败后先核对再决定是否重试
- IMAP 其他文件夹的 id 带文件夹键,folder 只对带键 id 起核对作用;改动类操作只认本地缓存;新错误码
- IMAP 补拉只取摘要,附件 id 为 part:<n>;/api/sync 支持 imap,syncInterval 按分钟
- required_client_version 提到 10.0.180,删掉两句已过时的旧客户端说明
This commit is contained in:
yige authored and GitHub committed 2026-10-28 22:37:35 +08:00
1 parent 1ced701714
commit 50882f17ff
3 files changed
+107 -57

No files matched your search

+55 -30
View File
@@ -10,7 +10,7 @@ description: >-
Use when 用户提到 邮件、邮箱、收件箱、发邮件、回复邮件、查邮件、Gmail、
Outlook、QQ邮箱、163邮箱、附件、标签、草稿、自动回复、邮件规则、
转发、抄送、未读邮件、收信、发信、邮件同步、邮件搜索。
version: 1.1.0
version: 1.2.0
type: procedural
risk_level: medium
status: enabled
@@ -24,7 +24,7 @@ tags:
- smtp
metadata:
author: desirecore
updated_at: '2026-10-05'
updated_at: '2026-10-28'
i18n:
default_locale: en-US
source_locale: zh-CN
@@ -37,7 +37,7 @@ metadata:
description: >-
Use this skill whenever the user wants to interact with email. This includes reading inbox, sending emails, replying, searching messages, managing labels and categories, downloading attachments, setting up auto-reply rules, or triggering agents to handle incoming emails. Supports Gmail, Outlook, and IMAP/SMTP (QQ Mail, 163, Yahoo, etc.) through DesireCore's local REST API. Use when 用户提到 邮件、邮箱、收件箱、发邮件、回复邮件、查邮件、Gmail、 Outlook、QQ邮箱、163邮箱、附件、标签、草稿、自动回复、邮件规则、 转发、抄送、未读邮件、收信、发信、邮件同步、邮件搜索。
body: ./SKILL.zh-CN.md
source_hash: sha256:24bffbade0dc09a7
source_hash: sha256:0f8d0c1cc15fa36e
translated_by: human
en-US:
name: Email Operations
@@ -45,9 +45,9 @@ metadata:
description: >-
Use this skill whenever the user wants to interact with email. This includes reading inbox, sending emails, replying, searching messages, managing labels and categories, downloading attachments, setting up auto-reply rules, or triggering agents to handle incoming emails. Supports Gmail, Outlook, and IMAP/SMTP (QQ Mail, 163, Yahoo, etc.) through DesireCore's local REST API. Use when the user mentions email, mailbox, inbox, sending email, replying, checking email, Gmail, Outlook, QQ Mail, 163 Mail, attachments, labels, drafts, auto-reply, email rules, forwarding, CC, unread email, receiving, sending, email sync, or email search.
body: ./SKILL.md
source_hash: sha256:ec3be525ab586e62
source_hash: sha256:0f8d0c1cc15fa36e
translated_by: human
translated_at: '2026-10-05'
translated_at: '2026-10-28'
market:
icon: >-
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0
@@ -63,7 +63,7 @@ market:
name: DesireCore Official
verified: true
channel: latest
required_client_version: 10.0.178
required_client_version: 10.0.180
---
# mail-operations Skill
@@ -106,10 +106,11 @@ Users can reach the email management interface via:
## API Basics
- **How to call**: use the built-in `MailOperations` tool. Its parameters are `path` (a relative path starting with `/api/`, with query parameters appended directly to it), `method` (default `GET`), `body` (a JSON object), and `save_to` (only for attachment downloads, see section 6). The tool locates the local Mail Service and attaches the access credential automatically; the Agent neither needs nor can supply a token.
- **How to call**: use the built-in `MailOperations` tool. Its parameters are `path` (a relative path starting with `/api/`, with query parameters appended directly to it), `method` (default `GET`), `body` (a JSON object), and `save_to` (writes the response to a file, see "Large responses and `save_to`" below; required when downloading an attachment, see section 6). The tool locates the local Mail Service and attaches the access credential automatically; the Agent neither needs nor can supply a token.
- **Large responses and `save_to`**: the tool returns at most 100 KB. Message list, search, and `messages/fetch` responses carry the body of every message, so a few dozen messages can exceed the limit. When the limit is exceeded and no `save_to` is given, the tool shortens overlong fields (such as message bodies) and re-indents the JSON before returning it, keeping only the head and tail when it still does not fit; a leading notice states the response size, that it is "not the complete result" or which fields were shortened, the response structure (e.g. `result.messages 20 条,total 411`), and how to get the full content. When you need the complete result, call again with the same `path` / `method` / `body` plus `save_to` (e.g. `"./mail-list.json"`) and read that file with Read or a script, or page with a smaller `limit`. With `save_to`, the complete response is written to the file atomically (JSON up to 8 MB is re-indented with 2 spaces; larger responses are written as is, and the receipt says so), and the tool returns only the absolute path, byte count, SHA-256, and a structure summary; non-2xx responses are not written; a response body over 32 MB is refused, so reduce `limit`; the target path must be inside a writable working directory, missing parent directories are created, and an existing file with the same name is overwritten. The result of `messages/fetch` is already written to the local cache before it is returned: when its response exceeds the limit, read the local cache with `GET /{p}/messages` (the matching `folder`, paged by `offset` / `limit`, with `save_to` if needed) instead of running the same fetch again.
- **Path form**: the endpoints below omit the `/api` prefix; add it when calling. For example, `/imap/messages?email=me%40example.com&limit=20` becomes `path: "/api/imap/messages?email=me%40example.com&limit=20"`. The only exception is the health check `/ping` (no `/api`).
- **Do not connect to the port directly**: do not `curl` `https://127.0.0.1:62000`. The port is allocated dynamically starting at 62000 (when several DesireCore instances run, 62000 may belong to another instance), and in strict capability mode direct requests without the credential always return 401.
- **Parameter location**: GET / DELETE parameters always go in the query string; for POST / PUT follow the tables below. The `email` of endpoints such as `messages/fetch`, mark as read/unread, Outlook single-message operations, and IMAP draft send must be in the query string; putting it in the body returns 400 `Missing email parameter`. For `/sync`, both `provider` and `email` must be in the query string: `provider` in the body returns 400 `Invalid provider`, and `email` alone in the body raises no parameter error but the sync does not take effect.
- **Parameter location**: GET / DELETE parameters always go in the query string; for POST / PUT follow the tables below. The `email` of endpoints such as `messages/fetch`, mark as read/unread, Outlook single-message operations, and IMAP draft send must be in the query string; putting it in the body returns 400 `Missing email parameter`. For `/sync`, both `provider` and `email` must be in the query string: `provider` in the body returns 400 `Invalid provider`, and `email` in the body returns 400 `Email is required`. `method` defaults to `GET`; endpoints that take a request body (such as `messages/fetch`) also need `method: "POST"`, and the tool refuses a GET with a `body` before sending it.
- **Content-Type**: `application/json` (set automatically by the tool when `body` is passed)
- **Response format**: success `{"code": 1, "msg": "Success", "result": ...}`, failure `{"code": 0, "msg": "error message"}`; some errors also carry a stable error code field `error` (e.g. `smtp_unverified`)
@@ -154,7 +155,7 @@ After a write operation (send, reply, delete, mark, label change, etc.) succeeds
|------|-------|---------|------|
| Authorization | OAuth2 | OAuth2 (MSAL) | password / app password |
| Provider path | `/gmail/` | `/outlook/` | `/imap/` |
| Message detail | path param `/{id}` | query param `?id={id}` | path param `/{uid}` (the list's `imap:<uid>` or a bare numeric UID) + `?folder=` |
| Message detail | path param `/{id}` | query param `?id={id}` | path param `/{id}` (pass the list's `id` back as is; `folder` optional) |
| Search (local cache) | supported | supported | supported |
| Remote fetch paging | `pageToken` (no `offset`) | `skip` / `offset` | `offset` |
| Drafts | supported (incl. list/detail) | supported (create/update/delete/send) | supported (create/update/delete/send) |
@@ -195,19 +196,19 @@ In the following, `{p}` denotes the provider (`gmail`, `outlook`, `imap`); `{ema
|------|------|------|------|
| Query local cache | GET | `/{p}/messages` | query string: `email, offset, limit, folder`; returns `{messages, total, offset, limit}` |
| Remote sync | POST | `/{p}/messages/fetch?email=` | `email` must be in the query string; body (or query string): `folder`, `limit` (1–1000, default 20); paging: IMAP `offset`, Outlook `skip` / `offset`, Gmail `pageToken` (Gmail returns 400 for `offset`); returns `messages` plus paging info `pagination` |
| Manually trigger sync | POST | `/sync?provider=&email=` | parameters in the query string; **gmail / outlook only** — IMAP returns 400, use `messages/fetch` instead |
| Manually trigger sync | POST | `/sync?provider=&email=` | parameters in the query string; `provider` is `gmail`, `outlook`, or `imap`. Runs one round of the same sync as automatic sync right away: for IMAP it pulls only new INBOX mail; use `messages/fetch` to backfill older mail or other folders |
**IMAP remote sync is slow**: every message is downloaded and parsed in full (about 0.65 messages/second measured), so keep each batch's `limit` at 100 or less and page through older mail with `offset` (how many of the newest messages to skip).
**IMAP remote sync**: `messages/fetch` generally fetches only each message's header fields, structure, and a length-capped body, without downloading attachments (an attachment is fetched by its part when you download it). When the body was truncated, or the HTML references inline images (`cid:`) that were not embedded, the entry carries `"bodyPartial": true`; when you need the full body, get the message detail (`GET /imap/messages/{id}`), which fetches the full message from the server and completes the local cache, and still returns the summary with `bodyPartial` set to `true` if it cannot. The attachment `size` in backfilled entries is an estimate; the download receipt gives the exact byte count. A batch can still take a long time, so keep each batch's `limit` at 100 or less and page through older mail with `offset` (how many of the newest messages to skip).
**folder values**:
- Local cache list and search: `inbox, sent, drafts, trash, spam, archive, other`, case-insensitive; server names (e.g. `INBOX`, `Sent Messages`) are accepted too. IMAP custom folders are all stored locally as `other`.
- Remote sync: generic names (`inbox`, `sent`, ...) are mapped automatically to the actual IMAP folder, the Outlook folder, or the Gmail label; for IMAP you may also pass a `path` returned by `GET /imap/folders`. Gmail has no label for `archive`, so it fetches without filtering.
- **IMAP single-message operations** (detail on a cache miss, mark as read/unread, delete, mark as junk / not junk, reply, attachment download) pass `folder` verbatim to the IMAP server, so it must be a real `path` returned by `GET /imap/folders` (e.g. `INBOX`, `Sent Messages`); it defaults to `INBOX` when omitted. The `folder` field of a list item is a normalized value (e.g. `sent`) and cannot be used as an IMAP folder name directly.
- **IMAP single-message operations** (detail, mark as read/unread, delete, mark as junk / not junk, reply, attachment download) do not need `folder`: the folder on the server is determined by the `id`; an `id` with a folder key (`imap:<mailboxKey>:<uid>`) uses the `imapFolder` recorded in the local cache. `folder` acts as a cross-check only for an `id` with a folder key; pass the entry's `imapFolder`, and a mismatch returns 409 `imap_folder_mismatch`. The `folder` field of a list item is a normalized value (custom folders are `other`) and cannot be used for the cross-check. For INBOX messages (`imap:<uid>`), do not pass `folder`, or pass only `INBOX`. See section 3.
**Response format** (message list item):
```json
{
"id": "messageID (imap:<uid> for IMAP)", "provider": "gmail",
"id": "messageID (for IMAP see below)", "provider": "gmail",
"subject": "subject",
"from": {"name": "...", "address": "..."},
"toRecipients": [{"name": "...", "address": "..."}],
@@ -218,29 +219,34 @@ In the following, `{p}` denotes the provider (`gmail`, `outlook`, `imap`); `{ema
}
```
`labelIds` appears only on Gmail messages and `categories` only on Outlook messages.
`labelIds` appears only on Gmail messages and `categories` only on Outlook messages. An IMAP message `id` includes its folder: `imap:<uid>` for INBOX and `imap:<mailboxKey>:<uid>` for other folders (`mailboxKey` is 16 hex digits derived from the server folder name); IMAP entries also carry `imapFolder` (the folder name on the server) and `imapUidValidity`, and backfilled entries may carry `bodyPartial`.
### 3. Single Message Operations
| Operation | Gmail | Outlook | IMAP |
|------|-------|---------|------|
| Get detail | GET `/{id}?email=` | GET `/message?id={id}&email=` | GET `/{uid}?email=&folder=` |
| Mark as read | POST `/{id}/read?email=` | POST `/message/read?id={id}&email=` | POST `/{uid}/read?email=&folder=` |
| Mark as unread | POST `/{id}/unread?email=` | POST `/message/unread?id={id}&email=` | POST `/{uid}/unread?email=&folder=` |
| Delete | DELETE `/{id}?email=` | DELETE `/message?id={id}&email=` | DELETE `/{uid}?email=&folder=` |
| Mark as junk | POST `/{id}/spam?email=` | POST `/message/spam?id={id}&email=` | POST `/{uid}/spam?email=&folder=` |
| Not junk | POST `/{id}/not-spam?email=` | POST `/message/not-spam?id={id}&email=` | POST `/{uid}/not-spam?email=&folder=` |
| Get detail | GET `/{id}?email=` | GET `/message?id={id}&email=` | GET `/{id}?email=` |
| Mark as read | POST `/{id}/read?email=` | POST `/message/read?id={id}&email=` | POST `/{id}/read?email=` |
| Mark as unread | POST `/{id}/unread?email=` | POST `/message/unread?id={id}&email=` | POST `/{id}/unread?email=` |
| Delete | DELETE `/{id}?email=` | DELETE `/message?id={id}&email=` | DELETE `/{id}?email=` |
| Mark as junk | POST `/{id}/spam?email=` | POST `/message/spam?id={id}&email=` | POST `/{id}/spam?email=` |
| Not junk | POST `/{id}/not-spam?email=` | POST `/message/not-spam?id={id}&email=` | POST `/{id}/not-spam?email=` |
> All paths are prefixed with `/api/{provider}/messages` (Gmail/IMAP) or `/api/outlook/` (Outlook's special routing). For IMAP, `{uid}` may be the list's `id` (`imap:<uid>`) as is; see section 2 for `folder`, which may be omitted for INBOX.
> All paths are prefixed with `/api/{provider}/messages` (Gmail/IMAP) or `/api/outlook/` (Outlook's special routing). For IMAP, pass the list's `id` back as `{id}` unchanged; do not build it yourself or strip its prefix. A bare numeric UID is also accepted and refers to a message in INBOX when no `folder` is given. INBOX `imap:<uid>` ids and bare UIDs do not cross-check `folder`: passing another folder redirects the call to the message with the same UID in that folder, and if that message happens to be in the local cache, a mutating operation acts on it. So for INBOX messages, do not pass `folder`, or pass only `INBOX`.
**Locating IMAP messages and rejections**: an `id` with a folder key is located by the `imapFolder` recorded in the local cache; `folder` may be omitted and, when passed, is only a cross-check (pass the entry's `imapFolder`). In the following cases the requested operation is not performed; do not retry it unchanged:
- Mark as read/unread, delete, mark as junk / not junk, and reply only accept messages that are in the local cache; otherwise they return 404 `imap_message_not_cached`. First fetch the folder with `messages/fetch` or get the message detail, then use the `id` from that result.
- Get detail and attachment download are not restricted this way, and getting the detail records the message in the local cache; but for an `id` with a folder key that is not cached locally, pass the entry's `imapFolder` as `folder`, otherwise they also return 404 `imap_message_not_cached`.
- The `folder` passed does not match the folder of an `id` with a folder key: 409 `imap_folder_mismatch`. Omit `folder`, or pass the entry's `imapFolder` (the `folder` field of a list item cannot be used for the cross-check).
- The server rebuilt the folder (UIDVALIDITY changed), so this `id` no longer refers to the original message: 409 `imap_uidvalidity_changed`. Run `messages/fetch` on that folder again and use the new `id`.
**Mark as junk / Not junk**: moves the message into the junk folder, or out of it back to the inbox. The server and the local cache change together, and the response is `result: {id, folder}`.
- Gmail swaps the `SPAM` / `INBOX` labels and keeps the `id`; Outlook and IMAP assign a new `id` after the move, so use the returned `id` for any later operation on this message. When the IMAP server lacks UIDPLUS the `id` is `null`; run `messages/fetch` on the destination folder before using the message again.
- If the IMAP account has no junk folder on the server, the call returns 409 `imap_spam_folder_not_found`. Tell the user as is; do not retry and do not substitute another folder.
- A message already in the destination folder returns success without moving. A message moved back to the inbox does not trigger mail rules or a new-mail notification.
- Not junk handles one message at a time; do not move a batch back to the inbox together. Mark as junk may be called once per message.
- Requires client 10.0.178 or later; older clients return 404, in which case ask the user to upgrade the client.
**Extra fields in message detail**: `body: {content, contentType}`, `ccRecipients`, `attachments: [{id, filename, contentType, size}]`. For IMAP, an attachment's `id` is its index within the message as a string (`"0"`, `"1"`, ...).
**Extra fields in message detail**: `body: {content, contentType}`, `ccRecipients`, `attachments: [{id, filename, contentType, size}]`. For IMAP, use an attachment's `id` as is: entries written by `messages/fetch` and by get detail generally use `part:<IMAP part number>` (e.g. `part:2`); new mail pulled by automatic polling or `POST /sync`, and entries cached earlier, may use an index string (`"0"`, `"1"`, ...). Both work for attachment download, and any other form returns 400.
### 4. Send and Reply
@@ -266,7 +272,7 @@ Each `attachments` item is `{filename, content (base64), contentType}`. Gmail re
|----------|------|------|
| Gmail | POST `/gmail/reply` | `{email, messageId, body, contentType}` |
| Outlook | POST `/outlook/message/reply?id={id}&email=` | `{body, contentType}` |
| IMAP | POST `/imap/reply` | `{email, uid, folder, body, contentType}` (`uid` may be `imap:<uid>`; `folder` defaults to `INBOX`) |
| IMAP | POST `/imap/reply` | `{email, uid, body, contentType}` (`uid` is the list's `id` as is; `folder` may be omitted and is a cross-check only for an `id` with a folder key; the original message must be in the local cache, see section 3) |
### 5. Search (All Three Providers)
@@ -286,7 +292,7 @@ Search reads only the **local cache** and never contacts the mail server; if not
Parameter names must match exactly; unknown parameters (e.g. `query`, `hasAttachments`) return 400. Returns `{messages, total, offset, limit}`.
To run a full-text search on the Gmail server by body or sender, use the `query` parameter of `POST /gmail/messages/fetch?email=` instead: it is passed straight to the Gmail API, supports Gmail search syntax (such as `from:` and `has:attachment`), and the results are also written to the local cache. Outlook and IMAP have no equivalent remote search parameter. If an older client returns 404 for `/outlook/search` or `/imap/search`, page through `GET /{p}/messages` and filter the results yourself.
To run a full-text search on the Gmail server by body or sender, use the `query` parameter of `POST /gmail/messages/fetch?email=` instead: it is passed straight to the Gmail API, supports Gmail search syntax (such as `from:` and `has:attachment`), and the results are also written to the local cache. Outlook and IMAP have no equivalent remote search parameter.
### 6. Attachment Download
@@ -297,7 +303,7 @@ To run a full-text search on the Gmail server by body or sender, use the `query`
| IMAP | POST | `/imap/attachment` | `{email, messageId, attachmentId, folder?}` |
- `attachmentId` comes from `attachments[].id` in the message detail; call the detail endpoint first to get the attachment list.
- IMAP: use the list's `id` (e.g. `imap:12345`) as `messageId`; `attachmentId` is the attachment index as a string (the first attachment is `"0"`); `folder` is the real folder path on the server and may be omitted for INBOX.
- IMAP: use the list's `id` as is (e.g. `imap:12345`) as `messageId`; use `attachments[].id` as is as `attachmentId` (e.g. `part:2`, or an index such as `"0"`, see section 3); `folder` may be omitted; when an `id` with a folder key is not cached locally, pass the entry's `imapFolder` (see section 3).
- **Always pass `save_to` to `MailOperations` when downloading an attachment** (the target file path): the tool decodes the base64 in process and writes the file, returning only the absolute path, byte count, and SHA-256; without `save_to` the tool refuses to return the attachment response. The target path must be inside a writable working directory.
- The endpoint's raw response is `result: {data: <base64>, size}`; the tool refuses to parse responses larger than about 32 MB — in that case follow the streaming-to-disk method given in the tool's error message, or ask the user to export the attachment manually from the Emails page.
@@ -307,7 +313,7 @@ Example (IMAP):
{
"path": "/api/imap/attachment",
"method": "POST",
"body": {"email": "me@example.com", "messageId": "imap:12345", "attachmentId": "0"},
"body": {"email": "me@example.com", "messageId": "imap:12345", "attachmentId": "part:2"},
"save_to": "./attachments/report.pdf"
}
```
@@ -443,7 +449,7 @@ The regex operator is `matches_regex` (`regex` is treated as an unknown operator
| Operation | Method | Endpoint |
|------|------|------|
| IMAP folder list | GET | `/imap/folders?email=` — returns `[{name, path, specialUse, flags}]`; use `path` as the `folder` of IMAP single-message operations |
| IMAP folder list | GET | `/imap/folders?email=` — returns `[{name, path, specialUse, flags}]`; `path` can be passed directly as the `folder` of `messages/fetch` |
| Outlook folder list | GET | `/outlook/folders?email=` |
> Gmail folders are fixed: inbox, sent, drafts, trash, spam, archive.
@@ -455,8 +461,8 @@ The regex operator is `matches_regex` (`regex` is treated as an unknown operator
The email system uses **local cache + periodic polling**:
- **Write operations** (send, mark, delete, Gmail native labels, Outlook categories): the provider endpoints update local and remote simultaneously, no delay; the unified label interface (section 8) and the mark, delete, and label actions of auto-rules change local data only
- **Read operations** (query, search): return the local cache; may be delayed (default 30-second polling)
- **Remote changes** (the user operates from the official web UI): Gmail / Outlook wait for the next polling cycle to sync; IMAP polling only pulls new INBOX mail, other folders require an explicit `messages/fetch`, and read or delete changes made on the server to already-cached messages are not written back locally
- **Read operations** (query, search): return the local cache and may be delayed. The automatic sync interval is the account setting `syncInterval`, in minutes (5 for new accounts; `0` turns automatic sync off, other valid values are 1–1440, and any other value returns 400 when updating the settings); call `POST /sync` to sync right away
- **Remote changes** (the user operates from the official web UI): Gmail / Outlook wait for the next polling cycle or a `POST /sync`; for IMAP, both polling and `POST /sync` only pull new INBOX mail, other folders require an explicit `messages/fetch`, and read or delete changes made on the server to already-cached messages are not written back locally
**Storage path**: `${DESIRECORE_ROOT}/mail/{provider}/{email}/` (meta.json, index.json, messages/)
@@ -469,7 +475,26 @@ The email system uses **local cache + periodic polling**:
| 400 | parameter error (including a parameter in the wrong place, e.g. a query-string parameter put in the body) | check parameter names and locations against `msg` |
| 401 | Gmail/Outlook authorization expired, IMAP account not configured, or missing Mail Service capability | **handle per Rule 1**; do not try other channels |
| 404 | resource not found | sync first and retry (Rule 3) |
| 404 | IMAP message not in the local cache (`error: imap_message_not_cached`) | fetch the folder with `messages/fetch` or get the detail first, then use the `id` from that result (see section 3) |
| 409 | IMAP account SMTP not verified (`error: smtp_unverified`) | guide the user to re-verify SMTP (`POST /imap/accounts/verify-smtp`) |
| 409 | the `folder` passed does not match the folder of an IMAP `id` with a folder key (`error: imap_folder_mismatch`), or the server rebuilt the folder (`error: imap_uidvalidity_changed`) | the operation was not performed; do not retry it unchanged; per section 3, omit `folder`, or fetch again and use the new `id` |
| 500 | internal error (common IMAP cause: `folder` is not a folder that exists on the server) | check `folder` first; if it still fails, tell the user to retry later |
**IMAP note**: domestic Chinese mailboxes (QQ, 163) require an "app password" instead of the login password. Use `/imap/test` to validate the configuration in advance and check `result.imap.success` and `result.smtp.success` in the response.
### When No Complete Response Arrives
`MailOperations` waits up to 20 minutes for the Mail Service to respond. When no complete response arrives, the tool's message depends on how far the request got: failures while waiting for the response start with `Mail Service 请求失败:`, and failures while reading the body after a status code arrived start with `HTTP <status code>`. The messages are in Chinese; match them by these key phrases:
| Key phrase in the message | Meaning | Handling |
|----------------|------|------|
| `等待 Mail Service 响应超过 20 分钟` | timed out waiting; the mail service may still be processing the request | do not retry right away with the same parameters; reduce the batch (e.g. the `limit` of `messages/fetch`) and request again; for write requests, verify the result first |
| `请求已被取消(运行中止)` | the run was aborted; the request may already have been delivered | for write requests, verify the result first (scope below) |
| `请求未发出:运行已中止` | the run was aborted and the request was not sent | nothing to verify |
| `无法连接 Mail Service` | the request was not delivered; the mail service may not have started yet or may be restarting | retry later |
| `与 Mail Service 的连接在请求途中断开` | the server may already have processed the request | for write requests, verify the result first (scope below); read-only requests can be retried directly |
| `Mail Service 已返回成功响应,但正文没有读完` | the request has already been processed | do not redo write requests; the result of `messages/fetch` is already in the local cache, so page through it with `GET /{p}/messages` instead of fetching again; other read-only requests can be sent again |
| `Mail Service 返回了失败状态码,正文没有读完` | go by the status code; the request did not succeed | handle it by the status code |
| `请求未能发出(不是网络问题)`, `GET 请求不能带 body` | the request parameters do not match | check `path`, `method`, and `body`; a request with a `body` also needs `method: "POST"` or similar |
The Mail Service does not stop processing because the client disconnected: after a timeout or abort, the server may still complete the request (`messages/fetch` still writes the local cache when it finishes). Therefore, when the request may have been delivered (wait timeout, run aborted, connection broken mid-request, body not fully read), **verify the result of any request other than GET, `messages/fetch`, and attachment download before deciding whether to retry** (for example, check the sent folder, fetch the folder again, get the detail, or list the drafts, rules, or labels). Requests whose replay can repeat a side effect include: send, reply, delete, and move (including mark as junk / not junk); creating a draft and sending a draft (saving an IMAP draft is not idempotent, so a replay leaves an extra draft; sending a draft sends another message); `/rules/execute` (`auto_reply` sends another reply and `agent_handle` triggers the Agent again); and creating a rule, label, or category (a replay creates another one). GET, `messages/fetch`, and attachment download can be retried (except after a wait timeout: reduce the batch first as described in the table).
+49 -24
View File
@@ -40,10 +40,11 @@ mail-operations 是一个**流程型技能(Procedural Skill)**,通过 Desi
## API 基础信息
- **调用方式**:使用内置工具 `MailOperations`,参数为 `path`(以 `/api/` 开头的相对路径,查询参数直接拼在 path 里)、`method`(默认 `GET`)、`body`(JSON 对象)和 `save_to`(仅下载附件时使用,见第 6 节)。工具自动定位本机 Mail Service 并携带访问凭证,Agent 不需要、也不能自行提供 token。
- **调用方式**:使用内置工具 `MailOperations`,参数为 `path`(以 `/api/` 开头的相对路径,查询参数直接拼在 path 里)、`method`(默认 `GET`)、`body`(JSON 对象)和 `save_to`(把响应写入文件,见下方「大响应与 `save_to`」;下载附件时必须传,见第 6 节)。工具自动定位本机 Mail Service 并携带访问凭证,Agent 不需要、也不能自行提供 token。
- **大响应与 `save_to`**:工具返回内容的上限是 100KB。邮件列表、搜索和 `messages/fetch` 的每封邮件都带正文,几十封就可能超限。超限又没传 `save_to` 时,工具截短超长字段(如邮件正文)、把 JSON 按缩进重排后返回,放不下时只保留首尾部分;开头的说明写明响应大小、「不是完整结果」或哪些字段被截短、响应结构(如 `result.messages 20 条,total 411`)以及怎样拿到完整内容。需要完整结果时,用同样的 `path` / `method` / `body` 再调用一次并加上 `save_to`(如 `"./mail-list.json"`),再用 Read 或脚本读取该文件;或减小 `limit` 分页请求。传了 `save_to` 时,完整响应原子写入该文件(8MB 以内的 JSON 按 2 空格缩进重排,更大的按原文写入,回执会注明),工具只返回绝对路径、字节数、SHA-256 与结构摘要;非 2xx 响应不写文件;响应体超过 32MB 时拒绝写入,需减小 `limit`;目标路径须位于允许写入的工作目录内,缺失的父目录自动创建,同名文件直接覆盖。`messages/fetch` 的结果在返回前已经写入本地缓存:它的响应超限时,改用 `GET /{p}/messages`(对应的 `folder`,按 `offset` / `limit` 分页,必要时加 `save_to`)读取本地缓存,不要原样重新补拉。
- **路径写法**:下文端点均省略 `/api` 前缀,调用时要补上,例如 `/imap/messages?email=me%40example.com&limit=20` 对应 `path: "/api/imap/messages?email=me%40example.com&limit=20"`。唯一例外是健康检查 `/ping`(不带 `/api`)。
- **不要直连端口**:不要用 `curl` 访问 `https://127.0.0.1:62000`。端口从 62000 起动态分配(同时运行多个 DesireCore 实例时,62000 可能属于另一个实例),严格能力模式下不带凭证的直连请求一律返回 401。
- **参数位置**:GET / DELETE 的参数全部放查询串;POST / PUT 按下文表格区分查询串与 body。`messages/fetch`、标记已读/未读、Outlook 单封操作、IMAP 草稿发送等端点的 `email` 必须放在查询串,放进 body 会返回 400 `Missing email parameter`。`/sync` 的 `provider` 与 `email` 都必须放查询串:`provider` 放进 body 返回 400 `Invalid provider`,只有 `email` 放进 body 则不会报参数错误,但同步不会生效。
- **参数位置**:GET / DELETE 的参数全部放查询串;POST / PUT 按下文表格区分查询串与 body。`messages/fetch`、标记已读/未读、Outlook 单封操作、IMAP 草稿发送等端点的 `email` 必须放在查询串,放进 body 会返回 400 `Missing email parameter`。`/sync` 的 `provider` 与 `email` 都必须放查询串:`provider` 放进 body 返回 400 `Invalid provider`,`email` 放进 body 返回 400 `Email is required`。`method` 缺省为 `GET`,需要请求体的端点(如 `messages/fetch`)要同时传 `method: "POST"`;GET 带 `body` 会在发出前被工具拒绝。
- **Content-Type**: `application/json`(传 `body` 时工具自动设置)
- **响应格式**: 成功 `{"code": 1, "msg": "Success", "result": ...}`,失败 `{"code": 0, "msg": "错误信息"}`,部分错误另带稳定错误码字段 `error`(如 `smtp_unverified`)
@@ -88,7 +89,7 @@ mail-operations 是一个**流程型技能(Procedural Skill)**,通过 Desi
|------|-------|---------|------|
| 授权 | OAuth2 | OAuth2 (MSAL) | 密码/授权码 |
| Provider 路径 | `/gmail/` | `/outlook/` | `/imap/` |
| 邮件详情 | 路径参数 `/{id}` | 查询参数 `?id={id}` | 路径参数 `/{uid}`(列表返回的 `imap:<uid>` 或纯数字 UID)+ `?folder=` |
| 邮件详情 | 路径参数 `/{id}` | 查询参数 `?id={id}` | 路径参数 `/{id}`(列表返回的 `id` 原样传回,`folder` 可选) |
| 搜索(本地缓存) | 支持 | 支持 | 支持 |
| 远程同步翻页 | `pageToken`(不支持 `offset`) | `skip` / `offset` | `offset` |
| 草稿 | 支持(含列表/详情) | 支持(创建/更新/删除/发送) | 支持(创建/更新/删除/发送) |
@@ -129,19 +130,19 @@ mail-operations 是一个**流程型技能(Procedural Skill)**,通过 Desi
|------|------|------|------|
| 查询本地缓存 | GET | `/{p}/messages` | 查询串:`email, offset, limit, folder`;返回 `{messages, total, offset, limit}` |
| 远程同步 | POST | `/{p}/messages/fetch?email=` | `email` 必须放查询串;body(或查询串):`folder`、`limit`(1–1000,默认 20);翻页:IMAP `offset`、Outlook `skip` / `offset`、Gmail `pageToken`(Gmail 传 `offset` 返回 400);返回 `messages` 与分页信息 `pagination` |
| 手动触发同步 | POST | `/sync?provider=&email=` | 参数放查询串;**仅支持 gmail / outlook**,IMAP 返回 400,请改用 `messages/fetch` |
| 手动触发同步 | POST | `/sync?provider=&email=` | 参数放查询串;`provider` 为 `gmail`、`outlook` 或 `imap`。立即执行一轮与自动同步相同的同步:IMAP 只拉取收件箱的新邮件,补拉历史邮件或其他文件夹请用 `messages/fetch` |
**IMAP 远程同步较慢**:每封邮件都要下载并解析完整内容(实测约 0.65 封/秒),单批 `limit` 建议不超过 100;更早的邮件用 `offset`(跳过最新的多少封)分批拉取。
**IMAP 远程同步**:`messages/fetch` 一般只取每封邮件的头字段、结构和限长正文,不下载附件(附件在下载时按 part 单独取)。正文被截断、或 HTML 里引用的内嵌图(`cid:`)没有嵌入时,条目带 `"bodyPartial": true`;需要完整正文时取单封详情(`GET /imap/messages/{id}`),它会回服务器取完整邮件并补全本地缓存,取不到时照旧返回摘要,`bodyPartial` 仍为 `true`。补拉条目里附件的 `size` 是估算值,确切字节数以下载回执为准。一批仍可能耗时较长,单批 `limit` 建议不超过 100;更早的邮件用 `offset`(跳过最新的多少封)分批拉取。
**folder 取值**:
- 本地缓存列表与搜索:`inbox, sent, drafts, trash, spam, archive, other`,大小写不敏感,也接受服务器原名(如 `INBOX`、`Sent Messages`);IMAP 的自定义文件夹在本地统一归为 `other`。
- 远程同步:通用名(`inbox`、`sent` 等)会自动映射到 IMAP 实际文件夹、Outlook 文件夹或 Gmail 标签;IMAP 也可直接传 `GET /imap/folders` 返回的 `path`。Gmail 的 `archive` 没有对应标签,会不加过滤地拉取。
- **IMAP 单封操作**(详情未命中缓存、标记已读/未读、删除、标记为垃圾邮件 / 不是垃圾邮件、回复、附件下载)的 `folder` 会原样交给 IMAP 服务器,必须是 `GET /imap/folders` 返回的真实 `path`(如 `INBOX`、`Sent Messages`),省略时默认 `INBOX`。列表项里的 `folder` 是归一化后的值(如 `sent`),不能直接当作 IMAP 文件夹名。
- **IMAP 单封操作**(详情、标记已读/未读、删除、标记为垃圾邮件 / 不是垃圾邮件、回复、附件下载)不需要传 `folder`:服务器上的文件夹由 `id` 确定,带文件夹键的 `id`(`imap:<mailboxKey>:<uid>`)取本地缓存记下的 `imapFolder`。`folder` 只对带文件夹键的 `id` 起核对作用,核对时传条目的 `imapFolder`,不一致返回 409 `imap_folder_mismatch`;列表项的 `folder` 字段是归一化后的值(自定义文件夹为 `other`),不能拿来核对。INBOX 邮件(`imap:<uid>`)不要传 `folder`,或只传 `INBOX`。详见第 3 节。
**响应格式**(邮件列表项):
```json
{
"id": "消息ID(IMAP 为 imap:<uid>)", "provider": "gmail",
"id": "消息ID(IMAP 见下方说明)", "provider": "gmail",
"subject": "主题",
"from": {"name": "...", "address": "..."},
"toRecipients": [{"name": "...", "address": "..."}],
@@ -152,29 +153,34 @@ mail-operations 是一个**流程型技能(Procedural Skill)**,通过 Desi
}
```
`labelIds` 只在 Gmail 邮件中出现,`categories` 只在 Outlook 邮件中出现。
`labelIds` 只在 Gmail 邮件中出现,`categories` 只在 Outlook 邮件中出现。IMAP 邮件的 `id` 带文件夹:INBOX 为 `imap:<uid>`,其他文件夹为 `imap:<mailboxKey>:<uid>`(`mailboxKey` 是由服务器文件夹原名算出的 16 位十六进制);另带 `imapFolder`(服务器上的文件夹原名)与 `imapUidValidity`,补拉写入的条目可能带 `bodyPartial`。
### 3. 单封邮件操作
| 操作 | Gmail | Outlook | IMAP |
|------|-------|---------|------|
| 获取详情 | GET `/{id}?email=` | GET `/message?id={id}&email=` | GET `/{uid}?email=&folder=` |
| 标记已读 | POST `/{id}/read?email=` | POST `/message/read?id={id}&email=` | POST `/{uid}/read?email=&folder=` |
| 标记未读 | POST `/{id}/unread?email=` | POST `/message/unread?id={id}&email=` | POST `/{uid}/unread?email=&folder=` |
| 删除 | DELETE `/{id}?email=` | DELETE `/message?id={id}&email=` | DELETE `/{uid}?email=&folder=` |
| 标记为垃圾邮件 | POST `/{id}/spam?email=` | POST `/message/spam?id={id}&email=` | POST `/{uid}/spam?email=&folder=` |
| 不是垃圾邮件 | POST `/{id}/not-spam?email=` | POST `/message/not-spam?id={id}&email=` | POST `/{uid}/not-spam?email=&folder=` |
| 获取详情 | GET `/{id}?email=` | GET `/message?id={id}&email=` | GET `/{id}?email=` |
| 标记已读 | POST `/{id}/read?email=` | POST `/message/read?id={id}&email=` | POST `/{id}/read?email=` |
| 标记未读 | POST `/{id}/unread?email=` | POST `/message/unread?id={id}&email=` | POST `/{id}/unread?email=` |
| 删除 | DELETE `/{id}?email=` | DELETE `/message?id={id}&email=` | DELETE `/{id}?email=` |
| 标记为垃圾邮件 | POST `/{id}/spam?email=` | POST `/message/spam?id={id}&email=` | POST `/{id}/spam?email=` |
| 不是垃圾邮件 | POST `/{id}/not-spam?email=` | POST `/message/not-spam?id={id}&email=` | POST `/{id}/not-spam?email=` |
> 所有路径前缀为 `/api/{provider}/messages`(Gmail/IMAP)或 `/api/outlook/`(Outlook 特殊路由)。IMAP 的 `{uid}` 可直接用列表返回的 `id`(`imap:<uid>`),`folder` 规则见第 2 节,INBOX 可省略。
> 所有路径前缀为 `/api/{provider}/messages`(Gmail/IMAP)或 `/api/outlook/`(Outlook 特殊路由)。IMAP 的 `{id}` 把列表返回的 `id` 原样传回,不要自己拼接或剥掉前缀;裸数字 UID 也接受,不带 `folder` 时指 INBOX 里的邮件。INBOX 的 `imap:<uid>` 和裸 UID 不核对 `folder`:传了别的文件夹,会改指那个文件夹里同号的另一封邮件,若本地恰好缓存了那封邮件,改动类操作就会落在它上面。所以 INBOX 邮件不要传 `folder`,或只传 `INBOX`。
**IMAP 单封操作的定位与拒绝**:带文件夹键的 `id` 按本地缓存记下的 `imapFolder` 定位,`folder` 可省略,传了只用来核对(传条目的 `imapFolder`)。下列情况不会执行所请求的操作,不要原样重试:
- 标记已读/未读、删除、标记为垃圾邮件 / 不是垃圾邮件、回复只认本地缓存里有的邮件,没有时返回 404 `imap_message_not_cached`。先用 `messages/fetch` 取该文件夹,或先取详情,再用结果里的 `id` 操作。
- 取详情与下载附件不受此限,取详情会把邮件记入本地缓存;但带文件夹键的 `id` 在本地没有缓存时,要传条目的 `imapFolder` 作为 `folder`,否则同样返回 404 `imap_message_not_cached`。
- 传入的 `folder` 与带文件夹键的 `id` 所在文件夹不一致:409 `imap_folder_mismatch`。去掉 `folder`,或传条目的 `imapFolder`(列表项的 `folder` 字段不能用来核对)。
- 服务器重建了该文件夹(UIDVALIDITY 变化),这个 `id` 已不再指向原来的邮件:409 `imap_uidvalidity_changed`。对该文件夹重新 `messages/fetch`,再用新的 `id`。
**标记为垃圾邮件 / 不是垃圾邮件**:把邮件移入垃圾邮件文件夹,或从垃圾邮件文件夹移回收件箱,服务器与本地缓存同时修改,返回 `result: {id, folder}`。
- Gmail 改 `SPAM` / `INBOX` 标签,`id` 不变;Outlook、IMAP 移动后 `id` 会变,之后再操作这封邮件要用返回的新 `id`。IMAP 服务器不支持 UIDPLUS 时 `id` 为 `null`,对目标文件夹做一次 `messages/fetch` 后再取。
- IMAP 账户在服务器上没有垃圾邮件文件夹时返回 409 `imap_spam_folder_not_found`,如实告知用户,不要重试,也不要改用其他文件夹代替。
- 邮件已经在目标文件夹时直接返回成功。移回收件箱的邮件不会触发邮件规则,也不会推送新邮件通知。
- 「不是垃圾邮件」一次只处理一封,不要把一批邮件一起移回收件箱;标记为垃圾邮件可以逐封调用。
- 需要客户端 10.0.178 及以上;旧客户端返回 404,提示用户升级客户端。
**邮件详情额外字段**:`body: {content, contentType}`, `ccRecipients`, `attachments: [{id, filename, contentType, size}]`。IMAP 附件的 `id` 是附件在该邮件中的序号字符串(`"0"`、`"1"`……)。
**邮件详情额外字段**:`body: {content, contentType}`, `ccRecipients`, `attachments: [{id, filename, contentType, size}]`。IMAP 附件的 `id` 原样使用:`messages/fetch` 与取详情写入的条目一般为 `part:<IMAP part 号>`(如 `part:2`);自动轮询或 `POST /sync` 拉到的新邮件、以及较早缓存的条目可能是序号字符串(`"0"`、`"1"`……)。两种都可直接用于附件下载,其他形态返回 400。
### 4. 发送与回复
@@ -200,7 +206,7 @@ mail-operations 是一个**流程型技能(Procedural Skill)**,通过 Desi
|----------|------|------|
| Gmail | POST `/gmail/reply` | `{email, messageId, body, contentType}` |
| Outlook | POST `/outlook/message/reply?id={id}&email=` | `{body, contentType}` |
| IMAP | POST `/imap/reply` | `{email, uid, folder, body, contentType}`(`uid` 可用 `imap:<uid>`,`folder` 默认 `INBOX`) |
| IMAP | POST `/imap/reply` | `{email, uid, body, contentType}`(`uid` 原样用列表返回的 `id`;`folder` 可省略,只对带文件夹键的 `id` 起核对作用;原邮件须在本地缓存中,见第 3 节) |
### 5. 搜索(三种邮箱均支持)
@@ -220,7 +226,7 @@ mail-operations 是一个**流程型技能(Procedural Skill)**,通过 Desi
参数名必须完全一致,未知参数(如 `query`、`hasAttachments`)直接返回 400。返回 `{messages, total, offset, limit}`。
需要按正文或发件人在 Gmail 服务器上全文检索时,改用 `POST /gmail/messages/fetch?email=` 的 `query` 参数:它原样交给 Gmail API,支持 Gmail 搜索语法(如 `from:`、`has:attachment`),结果同时写入本地缓存。Outlook 与 IMAP 没有对应的远程检索参数。较旧的客户端若对 `/outlook/search` 或 `/imap/search` 返回 404,改为分页读取 `GET /{p}/messages` 后自行筛选。
需要按正文或发件人在 Gmail 服务器上全文检索时,改用 `POST /gmail/messages/fetch?email=` 的 `query` 参数:它原样交给 Gmail API,支持 Gmail 搜索语法(如 `from:`、`has:attachment`),结果同时写入本地缓存。Outlook 与 IMAP 没有对应的远程检索参数。
### 6. 附件下载
@@ -231,7 +237,7 @@ mail-operations 是一个**流程型技能(Procedural Skill)**,通过 Desi
| IMAP | POST | `/imap/attachment` | `{email, messageId, attachmentId, folder?}` |
- `attachmentId` 取自邮件详情的 `attachments[].id`,先调用详情接口拿到附件列表。
- IMAP:`messageId` 直接用列表返回的 `id`(如 `imap:12345`);`attachmentId` 是附件序号字符串(第一个附件为 `"0"`);`folder` 为服务器上的真实文件夹路径,INBOX 可省略。
- IMAP:`messageId` 原样用列表返回的 `id`(如 `imap:12345`);`attachmentId` 原样用 `attachments[].id`(如 `part:2`,也可能是 `"0"` 这样的序号,见第 3 节);`folder` 可省略,带文件夹键的 `id` 本地没有缓存时传条目的 `imapFolder`(见第 3 节)。
- **下载附件时必须给 `MailOperations` 传 `save_to`**(目标文件路径):工具在进程内完成 base64 解码并写入文件,只返回绝对路径、字节数与 SHA-256;不传 `save_to` 时附件响应会被工具拒绝返回。目标路径须位于允许写入的工作目录内。
- 端点原始响应为 `result: {data: <base64>, size}`;响应超过约 32MB 时工具会拒绝解析,此时按工具错误提示中的流式落盘办法处理,或请用户在邮箱页面手工导出附件。
@@ -241,7 +247,7 @@ mail-operations 是一个**流程型技能(Procedural Skill)**,通过 Desi
{
"path": "/api/imap/attachment",
"method": "POST",
"body": {"email": "me@example.com", "messageId": "imap:12345", "attachmentId": "0"},
"body": {"email": "me@example.com", "messageId": "imap:12345", "attachmentId": "part:2"},
"save_to": "./attachments/report.pdf"
}
```
@@ -377,7 +383,7 @@ Outlook 使用 Categories 而非 Labels。
| 操作 | 方法 | 端点 |
|------|------|------|
| IMAP 文件夹列表 | GET | `/imap/folders?email=` — 返回 `[{name, path, specialUse, flags}]`,IMAP 单封操作的 `folder` 使用其中的 `path` |
| IMAP 文件夹列表 | GET | `/imap/folders?email=` — 返回 `[{name, path, specialUse, flags}]`,`messages/fetch` 的 `folder` 可直接用其中的 `path` |
| Outlook 文件夹列表 | GET | `/outlook/folders?email=` |
> Gmail 文件夹固定:inbox, sent, drafts, trash, spam, archive。
@@ -389,8 +395,8 @@ Outlook 使用 Categories 而非 Labels。
邮件系统采用**本地缓存 + 定期轮询**:
- **写操作**(发送、标记、删除、Gmail 原生标签、Outlook 分类):通过对应 provider 端点同时更新本地和远程,无延迟;统一标签接口(第 8 节)和自动规则中的标记、删除、标签动作只修改本地
- **读操作**(查询、搜索):返回本地缓存,可能有延迟(默认 30 秒轮询)
- **远程变更**(用户在官方页面操作):Gmail / Outlook 需等待下次轮询同步;IMAP 轮询只拉取收件箱的新邮件,其他文件夹需主动调用 `messages/fetch`,服务器上对已缓存邮件做的已读、删除等变更不会回写到本地
- **读操作**(查询、搜索):返回本地缓存,可能有延迟。自动同步频率取账户设置的 `syncInterval`,单位为分钟(新账户默认 5;`0` 表示关闭自动同步,其余合法值为 1–1440,其他值更新设置时返回 400);需要立刻同步时调用 `POST /sync`
- **远程变更**(用户在官方页面操作):Gmail / Outlook 需等待下次轮询同步或调用 `POST /sync`;IMAP 的轮询和 `POST /sync` 都只拉取收件箱的新邮件,其他文件夹需主动调用 `messages/fetch`,服务器上对已缓存邮件做的已读、删除等变更不会回写到本地
**存储路径**:`${DESIRECORE_ROOT}/mail/{provider}/{email}/`(meta.json, index.json, messages/)
@@ -403,7 +409,26 @@ Outlook 使用 Categories 而非 Labels。
| 400 | 参数错误(包括参数放错位置,如把查询串参数放进 body) | 按 `msg` 检查参数名与位置 |
| 401 | Gmail/Outlook 授权失效、IMAP 账户未配置,或缺少 Mail Service capability | **按规则 1 处理**,不要尝试其他途径 |
| 404 | 资源不存在 | 先同步再重试(规则 3) |
| 404 | IMAP 邮件不在本地缓存(`error: imap_message_not_cached`) | 先 `messages/fetch` 该文件夹或取详情,再用结果里的 `id` 操作(见第 3 节) |
| 409 | IMAP 账户 SMTP 未验证(`error: smtp_unverified`) | 引导用户重新验证 SMTP(`POST /imap/accounts/verify-smtp`) |
| 409 | 传入的 `folder` 与 IMAP 带文件夹键的 `id` 所在文件夹不一致(`error: imap_folder_mismatch`),或文件夹已被服务器重建(`error: imap_uidvalidity_changed`) | 操作没有执行,不要原样重试;按第 3 节去掉 `folder`,或重新取信后用新的 `id` |
| 500 | 内部错误(IMAP 常见原因:`folder` 不是服务器上存在的文件夹) | 先检查 `folder`,仍失败则告知用户稍后重试 |
**IMAP 注意**:国内邮箱(QQ、163)需使用"授权码"而非登录密码。用 `/imap/test` 预先验证配置,并检查返回的 `result.imap.success` 与 `result.smtp.success`。
### 没有拿到完整响应时
`MailOperations` 最多等待 Mail Service 响应 20 分钟。没有拿到完整响应时,工具按请求走到了哪一步给出不同的提示:等待响应阶段的失败以 `Mail Service 请求失败:` 开头,已收到状态码、读正文时的失败以 `HTTP <状态码>` 开头。
| 提示中的关键句 | 含义 | 处理 |
|----------------|------|------|
| `等待 Mail Service 响应超过 20 分钟` | 等待超时,邮件服务端可能仍在处理这次请求 | 不要马上用相同参数重试;缩小批次(如 `messages/fetch` 的 `limit`)后再请求;写操作先核对结果 |
| `请求已被取消(运行中止)` | 运行被中止,请求可能已经送达 | 写操作先核对结果(范围见下文) |
| `请求未发出:运行已中止` | 运行已中止,请求没有发出 | 无需核对 |
| `无法连接 Mail Service` | 请求没有送达,邮件服务可能尚未启动或正在重启 | 稍后重试 |
| `与 Mail Service 的连接在请求途中断开` | 服务端可能已经处理了这次请求 | 写操作先核对结果(范围见下文);只读请求可以直接重试 |
| `Mail Service 已返回成功响应,但正文没有读完` | 这次请求已经处理完 | 写操作不要重做;`messages/fetch` 的结果已写入本地缓存,改用 `GET /{p}/messages` 分页读取,不要重新补拉;其他只读请求可以重新请求 |
| `Mail Service 返回了失败状态码,正文没有读完` | 以状态码为准,这次请求没有成功 | 按状态码处理 |
| `请求未能发出(不是网络问题)`、`GET 请求不能带 body` | 请求参数不匹配 | 检查 `path`、`method` 与 `body`;带 `body` 的请求要同时传 `method: "POST"` 等 |
Mail Service 不会因为客户端断开而停止处理:超时或中止之后,服务端可能照样把请求做完(`messages/fetch` 做完后照常写入本地缓存)。因此,请求可能已经送达时(等待超时、运行中止、途中断开、正文没读完),**除 GET、`messages/fetch` 与附件下载以外的请求都先核对结果,再决定是否重试**(如查已发送文件夹、重新取该文件夹、取详情,或列出草稿、规则、标签)。重放可能造成重复副作用的包括:发送、回复、删除、移动(含标记为垃圾邮件 / 不是垃圾邮件);创建草稿与发送草稿(IMAP 草稿保存不幂等,重放会多出一份草稿;发送草稿会再发一封);`/rules/execute`(`auto_reply` 会再发一次回复,`agent_handle` 会再次触发智能体);新建规则、标签、分类(重放会多建一条)。GET、`messages/fetch` 与附件下载可以重试(等待超时的除外,按上表缩小批次后再请求)。
@@ -31,13 +31,13 @@
},
"release": {
"state": "known",
"version": "1.1.0",
"version": "1.2.0",
"versionScheme": "semver"
},
"timestamps": {
"catalogUpdatedAt": {
"state": "known",
"value": "2026-10-05",
"value": "2026-10-28",
"precision": "day"
},
"releasePublishedAt": {
@@ -68,7 +68,7 @@
"platforms": {
"state": "unknown"
},
"requiredClientVersion": "10.0.178"
"requiredClientVersion": "10.0.180"
},
"spec": {
"kind": "skill",