(step, state, pollPayload = {})
| 1802 | } |
| 1803 | |
| 1804 | async function pollHotmailVerificationCode(step, state, pollPayload = {}) { |
| 1805 | await addLog(`步骤 ${step}:正在确定 Hotmail 收信账号...`, 'info'); |
| 1806 | let account = await ensureHotmailAccountForFlow({ |
| 1807 | allowAllocate: true, |
| 1808 | markUsed: false, |
| 1809 | preferredAccountId: state.currentHotmailAccountId || null, |
| 1810 | }); |
| 1811 | await addLog(`步骤 ${step}:当前使用 Hotmail 账号 ${account.email} 轮询收件箱。`, 'info'); |
| 1812 | |
| 1813 | const serviceSettings = getHotmailServiceSettings(state); |
| 1814 | if (serviceSettings.mode === HOTMAIL_SERVICE_MODE_LOCAL) { |
| 1815 | return pollHotmailVerificationCodeViaLocalHelper(step, account, pollPayload); |
| 1816 | } |
| 1817 | |
| 1818 | const maxAttempts = Number(pollPayload.maxAttempts) || 5; |
| 1819 | const intervalMs = Number(pollPayload.intervalMs) || 3000; |
| 1820 | let lastError = null; |
| 1821 | |
| 1822 | function summarizeMessagesForLog(messages) { |
| 1823 | return (messages || []) |
| 1824 | .slice() |
| 1825 | .sort((left, right) => { |
| 1826 | const leftTime = Date.parse(left.receivedDateTime || '') || 0; |
| 1827 | const rightTime = Date.parse(right.receivedDateTime || '') || 0; |
| 1828 | return rightTime - leftTime; |
| 1829 | }) |
| 1830 | .slice(0, 3) |
| 1831 | .map((message) => { |
| 1832 | const receivedAt = message?.receivedDateTime || '未知时间'; |
| 1833 | const sender = message?.from?.emailAddress?.address || '未知发件人'; |
| 1834 | const subject = message?.subject || '(无主题)'; |
| 1835 | const preview = String(message?.bodyPreview || '').replace(/\s+/g, ' ').trim().slice(0, 80); |
| 1836 | return `[${message.mailbox || 'INBOX'}] ${receivedAt} | ${sender} | ${subject} | ${preview}`; |
| 1837 | }) |
| 1838 | .join(' || '); |
| 1839 | } |
| 1840 | |
| 1841 | for (let attempt = 1; attempt <= maxAttempts; attempt++) { |
| 1842 | throwIfStopped(); |
| 1843 | try { |
| 1844 | await addLog(`步骤 ${step}:正在通过 API对接 轮询 Hotmail 邮件(${attempt}/${maxAttempts})...`, 'info'); |
| 1845 | const fetchResult = await fetchHotmailMailboxMessages(account, HOTMAIL_MAILBOXES); |
| 1846 | account = fetchResult.account; |
| 1847 | const matchResult = pickVerificationMessageWithTimeFallback(fetchResult.messages, { |
| 1848 | afterTimestamp: pollPayload.filterAfterTimestamp || 0, |
| 1849 | senderFilters: pollPayload.senderFilters || [], |
| 1850 | subjectFilters: pollPayload.subjectFilters || [], |
| 1851 | excludeCodes: pollPayload.excludeCodes || [], |
| 1852 | }); |
| 1853 | const match = matchResult.match; |
| 1854 | |
| 1855 | if (match?.code) { |
| 1856 | const mailboxLabel = match.message?.mailbox || 'INBOX'; |
| 1857 | if (matchResult.usedRelaxedFilters) { |
| 1858 | const fallbackLabel = matchResult.usedTimeFallback ? '宽松匹配 + 时间回退' : '宽松匹配'; |
| 1859 | await addLog(`步骤 ${step}:严格规则未命中,已改用 ${fallbackLabel} 并命中 Hotmail ${mailboxLabel} 验证码。`, 'warn'); |
| 1860 | } |
| 1861 | await addLog(`步骤 ${step}:已通过 API对接 在 Hotmail ${mailboxLabel} 中找到验证码:${match.code}`, 'ok'); |
no test coverage detected