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']]) + } } }