/** * 仅测 IMAP 连通:登录 + SEARCH UNSEEN,不落库�? * pnpm imap:smoke */ import { getEnv, resetEnvCache } from "../src/lib/env"; import { createImapClient, hasImapCredentials, } from "../src/services/imap/client"; async function main() { resetEnvCache(); const env = getEnv(); if (!hasImapCredentials()) { console.error("缺少 IMAP_USER / IMAP_PASS"); process.exit(1); } const client = createImapClient(); if (!client) { console.error("createImapClient returned null"); process.exit(1); } console.log(`connecting ${env.IMAP_HOST}:${env.IMAP_PORT} as ${env.IMAP_USER}`); try { await client.connect(); const unseen = await client.fetchUnseen(); console.log( JSON.stringify( { ok: true, unseen: unseen.length, samples: unseen.slice(0, 5).map((m) => ({ uid: m.uid, subject: m.envelope?.subject, from: m.envelope?.from?.[0]?.address, messageId: m.envelope?.messageId, })), }, null, 2, ), ); } catch (err) { console.error("IMAP smoke failed:", err); process.exit(2); } finally { await client.disconnect().catch(() => undefined); } } main();