import type { IMessageRepository, IThreadMessageRepository, MessageItem } from "@remit/data-ports"; import { type IImapConnection } from "@remit/mailbox-service"; export interface MessageDeleteTerminalLogger { info(obj: Record, msg: string): void; error(obj: Record, msg: string): void; } export interface ResolveExhaustedMessageDeleteDeps { messageService: Pick; threadMessageService: Pick; log: MessageDeleteTerminalLogger; } export interface ResolveExhaustedMessageDeleteInput { /** Where the row stood when the caller read it; the delete holds only while it still does. */ placement: Pick; accountId: string; accountConfigId: string; messageId: string; sourceMailboxId: string; uid: number; sourceMailboxPath: string; getConnection: () => Promise; } export type MessageDeleteTerminalOutcome = "reconciled" | "broken"; export interface ResolveExhaustedMessageDeleteResult { outcome: MessageDeleteTerminalOutcome; } /** * Resolve a MESSAGE_DELETE failure that has exhausted its redelivery budget * into exactly one of two terminal outcomes, mirroring * `resolveExhaustedMessageMoveFailure` for the same failure taxonomy (issue * #655) — no third, softer outcome. * * 1. RECONCILED (expected) — the message no longer exists at the delete's * source on IMAP, confirmed by {@link isMessageGoneFromOpenMailbox} rather * than by a FETCH coming back empty. The move to Trash landed server-side, * or a foreign client moved or expunged the message; from here those are * indistinguishable and have the same answer. The stale rows are deleted via * `deleteIfPlacement` and the caller resyncs the affected folders, * so whichever folder actually holds the message re-projects it with the * server's own UID. Metric only, no alarm — routine. * 2. BROKEN — the message is still at the source, so the delete never took * effect, but it keeps failing: broken code or a broken account, not a * transient blip. The row is put back where the server has just said the * message is: `mailboxId` and `uid` return to the delete's source pair, and * the thread rows lose the deletion mark the optimistic transition * wrote (issue #1098). * * Settling `status` to `active` while leaving `mailboxId` on Trash is what * this replaces. `bindsForeignUid` refuses a mismatched pair only while * `status` is `moving`, so clearing it read as consistent, and the UI then * offered "Delete permanently" on a Trash mailbox with the source folder's * uid — an expunge naming a different message. Restoring the pair is not a * revert on ambiguity (what PR #652 was pulled for): the presence probe * above has just answered, so this writes a placement the server confirmed. * * A server that cannot be reached at exhaustion time never reaches either * verdict: the probe throws and the record dead-letters with the row untouched. * Absence is only ever concluded from an answer the server gave. */ export declare const resolveExhaustedMessageDeleteFailure: (deps: ResolveExhaustedMessageDeleteDeps, input: ResolveExhaustedMessageDeleteInput) => Promise;