import { type IImapConnection } from "@remit/mailbox-service"; import type { ProcessContext } from "../context.js"; import type { PlacementMovePushEvent } from "../events.js"; interface MoveOutcome { kind: "moved" | "not-found" | "trycreate"; newUid?: number; } /** * Attempt the IMAP MOVE. * * Takes two connection handles rather than one: `sourceConnection` and * `destinationConnection` wrap the SAME underlying connection but are each * cursor-guarded (#1272) against their OWN mailbox — a `guardConnectionCursor` * wrap binds `openBox` checks to whichever ONE mailbox snapshot it was built * with, so verifying at the destination must never run through the source's * guard (it would compare the destination's served UIDVALIDITY against the * source's stored one and misfire). * * - `moved` with a `newUid` — confirmed, either via COPYUID or (see below) * an explicit destination verification. * - `trycreate` — the destination mailbox doesn't exist yet; the caller * creates it and retries. * - `not-found` — confirmed absent from BOTH source and destination. Only * this outcome supersedes the pending-move marker (drops it, reconciles * the row as an external delete). * - Any other case throws (propagates for SQS retry, or as * `MailboxCursorPausedError` for the caller's cursor-pause handling) — * including an UNCONFIRMED move (no COPYUID, or an explicit "not * found"/NONEXISTENT from the server) whose message is still sitting at * the source. A MOVE that resolves without a uidMap entry on a * non-UIDPLUS server is a plausible SUCCESS, not evidence the message is * gone (PR #1289 review finding 2) — deleting the local row on that * ambiguity would be data loss. `not-found` is only returned once BOTH a * destination Message-ID search (when the header is known) misses AND * {@link isMessageGoneFromOpenMailbox} confirms the message absent from the * source — a FETCH returning no row does not, on its own, confirm anything. */ export declare const attemptMove: (sourceConnection: IImapConnection, destinationConnection: IImapConnection, sourceMailboxPath: string, destinationMailboxPath: string, uid: number, messageIdHeader: string | undefined) => Promise; /** * Handle PLACEMENT_MOVE_PUSH events (issue #1271, epic #1281). Drains ONE * pending placement-move marker: resolves the UID fresh from the Message row * (never trusts a captured value — invariant 1), pushes the IMAP MOVE, and * clears the marker ONLY on confirmed success. Every precedence rule (epic * invariant 2) is enforced here: * - Pending Remit move wins on location: nothing in this handler ever * corrects `message.mailboxId` back toward the source — a resync elsewhere * (message-sync.ts) never overwrites an existing row's `mailboxId` either * (create-only-if-not-exists semantics), so the local move is never undone. * - A NEWER local action superseding this marker (drop without pushing) — * see the `message.mailboxId !== marker.destinationMailboxId` check below. * - An external delete supersedes the marker entirely — the `not-found` * outcome drops the marker and reconciles the stale row. * * Cursor-guarded (#1272, epic #1281 invariant 5): both the source and * destination mailbox are checked for a non-`normal` `cursorState` before * connecting, and the connection is wrapped per-mailbox via * `guardConnectionCursor` so no stored UID touches the server while either * mailbox's axis is being rebuilt. A trip pauses the push (routine, no * alarm) — the marker stays durable and pushes again on the next event. */ export declare const handlePlacementMovePush: (event: PlacementMovePushEvent, ctx: ProcessContext, receiveCount: number) => Promise; export {};