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

Function requestHotmailLocalMessages

background.js:1551–1634  ·  view source on GitHub ↗
(account, mailboxes = HOTMAIL_MAILBOXES)

Source from the content-addressed store, hash-verified

1549}
1550
1551async function requestHotmailLocalMessages(account, mailboxes = HOTMAIL_MAILBOXES) {
1552 if (!account?.email) {
1553 throw new Error('Hotmail 账号缺少邮箱地址。');
1554 }
1555 if (!account?.clientId) {
1556 throw new Error(`Hotmail 账号 ${account.email || account.id} 缺少客户端 ID。`);
1557 }
1558 if (!account?.refreshToken) {
1559 throw new Error(`Hotmail 账号 ${account.email || account.id} 缺少刷新令牌(refresh token)。`);
1560 }
1561
1562 const serviceSettings = getHotmailServiceSettings(await getState());
1563 const { timeoutMs } = getHotmailMailApiRequestConfig();
1564 const requestTimeoutMs = Math.max(timeoutMs, HOTMAIL_LOCAL_HELPER_TIMEOUT_MS);
1565 const controller = new AbortController();
1566 const timeoutId = setTimeout(() => controller.abort(new Error('timeout')), requestTimeoutMs);
1567
1568 let response;
1569 try {
1570 response = await fetch(buildHotmailLocalEndpoint(serviceSettings.localBaseUrl, '/messages'), {
1571 method: 'POST',
1572 headers: {
1573 'Content-Type': 'application/json',
1574 Accept: 'application/json',
1575 },
1576 body: JSON.stringify({
1577 email: account.email,
1578 clientId: account.clientId,
1579 refreshToken: account.refreshToken,
1580 mailboxes,
1581 top: 5,
1582 }),
1583 signal: controller.signal,
1584 });
1585 } catch (err) {
1586 if (err?.name === 'AbortError') {
1587 throw new Error(`Hotmail 本地助手请求超时(>${Math.round(requestTimeoutMs / 1000)} 秒)`);
1588 }
1589 throw new Error(`Hotmail 本地助手请求失败:${err.message}`);
1590 } finally {
1591 clearTimeout(timeoutId);
1592 }
1593
1594 const text = await response.text();
1595 let payload = {};
1596 try {
1597 payload = text ? JSON.parse(text) : {};
1598 } catch {
1599 payload = { raw: text };
1600 }
1601
1602 if (!response.ok || payload?.ok === false) {
1603 const errorText = payload?.error || payload?.message || text || `HTTP ${response.status}`;
1604 throw new Error(`Hotmail 本地助手返回失败:${errorText}`);
1605 }
1606
1607 const rawMessages = Array.isArray(payload?.messages) ? payload.messages : [];
1608 const normalizedMessages = normalizeHotmailMailApiMessages(rawMessages).map((message, index) => ({

Callers 1

Calls 7

getStateFunction · 0.85
upsertHotmailAccountFunction · 0.85

Tested by

no test coverage detected