From 600ca27cbb8b53f39be2541e7815b5afae2e3ccf Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Sat, 8 Aug 2026 15:00:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(mail):=20=E5=8F=91=E4=BF=A1=E6=88=90?= =?UTF-8?q?=E5=8A=9F=E5=90=8E=E5=BD=92=E6=A1=A3=E5=88=B0=E5=B7=B2=E5=8F=91?= =?UTF-8?q?=E9=80=81=EF=BC=88Sent=EF=BC=89=E6=96=87=E4=BB=B6=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stalwart 不会自动把草稿移到 Sent,EmailSubmission 成功后显式 Email/set update mailboxIds 移至 Sent --- src/utils/jmap.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/utils/jmap.ts b/src/utils/jmap.ts index f31da0a..5f3b917 100644 --- a/src/utils/jmap.ts +++ b/src/utils/jmap.ts @@ -151,6 +151,7 @@ export class JmapClient { }): Promise { const mailboxes = await this.getMailboxes() const drafts = mailboxes.find((m) => m.role === 'drafts') || mailboxes[0] + const sent = mailboxes.find((m) => m.role === 'sent') const identityId = await this.getIdentityId() const emailData: Record = { @@ -188,12 +189,14 @@ export class JmapClient { ]) const [, created] = result.methodResponses[0] || [] - const createdData = created as unknown as { created?: Record } + const createdData = created as unknown as { created?: Record } if (!createdData?.created) { const err = created as unknown as { notCreated?: Record } const firstErr = Object.values(err.notCreated || {})[0] as { type?: string; description?: string } | undefined throw new Error(firstErr?.description || '创建邮件失败') } + const emailId = createdData.created.d1?.id + if (!emailId) throw new Error('创建邮件失败:未返回邮件 ID') // 检查 EmailSubmission/set 结果(methodResponses[1]):Email/set 成功不代表已投递 const [, submitted] = result.methodResponses[1] || [] @@ -202,5 +205,13 @@ export class JmapClient { const subErr = Object.values(submittedData?.notCreated || {})[0] as { type?: string; description?: string } | undefined throw new Error(subErr?.description || '邮件发送失败') } + + // 发件成功后归档到「已发送」:Stalwart 不会自动把草稿移到 Sent,需显式移动 + if (sent) { + await this.request([['Email/set', { + accountId: this.accountId, + update: { [emailId]: { mailboxIds: { [sent.id]: true } } }, + }, 'c3']]) + } } }