feat: 更新2925邮箱处理逻辑,增强验证码重发机制,调整测试用例

This commit is contained in:
QLHazyCoder
2026-04-20 13:15:39 +08:00
parent 8a16d81e01
commit ffecba6ab3
8 changed files with 108 additions and 48 deletions
+5 -31
View File
@@ -53,6 +53,10 @@ async function persistSeenCodes() {
}
function buildSeenCodeSessionKey(step, payload = {}) {
const explicitSessionKey = String(payload?.sessionKey || '').trim();
if (explicitSessionKey) {
return explicitSessionKey;
}
const timestamp = Number(payload?.filterAfterTimestamp);
if (Number.isFinite(timestamp) && timestamp > 0) {
return `${step}:${timestamp}`;
@@ -551,11 +555,7 @@ async function handlePollEmail(step, payload) {
throw new Error('2925 邮箱列表未加载完成,请确认当前已打开收件箱。');
}
const knownMailIds = getCurrentMailIds(initialItems);
log(`步骤 ${step}:邮件列表已加载,共 ${initialItems.length} 封邮件`);
log(`步骤 ${step}:已记录当前 ${knownMailIds.size} 封旧邮件快照`);
const FALLBACK_AFTER = 3;
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
log(`步骤 ${step}:正在轮询 2925 邮箱,第 ${attempt}/${maxAttempts}`);
@@ -568,26 +568,10 @@ async function handlePollEmail(step, payload) {
const items = findMailItems();
if (items.length > 0) {
const useFallback = attempt > FALLBACK_AFTER;
const newMailIds = new Set();
items.forEach((item, index) => {
const itemId = getMailItemId(item, index);
if (!knownMailIds.has(itemId)) {
newMailIds.add(itemId);
}
});
for (let index = 0; index < items.length; index += 1) {
const item = items[index];
const itemId = getMailItemId(item, index);
const isNewMail = newMailIds.has(itemId);
const itemTimestamp = parseMailItemTimestamp(item);
if (!useFallback && !isNewMail) {
continue;
}
const previewText = getMailItemText(item);
if (!matchesMailFilters(previewText, senderFilters, subjectFilters)) {
continue;
@@ -613,21 +597,11 @@ async function handlePollEmail(step, payload) {
seenCodes.add(candidateCode);
persistSeenCodes();
const source = useFallback && !isNewMail
? (bodyCode ? '回退匹配邮件正文' : '回退匹配邮件')
: (bodyCode ? '新邮件正文' : '新邮件');
const source = bodyCode ? '邮件正文' : '邮件预览';
const timeLabel = itemTimestamp ? `,时间:${new Date(itemTimestamp).toLocaleString('zh-CN', { hour12: false })}` : '';
log(`步骤 ${step}:已找到验证码:${candidateCode}(来源:${source}${timeLabel}`, 'ok');
return { ok: true, code: candidateCode, emailTimestamp: Date.now() };
}
items.forEach((item, index) => {
knownMailIds.add(getMailItemId(item, index));
});
}
if (attempt === FALLBACK_AFTER + 1) {
log(`步骤 ${step}:连续 ${FALLBACK_AFTER} 次未发现新邮件,开始回退到首封匹配邮件`, 'warn');
}
if (attempt < maxAttempts) {