MCPcopy Index your code
hub / github.com/QLHazyCoder/FlowPilot / pollCloudflareTempEmailVerificationCode

Function pollCloudflareTempEmailVerificationCode

background.js:2720–2788  ·  view source on GitHub ↗
(step, state, pollPayload = {})

Source from the content-addressed store, hash-verified

2718}
2719
2720async function pollCloudflareTempEmailVerificationCode(step, state, pollPayload = {}) {
2721 const config = ensureCloudflareTempEmailConfig(state, { requireAdminAuth: true });
2722 const targetEmail = resolveCloudflareTempEmailPollTargetEmail(state, pollPayload, config);
2723 const registrationEmail = normalizeCloudflareTempEmailReceiveMailbox(state.email);
2724 if (!targetEmail) {
2725 throw new Error('Cloudflare Temp Email 轮询前缺少目标邮箱地址,请先填写注册邮箱或“邮件接收”邮箱。');
2726 }
2727
2728 if (registrationEmail && registrationEmail !== targetEmail) {
2729 await addLog(`步骤 ${step}:正在轮询 Cloudflare Temp Email 收件邮箱(${targetEmail}),注册邮箱为 ${registrationEmail}...`, 'info');
2730 } else {
2731 await addLog(`步骤 ${step}:正在轮询 Cloudflare Temp Email 邮件(${targetEmail})...`, 'info');
2732 }
2733 const maxAttempts = Number(pollPayload.maxAttempts) || 5;
2734 const intervalMs = Number(pollPayload.intervalMs) || 3000;
2735 let lastError = null;
2736
2737 for (let attempt = 1; attempt <= maxAttempts; attempt++) {
2738 throwIfStopped();
2739 try {
2740 const { messages } = await listCloudflareTempEmailMessages(state, {
2741 address: targetEmail,
2742 limit: pollPayload.limit || CLOUDFLARE_TEMP_EMAIL_DEFAULT_PAGE_SIZE,
2743 offset: pollPayload.offset || 0,
2744 });
2745 const matchResult = pickVerificationMessageWithTimeFallback(messages, {
2746 afterTimestamp: pollPayload.filterAfterTimestamp || 0,
2747 senderFilters: pollPayload.senderFilters || [],
2748 subjectFilters: pollPayload.subjectFilters || [],
2749 excludeCodes: pollPayload.excludeCodes || [],
2750 });
2751 const match = matchResult.match;
2752
2753 if (match?.code) {
2754 if (matchResult.usedRelaxedFilters) {
2755 const fallbackLabel = matchResult.usedTimeFallback ? '宽松匹配 + 时间回退' : '宽松匹配';
2756 await addLog(`步骤 ${step}:严格规则未命中,已改用 ${fallbackLabel} 并命中 Cloudflare Temp Email 验证码。`, 'warn');
2757 }
2758 try {
2759 await deleteCloudflareTempEmailMail(config, match.message?.id);
2760 } catch (err) {
2761 await addLog(`步骤 ${step}:删除 Cloudflare Temp Email 邮件失败:${err.message}`, 'warn');
2762 }
2763 return {
2764 ok: true,
2765 code: match.code,
2766 emailTimestamp: match.receivedAt || Date.now(),
2767 mailId: match.message?.id || '',
2768 };
2769 }
2770
2771 lastError = new Error(`步骤 ${step}:暂未在 Cloudflare Temp Email 中找到匹配验证码(${attempt}/${maxAttempts})。`);
2772 await addLog(lastError.message, attempt === maxAttempts ? 'warn' : 'info');
2773 const sample = summarizeCloudflareTempEmailMessagesForLog(messages);
2774 if (sample) {
2775 await addLog(`步骤 ${step}:最近邮件样本:${sample}`, 'info');
2776 }
2777 } catch (err) {

Callers 1

Tested by

no test coverage detected