import type { IMessageAcceptanceContext, IMessageAcceptanceDecision } from '@push.rocks/smartmta';
import type { DcRouter } from '../classes.dcrouter.js';
export declare const DCROUTER_CACHE_ID_HEADER = "X-Dcrouter-Cached-Email-Id";
export type TSmartMtaQueueItemLike = {
    processingResult?: {
        headers?: Record<string, string>;
        email?: {
            headers?: Record<string, string>;
        };
    };
    status?: 'pending' | 'processing' | 'queued' | 'delivered' | 'failed' | 'deferred';
    attempts?: number;
    nextAttempt?: Date;
    lastError?: string;
};
/**
 * Accept-then-spool pipeline for inbound SMTP messages: persists accepted
 * messages as CachedEmail docs, replays them through SmartMTA on an interval,
 * and mirrors SmartMTA delivery-queue outcomes back onto the cached docs.
 */
export declare class AcceptedEmailSpool {
    private dcRouterRef;
    private spoolTimer?;
    private spoolRun?;
    private processing;
    private stopping;
    private queueUpdatePromises;
    constructor(dcRouterRef: DcRouter);
    acceptMessage(context: IMessageAcceptanceContext, processAfterAccept?: boolean): Promise<IMessageAcceptanceDecision>;
    /** Start the interval-driven spool processor and trigger an immediate run. */
    start(): void;
    /** Mark the spool as stopping and clear the interval without awaiting in-flight work. */
    beginStop(): void;
    /** Stop the spool and wait (bounded) for an in-flight run to settle. */
    stop(): Promise<void>;
    /** Kick off a spool run unless one is already in flight. */
    run(): void;
    trackQueueUpdate(item: TSmartMtaQueueItemLike, status: 'queued' | 'delivered' | 'failed', failureMessage: string): void;
    drainQueueUpdates(): Promise<void>;
    /** Requeue emails left in 'queued' state by a previous process as pending. */
    recoverQueuedEmails(): Promise<void>;
    private processSpool;
    private processAcceptedCachedEmail;
    private buildCachedEmailSession;
    private parseCachedEmailRouteData;
    private updateAcceptedEmailFromQueueItem;
    private waitForPromiseToSettleWithTimeout;
    private clearSpoolTimer;
    private setDcRouterCacheIdHeader;
    private isCachedEmailTerminal;
    private getCachedEmailIdFromQueueItem;
    private getHeaderValue;
    private removeHeader;
    private throwIfMessageAcceptanceAborted;
}
