MCPcopy Create free account
hub / github.com/QLHazyCoder/FlowPilot / handlePollEmail

Function handlePollEmail

content/mail-2925.js:294–435  ·  view source on GitHub ↗
(step, payload)

Source from the content-addressed store, hash-verified

292}
293
294async function handlePollEmail(step, payload) {
295 const {
296 senderFilters,
297 subjectFilters,
298 maxAttempts,
299 intervalMs,
300 filterAfterTimestamp = 0,
301 excludeCodes = [],
302 strictChatGPTCodeOnly = false,
303 targetEmail = '',
304 } = payload;
305 const excludedCodeSet = new Set(excludeCodes.filter(Boolean));
306 const filterAfterMinute = normalizeMinuteTimestamp(Number(filterAfterTimestamp) || 0);
307
308 log(`步骤 ${step}:开始轮询 2925 邮箱(最多 ${maxAttempts} 次)`);
309 if (filterAfterMinute) {
310 log(`步骤 ${step}:仅尝试 ${new Date(filterAfterMinute).toLocaleString('zh-CN', { hour12: false })} 及之后时间的邮件。`);
311 }
312
313 let initialItems = [];
314 for (let i = 0; i < 20; i++) {
315 initialItems = findMailItems();
316 if (initialItems.length > 0) break;
317 await sleep(500);
318 }
319
320 if (initialItems.length === 0) {
321 await refreshInbox();
322 await sleep(2000);
323 initialItems = findMailItems();
324 }
325
326 if (initialItems.length === 0) {
327 throw new Error('2925 邮箱列表未加载完成,请确认当前已打开收件箱。');
328 }
329
330 const existingMailIds = getCurrentMailIds(initialItems);
331 log(`步骤 ${step}:邮件列表已加载,共 ${initialItems.length} 封邮件`);
332 log(`步骤 ${step}:已记录当前 ${existingMailIds.size} 封旧邮件快照`);
333
334 const FALLBACK_AFTER = 3;
335
336 for (let attempt = 1; attempt <= maxAttempts; attempt++) {
337 log(`步骤 ${step}:正在轮询 2925 邮箱,第 ${attempt}/${maxAttempts} 次`);
338
339 if (attempt > 1) {
340 await refreshInbox();
341 await sleepRandom(900, 1500);
342 }
343
344 const items = findMailItems();
345 if (items.length > 0) {
346 const useFallback = attempt > FALLBACK_AFTER;
347
348 for (let index = 0; index < items.length; index++) {
349 const item = items[index];
350 const itemId = getMailItemId(item, index);
351 const itemTimestamp = parseMailItemTimestamp(item);

Callers 1

mail-2925.jsFile · 0.70

Calls 15

logFunction · 0.85
sleepFunction · 0.85
sleepRandomFunction · 0.85
getMailItemIdFunction · 0.85
parseMailItemTimestampFunction · 0.85
getMailItemTextFunction · 0.85
matchesMailFiltersFunction · 0.85
extractEmailsFunction · 0.85
simulateClickFunction · 0.85
normalizeMinuteTimestampFunction · 0.70
findMailItemsFunction · 0.70
refreshInboxFunction · 0.70

Tested by

no test coverage detected