@remit/imap-worker 0.0.11 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -12,8 +12,10 @@ const buildConnection = (opts: {
|
|
|
12
12
|
moveError?: Error;
|
|
13
13
|
/** Message-ID search hits in the destination mailbox — the verification probe. */
|
|
14
14
|
destinationSearchUids?: number[];
|
|
15
|
-
/** Whether the
|
|
15
|
+
/** Whether the message is still in the source mailbox. */
|
|
16
16
|
stillAtSource?: boolean;
|
|
17
|
+
/** The source FETCH drops the row for a message that is still there. */
|
|
18
|
+
sourceFetchDrops?: boolean;
|
|
17
19
|
}): IImapConnection =>
|
|
18
20
|
({
|
|
19
21
|
openBox: async () => ({}) as never,
|
|
@@ -25,9 +27,15 @@ const buildConnection = (opts: {
|
|
|
25
27
|
uidMap: opts.uidMap ?? new Map(),
|
|
26
28
|
};
|
|
27
29
|
},
|
|
28
|
-
search: async (
|
|
30
|
+
search: async (criteria: unknown[]) => {
|
|
31
|
+
const [first] = criteria;
|
|
32
|
+
if (Array.isArray(first) && first[0] === "UID") {
|
|
33
|
+
return opts.stillAtSource ? [Number(first[1])] : [];
|
|
34
|
+
}
|
|
35
|
+
return opts.destinationSearchUids ?? [];
|
|
36
|
+
},
|
|
29
37
|
fetchMessages: async (uids: number[]) =>
|
|
30
|
-
opts.stillAtSource
|
|
38
|
+
opts.stillAtSource && !opts.sourceFetchDrops
|
|
31
39
|
? uids.map((uid) => ({ uid }) as unknown as never)
|
|
32
40
|
: [],
|
|
33
41
|
}) as unknown as IImapConnection;
|
|
@@ -151,7 +159,29 @@ describe("attemptMove — the IMAP push (issue #1271)", () => {
|
|
|
151
159
|
);
|
|
152
160
|
});
|
|
153
161
|
|
|
154
|
-
it("
|
|
162
|
+
it("throws (never deletes) when the source FETCH drops the row for a message the server still lists", async () => {
|
|
163
|
+
const connection = buildConnection({
|
|
164
|
+
uidMap: new Map(),
|
|
165
|
+
destinationSearchUids: [],
|
|
166
|
+
stillAtSource: true,
|
|
167
|
+
sourceFetchDrops: true,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
await assert.rejects(
|
|
171
|
+
() =>
|
|
172
|
+
attemptMove(
|
|
173
|
+
connection,
|
|
174
|
+
connection,
|
|
175
|
+
"Junk",
|
|
176
|
+
"INBOX",
|
|
177
|
+
42,
|
|
178
|
+
MESSAGE_ID_HEADER,
|
|
179
|
+
),
|
|
180
|
+
/unresolved/,
|
|
181
|
+
);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("not-found: confirmed absent from BOTH destination (search miss) AND source (search miss)", async () => {
|
|
155
185
|
const connection = buildConnection({
|
|
156
186
|
uidMap: new Map(),
|
|
157
187
|
destinationSearchUids: [],
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
guardConnectionCursor,
|
|
6
6
|
type IImapConnection,
|
|
7
7
|
isCursorRebuildNeeded,
|
|
8
|
+
isMessageGoneFromOpenMailbox,
|
|
8
9
|
MailboxCursorPausedError,
|
|
9
10
|
reconcileStaleMessage,
|
|
10
11
|
resolveExhaustedPlacementMoveFailure,
|
|
@@ -90,7 +91,8 @@ const searchMailboxByMessageId = async (
|
|
|
90
91
|
* gone (PR #1289 review finding 2) — deleting the local row on that
|
|
91
92
|
* ambiguity would be data loss. `not-found` is only returned once BOTH a
|
|
92
93
|
* destination Message-ID search (when the header is known) misses AND
|
|
93
|
-
* the message
|
|
94
|
+
* {@link isMessageGoneFromOpenMailbox} confirms the message absent from the
|
|
95
|
+
* source — a FETCH returning no row does not, on its own, confirm anything.
|
|
94
96
|
*/
|
|
95
97
|
export const attemptMove = async (
|
|
96
98
|
sourceConnection: IImapConnection,
|
|
@@ -135,8 +137,7 @@ export const attemptMove = async (
|
|
|
135
137
|
}
|
|
136
138
|
|
|
137
139
|
await sourceConnection.openBox(sourceMailboxPath, true);
|
|
138
|
-
|
|
139
|
-
if (stillAtSource.length > 0) {
|
|
140
|
+
if (!(await isMessageGoneFromOpenMailbox(sourceConnection, uid))) {
|
|
140
141
|
throw new Error(
|
|
141
142
|
"Placement move unresolved (unconfirmed at destination, still present at source) — retrying",
|
|
142
143
|
);
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
isCursorRebuildNeeded,
|
|
9
9
|
MailboxCursorPausedError,
|
|
10
10
|
PlacementMoveService,
|
|
11
|
+
QuarantineService,
|
|
11
12
|
resolveExhaustedBodySyncFailures,
|
|
12
13
|
} from "@remit/mailbox-service";
|
|
13
14
|
import { env } from "expect-env";
|
|
@@ -20,6 +21,7 @@ import {
|
|
|
20
21
|
import type { SyncMessageBodyEvent } from "../events.js";
|
|
21
22
|
import { withOAuthLifecycle } from "../with-oauth-lifecycle.js";
|
|
22
23
|
import { buildLifecycleDeps } from "../with-oauth-lifecycle-deps.js";
|
|
24
|
+
import { workerVersion } from "../worker-version.js";
|
|
23
25
|
|
|
24
26
|
const bodySyncEnabledParameterName = env.BODY_SYNC_ENABLED_PARAMETER_NAME;
|
|
25
27
|
|
|
@@ -151,6 +153,8 @@ export const syncMessageBody = async (
|
|
|
151
153
|
messageLabel: messageLabelService,
|
|
152
154
|
storage,
|
|
153
155
|
secrets,
|
|
156
|
+
mailboxSpecialUse: mailboxSpecialUseRepository,
|
|
157
|
+
quarantine: quarantineRepository,
|
|
154
158
|
} = await getClient();
|
|
155
159
|
|
|
156
160
|
const account = await accountService.get(accountId);
|
|
@@ -234,6 +238,17 @@ export const syncMessageBody = async (
|
|
|
234
238
|
log,
|
|
235
239
|
placementConfig,
|
|
236
240
|
filterConfig,
|
|
241
|
+
{
|
|
242
|
+
quarantineService: new QuarantineService(
|
|
243
|
+
quarantineRepository,
|
|
244
|
+
mailboxSpecialUseRepository,
|
|
245
|
+
workerVersion(),
|
|
246
|
+
log,
|
|
247
|
+
),
|
|
248
|
+
mailboxId,
|
|
249
|
+
uidValidity: mailbox.uidValidity ?? 0,
|
|
250
|
+
attempts: receiveCount,
|
|
251
|
+
},
|
|
237
252
|
);
|
|
238
253
|
|
|
239
254
|
// Guard at the openBox choke point (epic #1281 invariants 3 & 5). The
|
|
@@ -5,9 +5,11 @@ import type {
|
|
|
5
5
|
IAddressRepository,
|
|
6
6
|
IEnvelopeRepository,
|
|
7
7
|
IMailboxRepository,
|
|
8
|
+
IMailboxSpecialUseRepository,
|
|
8
9
|
IMessageFlagPushRepository,
|
|
9
10
|
IMessageFlagRepository,
|
|
10
11
|
IMessageRepository,
|
|
12
|
+
IQuarantineRepository,
|
|
11
13
|
IThreadMessageRepository,
|
|
12
14
|
IUnitOfWork,
|
|
13
15
|
} from "@remit/data-ports";
|
|
@@ -19,6 +21,7 @@ import {
|
|
|
19
21
|
MailConnectionError,
|
|
20
22
|
type MailCredentials,
|
|
21
23
|
MessageSyncService,
|
|
24
|
+
QuarantineService,
|
|
22
25
|
type SyncedMessage,
|
|
23
26
|
} from "@remit/mailbox-service";
|
|
24
27
|
import pMap from "p-map";
|
|
@@ -31,6 +34,7 @@ import type {
|
|
|
31
34
|
} from "../events.js";
|
|
32
35
|
import { withOAuthLifecycle } from "../with-oauth-lifecycle.js";
|
|
33
36
|
import { buildLifecycleDeps } from "../with-oauth-lifecycle-deps.js";
|
|
37
|
+
import { workerVersion } from "../worker-version.js";
|
|
34
38
|
|
|
35
39
|
// One SYNC_MESSAGE_BODY event maps to one ranged UID FETCH on the consumer.
|
|
36
40
|
export const BODY_BATCH_SIZE = 200;
|
|
@@ -70,6 +74,8 @@ export const syncMessages = async (
|
|
|
70
74
|
address: addressService,
|
|
71
75
|
threadMessage: threadMessageService,
|
|
72
76
|
mailboxLock: mailboxLockService,
|
|
77
|
+
mailboxSpecialUse: mailboxSpecialUseService,
|
|
78
|
+
quarantine: quarantineService,
|
|
73
79
|
flagPush: flagPushMarkerService,
|
|
74
80
|
messageFlag: messageFlagService,
|
|
75
81
|
unitOfWork,
|
|
@@ -138,6 +144,8 @@ export const syncMessages = async (
|
|
|
138
144
|
envelopeService,
|
|
139
145
|
addressService,
|
|
140
146
|
threadMessageService,
|
|
147
|
+
mailboxSpecialUseService,
|
|
148
|
+
quarantineService,
|
|
141
149
|
flagPushMarkerService,
|
|
142
150
|
messageFlagService,
|
|
143
151
|
unitOfWork,
|
|
@@ -181,6 +189,8 @@ interface SyncDeps {
|
|
|
181
189
|
envelopeService: IEnvelopeRepository;
|
|
182
190
|
addressService: IAddressRepository;
|
|
183
191
|
threadMessageService: IThreadMessageRepository;
|
|
192
|
+
mailboxSpecialUseService: IMailboxSpecialUseRepository;
|
|
193
|
+
quarantineService: IQuarantineRepository;
|
|
184
194
|
flagPushMarkerService: IMessageFlagPushRepository;
|
|
185
195
|
messageFlagService: IMessageFlagRepository;
|
|
186
196
|
unitOfWork?: IUnitOfWork;
|
|
@@ -272,6 +282,8 @@ const syncMailboxMessages = async (
|
|
|
272
282
|
envelopeService,
|
|
273
283
|
addressService,
|
|
274
284
|
threadMessageService,
|
|
285
|
+
mailboxSpecialUseService,
|
|
286
|
+
quarantineService,
|
|
275
287
|
flagPushMarkerService,
|
|
276
288
|
messageFlagService,
|
|
277
289
|
unitOfWork,
|
|
@@ -307,6 +319,12 @@ const syncMailboxMessages = async (
|
|
|
307
319
|
unitOfWork,
|
|
308
320
|
flagPushMarkerService,
|
|
309
321
|
messageFlagService,
|
|
322
|
+
new QuarantineService(
|
|
323
|
+
quarantineService,
|
|
324
|
+
mailboxSpecialUseService,
|
|
325
|
+
workerVersion(),
|
|
326
|
+
log,
|
|
327
|
+
),
|
|
310
328
|
);
|
|
311
329
|
|
|
312
330
|
// Connect once, reuse for the entire sync operation
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The build of this worker, stamped onto a quarantine record so a maintainer
|
|
3
|
+
* reading a filed report knows which commit failed to read the message.
|
|
4
|
+
*
|
|
5
|
+
* Deliberately not the client's `APP_SHA`: that is the web build, and pointing
|
|
6
|
+
* a maintainer at it for a backend parse failure sends them to the wrong
|
|
7
|
+
* commit. The container bundle replaces this read at build time (see
|
|
8
|
+
* `npm-scripts/docker-bundle.mjs`); outside an image build it falls back to the
|
|
9
|
+
* CI-provided SHA, then to `dev`, so a local run is labelled honestly rather
|
|
10
|
+
* than claiming a release it is not.
|
|
11
|
+
*/
|
|
12
|
+
export const workerVersion = (): string =>
|
|
13
|
+
process.env.REMIT_WORKER_SHA || process.env.GITHUB_SHA || "dev";
|