/** * IMAP IDLE Watcher — real-time email monitoring. * * Maintains dedicated IMAP connections per account using IDLE to detect * new emails in real-time. Emits events on the shared event bus. * * Key design decisions: * - Separate ImapFlow connections from ConnectionManager (IDLE holds lock) * - Auto-reconnect with exponential backoff on connection failures * - Tracks last-seen UID per folder to detect genuinely new messages */ import type { AccountConfig, WatcherConfig } from '../types/index.js'; import type OAuthService from './oauth.service.js'; export interface WatcherStatus { account: string; folder: string; connected: boolean; lastSeenUid: number; } export default class WatcherService { private idleStates; private config; private accounts; private oauthService?; constructor(config: WatcherConfig, accounts: AccountConfig[], oauthService?: OAuthService); /** * IMAP credentials for an account, exchanging the refresh token for an * access token when the account uses OAuth2. * * The watcher builds its own connections rather than borrowing the pooled * ones, because IDLE holds the mailbox lock — so it also has to do its own * auth. It previously passed `account.password` as the access token, which * is undefined for an OAuth account, so IDLE could never authenticate and * the verification catcher and hooks were silently dead for exactly the * users Google and Microsoft are moving onto OAuth. */ private static buildAuth; start(): Promise; stop(): Promise; getStatus(): WatcherStatus[]; private static stateKey; private updateState; private startIdle; private connectIdle; private scheduleReconnect; private handleNewEmails; } //# sourceMappingURL=watcher.service.d.ts.map