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

Function requestHotmailRemoteMailbox

background.js:1454–1499  ·  view source on GitHub ↗
(account, mailbox = 'INBOX')

Source from the content-addressed store, hash-verified

1452}
1453
1454async function requestHotmailRemoteMailbox(account, mailbox = 'INBOX') {
1455 if (!account?.email) {
1456 throw new Error('Hotmail 账号缺少邮箱地址。');
1457 }
1458 if (!account?.clientId) {
1459 throw new Error(`Hotmail 账号 ${account.email || account.id} 缺少客户端 ID。`);
1460 }
1461 if (!account?.refreshToken) {
1462 throw new Error(`Hotmail 账号 ${account.email || account.id} 缺少刷新令牌(refresh token)。`);
1463 }
1464
1465 const { timeoutMs } = getHotmailMailApiRequestConfig();
1466 const controller = new AbortController();
1467 const timeoutId = setTimeout(() => controller.abort(new Error('timeout')), timeoutMs);
1468
1469 try {
1470 const result = await fetchMicrosoftMailboxMessages({
1471 clientId: account.clientId,
1472 refreshToken: account.refreshToken,
1473 mailbox,
1474 top: 10,
1475 signal: controller.signal,
1476 });
1477
1478 return {
1479 mailbox,
1480 payload: {
1481 source: 'microsoft-api',
1482 transport: result.transport,
1483 tokenStrategy: result.tokenStrategy,
1484 },
1485 messages: normalizeHotmailMailApiMessages(result.messages).map((message) => ({
1486 ...message,
1487 mailbox: message?.mailbox || mailbox,
1488 })),
1489 nextRefreshToken: result.nextRefreshToken,
1490 };
1491 } catch (err) {
1492 if (err?.name === 'AbortError') {
1493 throw new Error(`Hotmail API 对接请求超时(>${Math.round(timeoutMs / 1000)} 秒):${mailbox}`);
1494 }
1495 throw new Error(`Hotmail API 对接请求失败:${err.message}`);
1496 } finally {
1497 clearTimeout(timeoutId);
1498 }
1499}
1500
1501function applyHotmailApiResultToAccount(account, apiResult) {
1502 const nextRefreshToken = String(apiResult?.nextRefreshToken || '').trim();

Tested by

no test coverage detected