IMAP 同步邮箱和消息
目的:将 IMAP 同步作业排入队列并保留消息元数据以供搜索和读取流。
用户界面流程
- 用户选择凭证和文件夹。
- UI 将邮箱同步或消息同步排队。
- UI 轮询作业/任务的最终状态。
- UI 刷新
/api/accounts/:account_id/emails。
客户端库流程
const mailboxTask = await api.provider.imap.syncMailboxes(accountId, {
credential_id: imapCredentialId,
});
const messageTask = await api.provider.imap.syncMessages(accountId, {
credential_id: imapCredentialId,
folder: "INBOX",
});
await api.jobs.waitForTask(accountId, messageTask.data.task_id);
const emails = await api.emails.list(accountId, { limit: 20, offset: 0 });
HTTP/curl 流程
API_BASE_URL="https://api.inbox-manager.com"
curl -sS -X POST "${API_BASE_URL}/api/accounts/${ACCOUNT_ID}/imap/sync-mailboxes" \
-H "authorization: Bearer ${BEARER_TOKEN}" \
-H "content-type: application/json" \
--data "{\"credential_id\":\"${IMAP_CREDENTIAL_ID}\"}"
curl -sS -X POST "${API_BASE_URL}/api/accounts/${ACCOUNT_ID}/imap/sync-messages" \
-H "authorization: Bearer ${BEARER_TOKEN}" \
-H "content-type: application/json" \
--data "{\"credential_id\":\"${IMAP_CREDENTIAL_ID}\",\"folder\":\"INBOX\"}"
curl -sS "${API_BASE_URL}/api/accounts/${ACCOUNT_ID}/jobs?limit=20" \
-H "authorization: Bearer ${BEARER_TOKEN}"
curl -sS "${API_BASE_URL}/api/accounts/${ACCOUNT_ID}/emails?limit=20&offset=0" \
-H "authorization: Bearer ${BEARER_TOKEN}"
验证脚本
scripts/provider_job_flow.sh