You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
/**
* 一次<E4B880> ?IMAP 真拉取:优先读设置页绑定的邮箱,否则 .env
* pnpm imap:poll
*/
import { getEnv , resetEnvCache } from "../src/lib/env" ;
import { hasConfiguredMailbox } from "../src/services/imap/mailbox-config" ;
import { ImapPoller } from "../src/services/imap/poller" ;
import { readImapRuntimeStatus } from "../src/services/imap/runtime-status" ;
import { prisma } from "../src/services/db" ;
async function main() {
resetEnvCache ( ) ;
const env = getEnv ( ) ;
const configured = await hasConfiguredMailbox ( ) ;
const dbCount = await prisma . mailboxAccount . count ( { where : { enabled : true } } ) ;
console . log (
JSON . stringify (
{
dbEnabledMailboxes : dbCount ,
envUser : env.IMAP_USER || "(empty)" ,
configured ,
} ,
null ,
2 ,
) ,
) ;
if ( ! configured ) {
console . error (
" 无 可 用 邮 箱 : 请 在 「 设 <EFBFBD> ? <EFBFBD> ? 邮 箱 绑 定 」 配 置 , 或 填 <EFBFBD> ? . env <EFBFBD> ? IMAP_USER / IMAP_PASS <EFBFBD> ? ,
) ;
process . exit ( 1 ) ;
}
await ImapPoller . clearStaleLock ( ) ;
try {
const result = await ImapPoller . create ( ) . tick ( 30 ) ;
const runtime = await readImapRuntimeStatus ( ) ;
console . log ( JSON . stringify ( { result , runtime } , null , 2 ) ) ;
} catch ( err ) {
const runtime = await readImapRuntimeStatus ( ) ;
console . error ( err ) ;
console . error ( JSON . stringify ( { runtime } , null , 2 ) ) ;
process . exit ( 2 ) ;
} finally {
await prisma . $disconnect ( ) ;
}
}
main ( ) ;