import type { ThreadMessageItem } from "@remit/data-ports"; import { type IImapConnection } from "@remit/mailbox-service"; import type { ProcessContext } from "../context.js"; import type { MessageMoveEvent, SyncMessagesEvent } from "../events.js"; type EmitSyncMessages = (event: Omit) => Promise; /** * Re-read both folders' counts from IMAP after a move by enqueuing the existing * per-folder SYNC_MESSAGES sync. Counts are a projection of IMAP, never mutated * locally — the move shifted a message between source and destination, so both * folders must refresh through the one-way pipeline. */ export declare const emitMoveResync: (emit: EmitSyncMessages, params: { accountId: string; sourceMailboxId: string; destinationMailboxId: string; }) => Promise; /** * The one-folder half of {@link emitMoveResync}, for a mutation that has no * destination — a permanent delete removed local rows the server still holds, * and only a resync of that folder puts them back. */ export declare const emitMailboxResync: (emit: EmitSyncMessages, params: { accountId: string; mailboxId: string; }) => Promise; /** * SEARCH a mailbox for copies of a message identified by its RFC822 Message-ID * header and answer the HIGHEST matching uid. Read-only (EXAMINE, not SELECT) — * this is a verification probe, never a write. `null` when nothing matched. * * The highest uid is the freshly delivered copy only when one exists; deciding * that it does is the caller's job, not this function's. Every probe in this * package wants the highest: uids ascend with arrival inside a UIDVALIDITY, so a * copy that has just landed outranks every copy of the same Message-ID the * folder already held. Where nothing was delivered, the highest is simply the * newest pre-existing copy, and a caller that has not ruled that case out binds * itself to unrelated mail. * One Message-ID can have several server copies in one account (a sieve * `fileinto` + `keep`, a resend, a repeated COPY — `deriveCopyMessageId` reuses * the row, so the second copy is a second server COPY), while `deriveMessageId` * is folder-independent and gives them one local row. Taking the lowest bound * the fresh copy's row to an older copy's uid and orphaned the fresh one, which * a later delete or Empty Trash then expunged by the wrong uid (issue #1122). * * The maximum is computed rather than read off the tail: RFC 3501 leaves the * order of a SEARCH response unspecified, so "last returned" is not "highest". */ export declare const searchMailboxForHighestMessageIdUid: (connection: IImapConnection, mailboxPath: string, messageIdHeader: string) => Promise; /** * Which side of a paused mutation the server actually holds the message on. * `gone` is an answer both folders gave; `unprobeable` is the row that carries * no Message-ID header, where the server was never asked and its silence says * nothing. */ export type PausedPlacement = { kind: "at-source"; } | { kind: "at-destination"; uid: number; } | { kind: "gone"; } | { kind: "unprobeable"; }; /** * Ask the server, by Message-ID, which folder holds a message whose mutation a * paused cursor interrupted (issue #1203). * * Reached only on a redelivery, where "the command never left" has stopped * being provable: the earlier attempt's tagged OK can be lost with the * connection, so restoring the source pair on that assumption would write a * settled placement naming a folder the server has already moved the mail out * of. `message-copy.ts` asks the same question for the same reason. * * The SOURCE is asked first and a hit ends it, the gate `confirmTrashMoveUid` * documents (#1122): where the mutation never ran, every hit at the destination * is an older copy of the same Message-ID — a sieve `fileinto` + `keep`, a * multi-label store, a resend — that `deriveMessageId` folds into this one local * row, and binding to it hands a later delete somebody else's uid. * * The source's silence, however, is not the mirror image of its hit. Every * caller here reaches this on a paused cursor, which means the source's * UIDVALIDITY has moved and the folder may have been recreated holding nothing * it held before — so "not at the source" is an answer about the folder, not * about our mutation, and `at-destination` is a sighting rather than a * confirmation. Callers settle it as unproven; see `settlePausedMove`. * * Identity, not position, is what makes this askable at all: a paused cursor * means the source's UIDVALIDITY has moved, so every stored uid for it names * something else, but a SEARCH by header is independent of the axis and answers * the same question the cursor rebuild itself matches rows by. For that reason * the caller passes the UNGUARDED connection — a `guardConnectionCursor` wrap * refuses to open the mailbox at all, and it is bound to the source's snapshot * anyway, so opening the destination through it would trip that mailbox too. */ export declare const probePausedPlacement: (connection: IImapConnection, input: { messageIdHeader: string | undefined; sourceMailboxPath: string; destinationMailboxPath: string | undefined; }) => Promise; /** * Resync the affected folders only once the IMAP move has resolved. A move that * fails (or is retried) must not refresh counts off a move that didn't happen, * so the resync is sequenced strictly after `performMove`. */ export declare const moveThenResync: (performMove: () => Promise, resync: () => Promise) => Promise; /** * Build the `set` and `composites` payload for the ThreadMessage update on a * MESSAGE_MOVE. * * The CURRENT row state goes in `composites`; the NEW values go in `set`. * ElectroDB uses `composites` to run the conditional check on the existing row * AND to compute the previous sort-key values needed to recompute the new ones. * Passing the NEW values in `composites` makes the conditional check fail with * ConditionalCheckFailedException, which ElectroDB wraps as NotFoundError, and * the caller silently drops the update. Same root cause as PR #186 fixed for * `flag-queue.ts`. */ export declare const buildThreadMessageMoveUpdate: (threadMessage: Pick, newUid: number, destinationMailboxId: string) => { set: { uid: number; mailboxId: string; isDeleted: boolean; }; composites: { sentDate: number; mailboxId: string; isRead: boolean; isDeleted: boolean; hasStars: boolean; hasAttachment: boolean; }; }; /** * Handle MESSAGE_MOVE events. * Executes IMAP MOVE command and updates local state with new UID. * * A failing move retries on SQS redelivery until `receiveCount` reaches * the `config.attempts.messageMove` budget, at which point * {@link resolveExhaustedMessageMoveFailure} asks IMAP where the message * actually is and settles the row into one terminal outcome (issue #655). * Before that, `syncStatus: failed` marked every attempt and nothing ever * settled the row, so an exhausted move sat `moving`/`failed` forever. */ export declare const handleMessageMove: (event: MessageMoveEvent, ctx: ProcessContext, receiveCount: number) => Promise; export {};