feat: 添加邮件清理调度功能,优化邮件删除流程

This commit is contained in:
QLHazyCoder
2026-04-11 20:05:32 +08:00
parent 2b9b6e72ed
commit 28c151d109
+10 -4
View File
@@ -145,6 +145,14 @@ function getMailTimestamp(item) {
return null;
}
function scheduleEmailCleanup(item, step) {
setTimeout(() => {
Promise.resolve(deleteEmail(item, step)).catch(() => {
// Cleanup is best effort only and must never affect the main verification flow.
});
}, 0);
}
// ============================================================
// Email Polling
// ============================================================
@@ -242,10 +250,8 @@ async function handlePollEmail(step, payload) {
const timeLabel = mailTimestamp ? `,时间:${new Date(mailTimestamp).toLocaleString('zh-CN', { hour12: false })}` : '';
log(`步骤 ${step}:已找到验证码:${code}(来源:${source}${timeLabel},主题:${subject.slice(0, 40)}`, 'ok');
// Delete this email via right-click menu, WAIT for it to finish before returning
await deleteEmail(item, step);
// Extra wait to ensure deletion is processed
await sleep(1000);
// Trigger cleanup only as a best-effort side effect.
scheduleEmailCleanup(item, step);
return { ok: true, code, emailTimestamp: Date.now(), mailId: id };
} else if (code && seenCodes.has(code)) {