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

Function handlePollEmail

content/mail-163.js:160–276  ·  view source on GitHub ↗
(step, payload)

Source from the content-addressed store, hash-verified

158// ============================================================
159
160async function handlePollEmail(step, payload) {
161 const { senderFilters, subjectFilters, maxAttempts, intervalMs, excludeCodes = [], filterAfterTimestamp = 0 } = payload;
162 const excludedCodeSet = new Set(excludeCodes.filter(Boolean));
163 const filterAfterMinute = normalizeMinuteTimestamp(Number(filterAfterTimestamp) || 0);
164
165 log(`步骤 ${step}:开始轮询 163 邮箱(最多 ${maxAttempts} 次)`);
166 if (filterAfterMinute) {
167 log(`步骤 ${step}:仅尝试 ${new Date(filterAfterMinute).toLocaleString('zh-CN', { hour12: false })} 及之后时间的邮件。`);
168 }
169
170 // Click inbox in sidebar to ensure we're in inbox view
171 log(`步骤 ${step}:正在等待侧边栏加载...`);
172 try {
173 const inboxLink = await waitForElement('.nui-tree-item-text[title="收件箱"]', 5000);
174 inboxLink.click();
175 log(`步骤 ${step}:已点击收件箱`);
176 } catch {
177 log(`步骤 ${step}:未找到收件箱入口,继续尝试后续流程...`, 'warn');
178 }
179
180 // Wait for mail list to appear
181 log(`步骤 ${step}:正在等待邮件列表加载...`);
182 let items = [];
183 for (let i = 0; i < 20; i++) {
184 items = findMailItems();
185 if (items.length > 0) break;
186 await sleep(500);
187 }
188
189 if (items.length === 0) {
190 await refreshInbox();
191 await sleep(2000);
192 items = findMailItems();
193 }
194
195 if (items.length === 0) {
196 throw new Error('163 邮箱列表未加载完成,请确认当前已打开收件箱。');
197 }
198
199 log(`步骤 ${step}:邮件列表已加载,共 ${items.length} 封邮件`);
200
201 // Snapshot existing mail IDs
202 const existingMailIds = getCurrentMailIds();
203 log(`步骤 ${step}:已记录当前 ${existingMailIds.size} 封旧邮件快照`);
204
205 const FALLBACK_AFTER = 3;
206
207 for (let attempt = 1; attempt <= maxAttempts; attempt++) {
208 log(`步骤 ${step}:正在轮询 163 邮箱,第 ${attempt}/${maxAttempts} 次`);
209
210 if (attempt > 1) {
211 await refreshInbox();
212 await sleep(1000);
213 }
214
215 const allItems = findMailItems();
216 const useFallback = attempt > FALLBACK_AFTER;
217

Callers 1

mail-163.jsFile · 0.70

Calls 11

logFunction · 0.85
waitForElementFunction · 0.85
sleepFunction · 0.85
getMailTimestampFunction · 0.85
scheduleEmailCleanupFunction · 0.85
normalizeMinuteTimestampFunction · 0.70
findMailItemsFunction · 0.70
refreshInboxFunction · 0.70
getCurrentMailIdsFunction · 0.70
extractVerificationCodeFunction · 0.70
persistSeenCodesFunction · 0.70

Tested by

no test coverage detected