feat: 添加2925邮箱会话确保逻辑,优化邮箱轮询验证码流程

This commit is contained in:
QLHazyCoder
2026-04-23 00:33:16 +08:00
parent 9b4feea87c
commit c906e4434d
2 changed files with 50 additions and 5 deletions
+25
View File
@@ -9,6 +9,7 @@
chrome, chrome,
CLOUDFLARE_TEMP_EMAIL_PROVIDER, CLOUDFLARE_TEMP_EMAIL_PROVIDER,
confirmCustomVerificationStepBypass, confirmCustomVerificationStepBypass,
ensureMail2925MailboxSession,
ensureStep8VerificationPageReady, ensureStep8VerificationPageReady,
getOAuthFlowRemainingMs, getOAuthFlowRemainingMs,
getOAuthFlowStepTimeoutMs, getOAuthFlowStepTimeoutMs,
@@ -57,6 +58,20 @@
return String(value || '').trim().toLowerCase(); return String(value || '').trim().toLowerCase();
} }
function getExpectedMail2925MailboxEmail(state = {}) {
if (Boolean(state?.mail2925UseAccountPool)) {
const currentAccountId = String(state?.currentMail2925AccountId || '').trim();
const accounts = Array.isArray(state?.mail2925Accounts) ? state.mail2925Accounts : [];
const currentAccount = accounts.find((account) => String(account?.id || '') === currentAccountId) || null;
const accountEmail = String(currentAccount?.email || '').trim().toLowerCase();
if (accountEmail) {
return accountEmail;
}
}
return String(state?.mail2925BaseEmail || '').trim().toLowerCase();
}
async function focusOrOpenMailTab(mail) { async function focusOrOpenMailTab(mail) {
const alive = await isTabAlive(mail.source); const alive = await isTabAlive(mail.source);
if (alive) { if (alive) {
@@ -134,7 +149,17 @@
await addLog(`步骤 8:正在通过 ${mail.label} 轮询验证码...`); await addLog(`步骤 8:正在通过 ${mail.label} 轮询验证码...`);
} else { } else {
await addLog(`步骤 8:正在打开${mail.label}...`); await addLog(`步骤 8:正在打开${mail.label}...`);
if (mail.provider === '2925' && typeof ensureMail2925MailboxSession === 'function') {
await ensureMail2925MailboxSession({
accountId: state.currentMail2925AccountId || null,
forceRelogin: false,
allowLoginWhenOnLoginPage: Boolean(state?.mail2925UseAccountPool),
expectedMailboxEmail: getExpectedMail2925MailboxEmail(state),
actionLabel: 'Step 8: ensure 2925 mailbox session',
});
} else {
await focusOrOpenMailTab(mail); await focusOrOpenMailTab(mail);
}
if (mail.provider === '2925') { if (mail.provider === '2925') {
await addLog(`步骤 8:将直接使用当前已登录的 ${mail.label} 轮询验证码。`, 'info'); await addLog(`步骤 8:将直接使用当前已登录的 ${mail.label} 轮询验证码。`, 'info');
} }
+24 -4
View File
@@ -92,6 +92,7 @@ test('step 8 submits login verification directly without replaying step 7', asyn
test('step 8 uses a fixed 10-minute lookback window and disables resend interval for 2925 mailbox polling', async () => { test('step 8 uses a fixed 10-minute lookback window and disables resend interval for 2925 mailbox polling', async () => {
let capturedOptions = null; let capturedOptions = null;
let ensureCalls = 0; let ensureCalls = 0;
let ensureOptions = null;
const tabUpdates = []; const tabUpdates = [];
const tabReuses = []; const tabReuses = [];
const realDateNow = Date.now; const realDateNow = Date.now;
@@ -108,8 +109,9 @@ test('step 8 uses a fixed 10-minute lookback window and disables resend interval
}, },
CLOUDFLARE_TEMP_EMAIL_PROVIDER: 'cloudflare-temp-email', CLOUDFLARE_TEMP_EMAIL_PROVIDER: 'cloudflare-temp-email',
confirmCustomVerificationStepBypass: async () => {}, confirmCustomVerificationStepBypass: async () => {},
ensureMail2925MailboxSession: async () => { ensureMail2925MailboxSession: async (options) => {
ensureCalls += 1; ensureCalls += 1;
ensureOptions = options;
}, },
ensureStep8VerificationPageReady: async () => ({ state: 'verification_page' }), ensureStep8VerificationPageReady: async () => ({ state: 'verification_page' }),
rerunStep7ForStep8Recovery: async () => {}, rerunStep7ForStep8Recovery: async () => {},
@@ -122,7 +124,15 @@ test('step 8 uses a fixed 10-minute lookback window and disables resend interval
url: 'https://2925.com', url: 'https://2925.com',
navigateOnReuse: false, navigateOnReuse: false,
}), }),
getState: async () => ({ email: 'user@example.com', password: 'secret' }), getState: async () => ({
email: 'user@example.com',
password: 'secret',
mail2925UseAccountPool: true,
currentMail2925AccountId: 'acc-1',
mail2925Accounts: [
{ id: 'acc-1', email: 'pool-user@2925.com' },
],
}),
getTabId: async (sourceName) => (sourceName === 'signup-page' ? 1 : 2), getTabId: async (sourceName) => (sourceName === 'signup-page' ? 1 : 2),
HOTMAIL_PROVIDER: 'hotmail-api', HOTMAIL_PROVIDER: 'hotmail-api',
isTabAlive: async () => true, isTabAlive: async () => true,
@@ -148,16 +158,26 @@ test('step 8 uses a fixed 10-minute lookback window and disables resend interval
password: 'secret', password: 'secret',
oauthUrl: 'https://oauth.example/latest', oauthUrl: 'https://oauth.example/latest',
mail2925UseAccountPool: true, mail2925UseAccountPool: true,
currentMail2925AccountId: 'acc-1',
mail2925Accounts: [
{ id: 'acc-1', email: 'pool-user@2925.com' },
],
}); });
} finally { } finally {
Date.now = realDateNow; Date.now = realDateNow;
} }
assert.equal(ensureCalls, 0); assert.equal(ensureCalls, 1);
assert.deepStrictEqual(ensureOptions, {
accountId: 'acc-1',
forceRelogin: false,
allowLoginWhenOnLoginPage: true,
expectedMailboxEmail: 'pool-user@2925.com',
actionLabel: 'Step 8: ensure 2925 mailbox session',
});
assert.deepStrictEqual(tabReuses, []); assert.deepStrictEqual(tabReuses, []);
assert.deepStrictEqual(tabUpdates, [ assert.deepStrictEqual(tabUpdates, [
{ tabId: 1, payload: { active: true } }, { tabId: 1, payload: { active: true } },
{ tabId: 2, payload: { active: true } },
]); ]);
assert.equal(capturedOptions.filterAfterTimestamp, 300000); assert.equal(capturedOptions.filterAfterTimestamp, 300000);
assert.equal(capturedOptions.resendIntervalMs, 0); assert.equal(capturedOptions.resendIntervalMs, 0);