@remit/mailbox-service 0.0.110 → 0.0.112
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 +21 -6
- package/src/body-part-mapper.ts +51 -1
- package/src/body-sync-queue.test.ts +39 -99
- package/src/body-sync-terminal.test.ts +115 -277
- package/src/body-sync-terminal.ts +10 -12
- package/src/body-sync.test.ts +925 -0
- package/src/body-sync.ts +226 -200
- package/src/classification-backfill.test.ts +197 -527
- package/src/classify-message.test.ts +11 -74
- package/src/external-move.test.ts +102 -209
- package/src/external-move.ts +13 -0
- package/src/filter-operations.test.ts +319 -0
- package/src/filter-operations.ts +377 -0
- package/src/filter-update.test.ts +313 -0
- package/src/filters/filter-config.test.ts +55 -197
- package/src/filters/filter-config.ts +4 -39
- package/src/filters/match.test.ts +1 -38
- package/src/filters/match.ts +3 -52
- package/src/filters/pipeline.test.ts +158 -289
- package/src/filters/pipeline.ts +56 -170
- package/src/flag-push-terminal.ts +9 -11
- package/src/flag-push.test.ts +76 -372
- package/src/flag-queue.test.ts +197 -0
- package/src/folder-operations.test.ts +273 -0
- package/src/folder-operations.ts +217 -0
- package/src/forwarded-message.test.ts +122 -0
- package/src/imapflow-connect-retry.test.ts +76 -113
- package/src/imapflow-connection.test.ts +34 -0
- package/src/imapflow-connection.ts +19 -15
- package/src/index.ts +59 -12
- package/src/list-id-backfill.test.ts +133 -499
- package/src/mailbox-cursor.test.ts +81 -189
- package/src/mailbox-delete-intent.test.ts +78 -205
- package/src/mailbox-intent.ts +5 -3
- package/src/mailbox-management.test.ts +107 -220
- package/src/mailbox-management.ts +1 -2
- package/src/mailbox-presence.test.ts +36 -34
- package/src/mailbox-queue.ts +2 -20
- package/src/mailbox-rename-intent.test.ts +156 -325
- package/src/mailbox-rename-subtree.test.ts +205 -582
- package/src/mailbox-sync.test.ts +182 -744
- package/src/message-move.test.ts +726 -0
- package/src/message-move.ts +227 -57
- package/src/message-read.ts +87 -0
- package/src/message-save-retry.test.ts +90 -0
- package/src/message-sync-flags.test.ts +10 -1
- package/src/message-sync.test.ts +762 -0
- package/src/message-sync.ts +409 -239
- package/src/mime-walker.ts +16 -15
- package/src/organize-job.ts +93 -0
- package/src/outbox-attachment.test.ts +97 -209
- package/src/outbox-failed-recovery.test.ts +198 -269
- package/src/outbox-queue.test.ts +24 -0
- package/src/outbox-queue.ts +25 -8
- package/src/ownership.ts +140 -0
- package/src/placement-move-terminal.ts +9 -12
- package/src/placement-move.ts +33 -6
- package/src/placement-settled.ts +28 -4
- package/src/placement.test.ts +404 -0
- package/src/quarantine.test.ts +90 -148
- package/src/quarantine.ts +3 -2
- package/src/refusal.ts +29 -0
- package/src/restore-source-placement.ts +0 -4
- package/src/spam-report.test.ts +238 -710
- package/src/sync-warning.test.ts +213 -0
- package/src/sync-warning.ts +56 -0
- package/src/test-helpers/fake-imap.ts +690 -0
- package/src/test-helpers/test-queue.ts +56 -0
- package/src/test-helpers/test-store.ts +299 -0
- package/src/thread-root.test.ts +29 -0
- package/src/thread-root.ts +51 -0
- package/src/types/mailparser-augment.d.ts +8 -0
- package/src/types.ts +1 -1
- package/src/adversarial-mime.e2e.test.ts +0 -307
- package/src/body-sync-auto-read-writeonce.test.ts +0 -219
- package/src/body-sync-calendar-suggestion.test.ts +0 -433
- package/src/body-sync-category-denormalize.test.ts +0 -352
- package/src/body-sync-category-override.test.ts +0 -501
- package/src/body-sync-category-writeonce.test.ts +0 -234
- package/src/body-sync-filter.test.ts +0 -237
- package/src/body-sync-placement-flags.test.ts +0 -347
- package/src/body-sync-placement-writeonce.test.ts +0 -337
- package/src/body-sync-quarantine.test.ts +0 -276
- package/src/body-sync-resync.test.ts +0 -605
- package/src/body-sync-unclassifiable-once.test.ts +0 -260
- package/src/body-sync-unsubscribed-auto-read.test.ts +0 -176
- package/src/filters/anchor-drift.ts +0 -55
- package/src/filters/message-embedder.test.ts +0 -39
- package/src/filters/message-embedder.ts +0 -33
- package/src/flag-push-terminal.test.ts +0 -209
- package/src/flag-queue-stars.test.ts +0 -171
- package/src/imapflow-connection.e2e.test.ts +0 -335
- package/src/imapflow-connection.integ.test.ts +0 -316
- package/src/message-delete-junk-reconcile.test.ts +0 -117
- package/src/message-delete-no-trash.test.ts +0 -245
- package/src/message-delete-unsettled-placement.test.ts +0 -396
- package/src/message-move-copy.test.ts +0 -562
- package/src/message-move-empty-trash.test.ts +0 -326
- package/src/message-move-same-mailbox.test.ts +0 -139
- package/src/message-move-unsettled-placement.test.ts +0 -378
- package/src/message-sync-address-spoof.test.ts +0 -293
- package/src/message-sync-category.test.ts +0 -142
- package/src/message-sync-changedsince.test.ts +0 -840
- package/src/message-sync-junk-harvest.test.ts +0 -244
- package/src/message-sync-quarantine.test.ts +0 -416
- package/src/message-sync-repoint.test.ts +0 -419
- package/src/outbox-queue-settled-row.test.ts +0 -140
- package/src/pass-through-unit-of-work.ts +0 -17
- package/src/placement-move-terminal.test.ts +0 -300
- package/src/placement-move-unsettled.test.ts +0 -275
- package/src/placement-transition-race.test.ts +0 -482
- package/src/stale-message-reconcile.test.ts +0 -82
- package/src/stale-message-reconcile.ts +0 -55
- package/src/test-helpers/isolated-mailbox.ts +0 -44
- package/src/test-helpers/mailfuzz-connection.ts +0 -27
- package/test/fixtures/mime-adversarial-e2e/01-octet-stream-pdf.eml +0 -21
- package/test/fixtures/mime-adversarial-e2e/02-nested-related-cid-image.eml +0 -31
- package/test/fixtures/mime-adversarial-e2e/03-calendar-invite.eml +0 -33
- package/test/fixtures/mime-adversarial-e2e/04-forwarded-rfc822-with-attachments.eml +0 -42
- package/test/fixtures/mime-adversarial-e2e/05-tnef-winmail.eml +0 -25
- package/test/fixtures/mime-adversarial-e2e/06-8bit-non-ascii.eml +0 -15
- package/test/fixtures/mime-adversarial-e2e/07-quoted-printable-soft-breaks.eml +0 -17
- package/test/fixtures/mime-adversarial-e2e/08-alternative-empty-text.eml +0 -18
|
@@ -1,310 +1,148 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
|
-
import { describe, it } from "node:test";
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
IThreadMessageRepository,
|
|
6
|
-
} from "@remit/data-ports";
|
|
7
|
-
import type {
|
|
8
|
-
StorageService,
|
|
9
|
-
StoreBodyPartParams,
|
|
10
|
-
} from "@remit/storage-service";
|
|
11
|
-
import type { BodySyncLogger } from "./body-sync.js";
|
|
2
|
+
import { afterEach, beforeEach, describe, it } from "node:test";
|
|
3
|
+
import type { AccountItem, MailboxItem } from "@remit/data-ports";
|
|
4
|
+
import type { StorageService } from "@remit/storage-service";
|
|
12
5
|
import {
|
|
13
6
|
isMessageBodySyncBroken,
|
|
14
|
-
type ResolveExhaustedBodySyncDeps,
|
|
15
7
|
resolveExhaustedBodySyncFailures,
|
|
16
8
|
} from "./body-sync-terminal.js";
|
|
17
|
-
import
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const buildMessageService = (
|
|
43
|
-
uidByMessageId: Record<string, number>,
|
|
44
|
-
deleted: string[],
|
|
45
|
-
): Pick<IMessageRepository, "get" | "delete"> =>
|
|
46
|
-
({
|
|
47
|
-
get: async (messageId: string) => {
|
|
48
|
-
const uid = uidByMessageId[messageId];
|
|
49
|
-
if (uid === undefined) {
|
|
50
|
-
throw new Error(`no fixture uid for ${messageId}`);
|
|
51
|
-
}
|
|
52
|
-
return { messageId, uid };
|
|
53
|
-
},
|
|
54
|
-
delete: async (messageId: string) => {
|
|
55
|
-
deleted.push(messageId);
|
|
56
|
-
},
|
|
57
|
-
}) as unknown as Pick<IMessageRepository, "get" | "delete">;
|
|
9
|
+
import { eml, FakeImapServer } from "./test-helpers/fake-imap.js";
|
|
10
|
+
import {
|
|
11
|
+
messageAtUid,
|
|
12
|
+
openStore,
|
|
13
|
+
type Store,
|
|
14
|
+
seedAccount,
|
|
15
|
+
seedMailbox,
|
|
16
|
+
silentLog,
|
|
17
|
+
syncFolder,
|
|
18
|
+
} from "./test-helpers/test-store.js";
|
|
19
|
+
|
|
20
|
+
let store: Store;
|
|
21
|
+
let storage: StorageService;
|
|
22
|
+
let imap: FakeImapServer;
|
|
23
|
+
let account: AccountItem;
|
|
24
|
+
let inbox: MailboxItem;
|
|
25
|
+
|
|
26
|
+
beforeEach(async () => {
|
|
27
|
+
store = await openStore();
|
|
28
|
+
storage = store.storage();
|
|
29
|
+
imap = new FakeImapServer();
|
|
30
|
+
account = await seedAccount(store);
|
|
31
|
+
inbox = await seedMailbox(store, account, "INBOX");
|
|
32
|
+
imap.addFolder("INBOX");
|
|
33
|
+
});
|
|
58
34
|
|
|
59
|
-
|
|
60
|
-
deletedKeys: Array<{ accountConfigId: string; threadMessageId: string }>,
|
|
61
|
-
): Pick<IThreadMessageRepository, "findAllByMessageId" | "deleteMany"> =>
|
|
62
|
-
({
|
|
63
|
-
findAllByMessageId: async (accountConfigId: string, messageId: string) => [
|
|
64
|
-
{
|
|
65
|
-
accountConfigId,
|
|
66
|
-
threadMessageId: `tm-${messageId}`,
|
|
67
|
-
messageId,
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
deleteMany: async (
|
|
71
|
-
keys: Array<{ accountConfigId: string; threadMessageId: string }>,
|
|
72
|
-
) => {
|
|
73
|
-
deletedKeys.push(...keys);
|
|
74
|
-
},
|
|
75
|
-
}) as unknown as Pick<
|
|
76
|
-
IThreadMessageRepository,
|
|
77
|
-
"findAllByMessageId" | "deleteMany"
|
|
78
|
-
>;
|
|
35
|
+
afterEach(() => store.close());
|
|
79
36
|
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
stored: StoreBodyPartParams[];
|
|
85
|
-
} => {
|
|
86
|
-
const stored: StoreBodyPartParams[] = [];
|
|
87
|
-
return {
|
|
88
|
-
stored,
|
|
89
|
-
storageService: {
|
|
90
|
-
storeBodyPart: async (params: StoreBodyPartParams) => {
|
|
91
|
-
stored.push(params);
|
|
92
|
-
brokenAlready.add(params.messageId);
|
|
93
|
-
return {} as never;
|
|
94
|
-
},
|
|
95
|
-
bodyPartExists: async (
|
|
96
|
-
_accountConfigId: string,
|
|
97
|
-
_accountId: string,
|
|
98
|
-
messageId: string,
|
|
99
|
-
partPath: string,
|
|
100
|
-
) => partPath === ".sync-failed" && brokenAlready.has(messageId),
|
|
101
|
-
},
|
|
102
|
-
};
|
|
37
|
+
const arrive = async (subject: string) => {
|
|
38
|
+
const uid = imap.deliver("INBOX", eml({ Subject: subject }));
|
|
39
|
+
await syncFolder(store, account, inbox, imap);
|
|
40
|
+
return { uid, messageId: (await messageAtUid(store, inbox, uid)).messageId };
|
|
103
41
|
};
|
|
104
42
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
present: Set<number>,
|
|
112
|
-
fetchDrops: Set<number> = new Set(),
|
|
113
|
-
): IImapConnection =>
|
|
114
|
-
({
|
|
115
|
-
openBox: async () => ({}) as never,
|
|
116
|
-
fetchMessages: async (uids: number[]) =>
|
|
117
|
-
uids
|
|
118
|
-
.filter((uid) => present.has(uid) && !fetchDrops.has(uid))
|
|
119
|
-
.map((uid) => ({ uid }) as unknown as never),
|
|
120
|
-
search: async (criteria: unknown[]) => {
|
|
121
|
-
const [, value] = (criteria as Array<[string, string]>)[0];
|
|
122
|
-
const uid = Number(value);
|
|
123
|
-
return present.has(uid) ? [uid] : [];
|
|
43
|
+
const resolve = (failedMessageIds: string[], connection = imap.connection()) =>
|
|
44
|
+
resolveExhaustedBodySyncFailures(
|
|
45
|
+
{
|
|
46
|
+
messageService: store.message,
|
|
47
|
+
storageService: storage,
|
|
48
|
+
log: silentLog,
|
|
124
49
|
},
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const deletedMessages: string[] = [];
|
|
130
|
-
const deletedThreadMessages: Array<{
|
|
131
|
-
accountConfigId: string;
|
|
132
|
-
threadMessageId: string;
|
|
133
|
-
}> = [];
|
|
134
|
-
const { storageService, stored } = buildStorageService();
|
|
135
|
-
const { log, infos, errors } = buildLogger();
|
|
136
|
-
|
|
137
|
-
const deps: ResolveExhaustedBodySyncDeps = {
|
|
138
|
-
messageService: buildMessageService({ "msg-gone": 101 }, deletedMessages),
|
|
139
|
-
threadMessageService: buildThreadMessageService(deletedThreadMessages),
|
|
140
|
-
storageService,
|
|
141
|
-
log,
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
const result = await resolveExhaustedBodySyncFailures(deps, {
|
|
145
|
-
accountId: "acc-1",
|
|
146
|
-
accountConfigId: "cfg-1",
|
|
147
|
-
mailboxId: "mbx-1",
|
|
50
|
+
{
|
|
51
|
+
accountId: account.accountId,
|
|
52
|
+
accountConfigId: account.accountConfigId,
|
|
53
|
+
mailboxId: inbox.mailboxId,
|
|
148
54
|
mailboxPath: "INBOX",
|
|
149
|
-
failedMessageIds
|
|
150
|
-
getConnection: async () =>
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
55
|
+
failedMessageIds,
|
|
56
|
+
getConnection: async () => connection,
|
|
57
|
+
},
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const isBroken = (messageId: string) =>
|
|
61
|
+
isMessageBodySyncBroken(
|
|
62
|
+
storage,
|
|
63
|
+
account.accountConfigId,
|
|
64
|
+
account.accountId,
|
|
65
|
+
messageId,
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
describe("a body sync that exhausted its retries", () => {
|
|
69
|
+
it("removes the row and every thread copy of a message the server expunged", async () => {
|
|
70
|
+
const { uid, messageId } = await arrive("gone");
|
|
71
|
+
const [row] = await store.threadMessage.findAllByMessageId(
|
|
72
|
+
account.accountConfigId,
|
|
73
|
+
messageId,
|
|
165
74
|
);
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
it("outcome 2 (BROKEN): a uid IMAP still has persists the failed-forever sentinel and alerts", async () => {
|
|
169
|
-
const deletedMessages: string[] = [];
|
|
170
|
-
const { storageService, stored } = buildStorageService();
|
|
171
|
-
const { log, errors } = buildLogger();
|
|
75
|
+
await store.threadMessage.create({ ...row, threadId: "drifted-root" });
|
|
76
|
+
imap.expunge("INBOX", uid);
|
|
172
77
|
|
|
173
|
-
const
|
|
174
|
-
messageService: buildMessageService(
|
|
175
|
-
{ "msg-broken": 202 },
|
|
176
|
-
deletedMessages,
|
|
177
|
-
),
|
|
178
|
-
threadMessageService: buildThreadMessageService([]),
|
|
179
|
-
storageService,
|
|
180
|
-
log,
|
|
181
|
-
};
|
|
78
|
+
const result = await resolve([messageId]);
|
|
182
79
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
mailboxId: "mbx-1",
|
|
187
|
-
mailboxPath: "INBOX",
|
|
188
|
-
failedMessageIds: ["msg-broken"],
|
|
189
|
-
getConnection: async () => buildConnection(new Set([202])),
|
|
80
|
+
assert.deepEqual(result, {
|
|
81
|
+
reconciledMessageIds: [messageId],
|
|
82
|
+
brokenMessageIds: [],
|
|
190
83
|
});
|
|
191
|
-
|
|
192
|
-
assert.deepEqual(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
assert.ok(
|
|
199
|
-
errors.some((e) => e.obj.alert === "body_sync_message_broken"),
|
|
200
|
-
"expects an alert-shaped error log for the broken case",
|
|
84
|
+
await assert.rejects(store.message.get(messageId));
|
|
85
|
+
assert.deepEqual(
|
|
86
|
+
await store.threadMessage.findAllByMessageId(
|
|
87
|
+
account.accountConfigId,
|
|
88
|
+
messageId,
|
|
89
|
+
),
|
|
90
|
+
[],
|
|
201
91
|
);
|
|
92
|
+
assert.equal(await isBroken(messageId), false);
|
|
202
93
|
});
|
|
203
94
|
|
|
204
|
-
it("a
|
|
205
|
-
const
|
|
206
|
-
const deletedThreadMessages: Array<{
|
|
207
|
-
accountConfigId: string;
|
|
208
|
-
threadMessageId: string;
|
|
209
|
-
}> = [];
|
|
210
|
-
const { storageService } = buildStorageService();
|
|
211
|
-
const { log } = buildLogger();
|
|
212
|
-
|
|
213
|
-
const deps: ResolveExhaustedBodySyncDeps = {
|
|
214
|
-
messageService: buildMessageService({ m1: 1, m2: 2 }, deletedMessages),
|
|
215
|
-
threadMessageService: buildThreadMessageService(deletedThreadMessages),
|
|
216
|
-
storageService,
|
|
217
|
-
log,
|
|
218
|
-
};
|
|
95
|
+
it("marks a message the server still holds as broken and keeps its row", async () => {
|
|
96
|
+
const { messageId } = await arrive("broken");
|
|
219
97
|
|
|
220
|
-
|
|
221
|
-
// immediately following FETCH for m2 drops its row (#408).
|
|
222
|
-
const result = await resolveExhaustedBodySyncFailures(deps, {
|
|
223
|
-
accountId: "acc-1",
|
|
224
|
-
accountConfigId: "cfg-1",
|
|
225
|
-
mailboxId: "mbx-1",
|
|
226
|
-
mailboxPath: "INBOX",
|
|
227
|
-
failedMessageIds: ["m1", "m2"],
|
|
228
|
-
getConnection: async () => buildConnection(new Set([1, 2]), new Set([2])),
|
|
229
|
-
});
|
|
98
|
+
const result = await resolve([messageId]);
|
|
230
99
|
|
|
231
|
-
assert.deepEqual(result.
|
|
232
|
-
assert.
|
|
233
|
-
assert.
|
|
234
|
-
assert.deepEqual(deletedThreadMessages, []);
|
|
100
|
+
assert.deepEqual(result.brokenMessageIds, [messageId]);
|
|
101
|
+
assert.ok(await store.message.get(messageId));
|
|
102
|
+
assert.equal(await isBroken(messageId), true);
|
|
235
103
|
});
|
|
236
104
|
|
|
237
|
-
it("
|
|
238
|
-
const
|
|
239
|
-
const
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
log,
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
const result = await resolveExhaustedBodySyncFailures(deps, {
|
|
253
|
-
accountId: "acc-1",
|
|
254
|
-
accountConfigId: "cfg-1",
|
|
255
|
-
mailboxId: "mbx-1",
|
|
256
|
-
mailboxPath: "INBOX",
|
|
257
|
-
failedMessageIds: ["msg-gone", "msg-broken"],
|
|
258
|
-
getConnection: async () => buildConnection(new Set([2])),
|
|
259
|
-
});
|
|
105
|
+
it("does not read a dropped FETCH row as absence", async () => {
|
|
106
|
+
const first = await arrive("first");
|
|
107
|
+
const second = await arrive("second");
|
|
108
|
+
const connection = imap.connection();
|
|
109
|
+
const fetch = connection.fetchMessages;
|
|
110
|
+
connection.fetchMessages = async (uids) =>
|
|
111
|
+
uids.includes(second.uid) ? [] : fetch(uids);
|
|
112
|
+
|
|
113
|
+
const result = await resolve(
|
|
114
|
+
[first.messageId, second.messageId],
|
|
115
|
+
connection,
|
|
116
|
+
);
|
|
260
117
|
|
|
261
|
-
assert.deepEqual(result.reconciledMessageIds, [
|
|
262
|
-
assert.deepEqual(result.brokenMessageIds, [
|
|
118
|
+
assert.deepEqual(result.reconciledMessageIds, []);
|
|
119
|
+
assert.deepEqual(result.brokenMessageIds, [
|
|
120
|
+
first.messageId,
|
|
121
|
+
second.messageId,
|
|
122
|
+
]);
|
|
123
|
+
assert.ok(await store.message.get(second.messageId));
|
|
263
124
|
});
|
|
264
125
|
|
|
265
|
-
it("
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
messageService: buildMessageService({}, []),
|
|
272
|
-
threadMessageService: buildThreadMessageService([]),
|
|
273
|
-
storageService,
|
|
274
|
-
log,
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
const result = await resolveExhaustedBodySyncFailures(deps, {
|
|
278
|
-
accountId: "acc-1",
|
|
279
|
-
accountConfigId: "cfg-1",
|
|
280
|
-
mailboxId: "mbx-1",
|
|
281
|
-
mailboxPath: "INBOX",
|
|
282
|
-
failedMessageIds: [],
|
|
283
|
-
getConnection: async () => {
|
|
284
|
-
connectionRequested = true;
|
|
285
|
-
return buildConnection(new Set());
|
|
126
|
+
it("never opens a connection when nothing failed", async () => {
|
|
127
|
+
const result = await resolveExhaustedBodySyncFailures(
|
|
128
|
+
{
|
|
129
|
+
messageService: store.message,
|
|
130
|
+
storageService: storage,
|
|
131
|
+
log: silentLog,
|
|
286
132
|
},
|
|
287
|
-
|
|
133
|
+
{
|
|
134
|
+
accountId: account.accountId,
|
|
135
|
+
accountConfigId: account.accountConfigId,
|
|
136
|
+
mailboxId: inbox.mailboxId,
|
|
137
|
+
mailboxPath: "INBOX",
|
|
138
|
+
failedMessageIds: [],
|
|
139
|
+
getConnection: async () => assert.fail("no connection is needed"),
|
|
140
|
+
},
|
|
141
|
+
);
|
|
288
142
|
|
|
289
143
|
assert.deepEqual(result, {
|
|
290
144
|
reconciledMessageIds: [],
|
|
291
145
|
brokenMessageIds: [],
|
|
292
146
|
});
|
|
293
|
-
assert.equal(connectionRequested, false);
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
describe("isMessageBodySyncBroken", () => {
|
|
298
|
-
it("delegates to bodyPartExists with the sentinel path", async () => {
|
|
299
|
-
const { storageService } = buildStorageService(new Set(["msg-1"]));
|
|
300
|
-
|
|
301
|
-
assert.equal(
|
|
302
|
-
await isMessageBodySyncBroken(storageService, "cfg-1", "acc-1", "msg-1"),
|
|
303
|
-
true,
|
|
304
|
-
);
|
|
305
|
-
assert.equal(
|
|
306
|
-
await isMessageBodySyncBroken(storageService, "cfg-1", "acc-1", "msg-2"),
|
|
307
|
-
false,
|
|
308
|
-
);
|
|
309
147
|
});
|
|
310
148
|
});
|
|
@@ -2,10 +2,6 @@ import type { IMessageRepository } from "@remit/data-ports";
|
|
|
2
2
|
import type { StorageService } from "@remit/storage-service";
|
|
3
3
|
import type { BodySyncLogger } from "./body-sync.js";
|
|
4
4
|
import { isMessageGoneFromOpenMailbox } from "./message-presence.js";
|
|
5
|
-
import {
|
|
6
|
-
reconcileStaleMessage,
|
|
7
|
-
type StaleMessageReconcileDeps,
|
|
8
|
-
} from "./stale-message-reconcile.js";
|
|
9
5
|
import type { IImapConnection } from "./types.js";
|
|
10
6
|
|
|
11
7
|
/**
|
|
@@ -17,9 +13,8 @@ import type { IImapConnection } from "./types.js";
|
|
|
17
13
|
*/
|
|
18
14
|
const BODY_SYNC_FAILED_MARKER_PATH = ".sync-failed";
|
|
19
15
|
|
|
20
|
-
export interface ResolveExhaustedBodySyncDeps
|
|
21
|
-
|
|
22
|
-
messageService: Pick<IMessageRepository, "get" | "delete">;
|
|
16
|
+
export interface ResolveExhaustedBodySyncDeps {
|
|
17
|
+
messageService: Pick<IMessageRepository, "get" | "deleteIfPlacement">;
|
|
23
18
|
storageService: Pick<StorageService, "storeBodyPart" | "bodyPartExists">;
|
|
24
19
|
log: BodySyncLogger;
|
|
25
20
|
}
|
|
@@ -90,7 +85,7 @@ const markMessageBodySyncFailed = async (
|
|
|
90
85
|
* the four sites that used to read an empty FETCH as absence: it issues
|
|
91
86
|
* back-to-back single-UID FETCHes on one connection, which is the
|
|
92
87
|
* condition imapflow #408 drops rows under. The stale row is deleted via
|
|
93
|
-
*
|
|
88
|
+
* `deleteIfPlacement` so the existing missing-row 404 path
|
|
94
89
|
* takes over. Callers should emit a metric only — this is routine, not an
|
|
95
90
|
* incident.
|
|
96
91
|
* 2. BROKEN — the message still exists on IMAP but its body could not be
|
|
@@ -130,10 +125,13 @@ export const resolveExhaustedBodySyncFailures = async (
|
|
|
130
125
|
const message = await deps.messageService.get(messageId);
|
|
131
126
|
|
|
132
127
|
if (await isMessageGoneFromOpenMailbox(connection, message.uid)) {
|
|
133
|
-
const
|
|
134
|
-
deps,
|
|
135
|
-
accountConfigId,
|
|
128
|
+
const reconciled = await deps.messageService.deleteIfPlacement(
|
|
136
129
|
messageId,
|
|
130
|
+
{
|
|
131
|
+
status: message.status,
|
|
132
|
+
mailboxId: message.mailboxId,
|
|
133
|
+
uid: message.uid,
|
|
134
|
+
},
|
|
137
135
|
);
|
|
138
136
|
deps.log.info(
|
|
139
137
|
{
|
|
@@ -143,7 +141,7 @@ export const resolveExhaustedBodySyncFailures = async (
|
|
|
143
141
|
mailboxId,
|
|
144
142
|
messageId,
|
|
145
143
|
uid: message.uid,
|
|
146
|
-
|
|
144
|
+
reconciled,
|
|
147
145
|
},
|
|
148
146
|
"Message no longer exists on IMAP after retry exhaustion; stale row reconciled",
|
|
149
147
|
);
|