feat(mail): 发信成功后归档到已发送(Sent)文件夹

Stalwart 不会自动把草稿移到 Sent,EmailSubmission 成功后显式 Email/set update mailboxIds 移至 Sent
This commit is contained in:
TermiNexus committed 2026-08-08 15:00:34 +08:00
1 parent 03fd87df13
commit 600ca27cbb
1 file changed
+12 -1
+12 -1
View File
@@ -151,6 +151,7 @@ export class JmapClient {
}): Promise<void> {
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<string, unknown> = {
@@ -188,12 +189,14 @@ export class JmapClient {
])
const [, created] = result.methodResponses[0] || []
const createdData = created as unknown as { created?: Record<string, unknown> }
const createdData = created as unknown as { created?: Record<string, { id?: string }> }
if (!createdData?.created) {
const err = created as unknown as { notCreated?: Record<string, unknown> }
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']])
}
}
}