export type ResponseItem = { line: string; /** Literal data if the line ended with a {N} marker, null otherwise */ literal: Uint8Array | null; }; export declare class ImapError extends Error { status: "OK" | "NO" | "BAD"; tag: string; messageText: string; untagged: ResponseItem[]; constructor(status: "OK" | "NO" | "BAD", tag: string, messageText: string, untagged: ResponseItem[]); } /** * Reads IMAP responses from a socket's readable stream. * * Handles: * - Responses split across arbitrary TCP chunks * - Literals ({N} markers) whose content may span multiple chunks and * contain CRLF, parens or any other bytes * - Multi-byte UTF-8 sequences split across chunk boundaries */ export declare class ImapStream { private reader; private buffer; private textDecoder; private timeoutMs; /** * The in-flight reader.read() promise. Never issue a second read() while * one is pending (the stream throws); on a read timeout the pending * promise is kept here and reused by the next read, so its data is never * lost and the stream stays consistent. */ private pendingRead; constructor(reader: ReadableStreamDefaultReader, timeoutMs?: number); private nextRead; /** Reads one chunk from the socket, waiting up to timeoutMs. */ private readChunk; private fillBuffer; /** Like fillBuffer, but returns false on timeout instead of closing the reader. */ private fillBufferNoThrow; private appendChunk; private indexOfCRLF; private close; /** * Reads the next protocol element: either a plain line, or a line ending * with a {N} literal marker together with the N raw literal bytes. */ readItem(): Promise; /** * Like readItem, but a read timeout while waiting for a line is not fatal: * returns null instead (the reader is NOT cancelled, the stream stays * usable). Timeouts while waiting for literal bytes are still fatal — a * partially-consumed literal leaves the stream corrupt. Used by IDLE, * where silence between responses is normal. */ readItemNoThrow(): Promise; private readItemInternal; /** * Reads items until the tagged completion response (tag OK/NO/BAD) arrives. * With continuation: true, stops at the first "+ " continuation line * instead (used for literal uploads). */ readUntilTag(tag: string, opts?: { continuation?: boolean; }): Promise<{ items: ResponseItem[]; tagged: ResponseItem; }>; }