@remit/mailbox-service 0.0.111 → 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 +156 -235
- 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 +5 -4
- 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/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-message-gone.test.ts +0 -139
- 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,501 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `Address.flags.category` overrides classification at sync time (issue #299,
|
|
3
|
-
* RFC 039 Decision 3, closing item 3 of RFC 039). A user who has told Remit
|
|
4
|
-
* "this sender is actually Personal, not Marketing" via the Reclassify dialog
|
|
5
|
-
* (`PATCH /addresses/{id}`) gets that category on the sender's next message,
|
|
6
|
-
* instead of `classifyByHeaders` re-deriving the same header-driven verdict
|
|
7
|
-
* every time.
|
|
8
|
-
*
|
|
9
|
-
* The override sits behind the same `hasDecidedCategory` write-once gate #378
|
|
10
|
-
* added for `Message.category` (RFC 034 Decision 3.1, RFC 030's message-list
|
|
11
|
-
* GSI sort key depends on it never churning): a message already carrying a
|
|
12
|
-
* real category is never re-touched, override present or not. The two tests
|
|
13
|
-
* under "survives a re-entrant pass" feed a *differing* override to an
|
|
14
|
-
* already-classified message through both shipped re-entry paths — the
|
|
15
|
-
* `NoSuchKey` IMAP re-fetch and `syncBodies(..., force: true)` — so a
|
|
16
|
-
* regression that let the override bypass the guard shows up here, not just
|
|
17
|
-
* in an isolated unit check.
|
|
18
|
-
*
|
|
19
|
-
* The override reaches a message on the pass that examines it, and only then
|
|
20
|
-
* (issue #331). Mail already stored and examined is not revisited, whatever the
|
|
21
|
-
* user later says about the sender: an ordinary sync pass does not re-read a
|
|
22
|
-
* stored body, and the last test here pins that. Applying a reclassification
|
|
23
|
-
* backwards over mail already on disk is a deliberate operation over
|
|
24
|
-
* `Message.classificationState`, tracked in issue #415, and nothing in this
|
|
25
|
-
* file claims it happens today.
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
import assert from "node:assert/strict";
|
|
29
|
-
import { Readable } from "node:stream";
|
|
30
|
-
import { describe, it } from "node:test";
|
|
31
|
-
import type {
|
|
32
|
-
AddressItem,
|
|
33
|
-
IAddressRepository,
|
|
34
|
-
IEnvelopeRepository,
|
|
35
|
-
IMessageRepository,
|
|
36
|
-
IThreadMessageRepository,
|
|
37
|
-
MessageItem,
|
|
38
|
-
ThreadMessageItem,
|
|
39
|
-
UpdateMessageInput,
|
|
40
|
-
UpdateThreadMessageInput,
|
|
41
|
-
} from "@remit/data-ports";
|
|
42
|
-
import { NotFoundError } from "@remit/data-ports/errors";
|
|
43
|
-
import { MessageCategory } from "@remit/domain-enums";
|
|
44
|
-
import type { StorageService } from "@remit/storage-service";
|
|
45
|
-
import { BodySyncService } from "./body-sync.js";
|
|
46
|
-
import type { IImapConnection } from "./types.js";
|
|
47
|
-
|
|
48
|
-
const LINKEDIN_EML = Buffer.from(
|
|
49
|
-
[
|
|
50
|
-
"From: LinkedIn <messages-noreply@linkedin.com>",
|
|
51
|
-
"To: me@example.com",
|
|
52
|
-
"Subject: You have a new invitation",
|
|
53
|
-
"List-Unsubscribe: <https://www.linkedin.com/e/unsub>",
|
|
54
|
-
"Content-Type: text/plain",
|
|
55
|
-
"",
|
|
56
|
-
"invitation",
|
|
57
|
-
].join("\r\n"),
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
interface ThreadUpdate {
|
|
61
|
-
threadMessageId: string;
|
|
62
|
-
input: UpdateThreadMessageInput;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
interface Harness {
|
|
66
|
-
service: BodySyncService;
|
|
67
|
-
message: MessageItem;
|
|
68
|
-
rows: ThreadMessageItem[];
|
|
69
|
-
messageUpdates: Array<{ messageId: string; input: UpdateMessageInput }>;
|
|
70
|
-
threadUpdates: ThreadUpdate[];
|
|
71
|
-
getAddressCalls: number;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const buildHarness = (
|
|
75
|
-
message: Partial<MessageItem> & Pick<MessageItem, "messageId">,
|
|
76
|
-
flags: AddressItem["flags"] | undefined,
|
|
77
|
-
retrieve: () => Promise<Buffer> = async () => {
|
|
78
|
-
throw new Error("no body configured for retrieve()");
|
|
79
|
-
},
|
|
80
|
-
): Harness => {
|
|
81
|
-
const messageUpdates: Array<{
|
|
82
|
-
messageId: string;
|
|
83
|
-
input: UpdateMessageInput;
|
|
84
|
-
}> = [];
|
|
85
|
-
const threadUpdates: ThreadUpdate[] = [];
|
|
86
|
-
let getAddressCalls = 0;
|
|
87
|
-
|
|
88
|
-
const messageRow = {
|
|
89
|
-
uid: 1,
|
|
90
|
-
mailboxId: "mb-1",
|
|
91
|
-
category: MessageCategory.uncategorized,
|
|
92
|
-
...message,
|
|
93
|
-
} as unknown as MessageItem;
|
|
94
|
-
|
|
95
|
-
const rows: ThreadMessageItem[] = [
|
|
96
|
-
{
|
|
97
|
-
threadMessageId: "tm-1",
|
|
98
|
-
messageId: message.messageId,
|
|
99
|
-
mailboxId: "mb-1",
|
|
100
|
-
sentDate: 1,
|
|
101
|
-
isRead: false,
|
|
102
|
-
isDeleted: false,
|
|
103
|
-
hasStars: false,
|
|
104
|
-
hasAttachment: false,
|
|
105
|
-
category: messageRow.category,
|
|
106
|
-
} as unknown as ThreadMessageItem,
|
|
107
|
-
];
|
|
108
|
-
|
|
109
|
-
const messageService = {
|
|
110
|
-
get: async () => messageRow,
|
|
111
|
-
update: async (messageId: string, input: UpdateMessageInput) => {
|
|
112
|
-
messageUpdates.push({ messageId, input });
|
|
113
|
-
Object.assign(messageRow, input);
|
|
114
|
-
},
|
|
115
|
-
} as unknown as IMessageRepository;
|
|
116
|
-
|
|
117
|
-
const threadMessageService = {
|
|
118
|
-
findAllByMessageId: async () => rows,
|
|
119
|
-
update: async (
|
|
120
|
-
_accountConfigId: string,
|
|
121
|
-
threadMessageId: string,
|
|
122
|
-
input: UpdateThreadMessageInput,
|
|
123
|
-
) => {
|
|
124
|
-
threadUpdates.push({ threadMessageId, input });
|
|
125
|
-
const row = rows.find((r) => r.threadMessageId === threadMessageId);
|
|
126
|
-
if (row) Object.assign(row, input);
|
|
127
|
-
},
|
|
128
|
-
} as unknown as IThreadMessageRepository;
|
|
129
|
-
|
|
130
|
-
const storageService = {
|
|
131
|
-
retrieve,
|
|
132
|
-
storeMessageBody: async () => ({ uri: `s3://bodies/${message.messageId}` }),
|
|
133
|
-
storeMessageBodyStream: async () => ({
|
|
134
|
-
uri: `s3://bodies/${message.messageId}`,
|
|
135
|
-
}),
|
|
136
|
-
storeParsedBody: async () => {},
|
|
137
|
-
listBodyParts: async () => [],
|
|
138
|
-
} as unknown as StorageService;
|
|
139
|
-
|
|
140
|
-
const addressService = {
|
|
141
|
-
getAddress: async () => {
|
|
142
|
-
getAddressCalls++;
|
|
143
|
-
if (flags === undefined) {
|
|
144
|
-
throw new NotFoundError("Address not found");
|
|
145
|
-
}
|
|
146
|
-
return { flags } as unknown as AddressItem;
|
|
147
|
-
},
|
|
148
|
-
incrementInboundCount: async () => {},
|
|
149
|
-
} as unknown as IAddressRepository;
|
|
150
|
-
|
|
151
|
-
const envelopeService = {
|
|
152
|
-
listBodyParts: async () => [],
|
|
153
|
-
} as unknown as IEnvelopeRepository;
|
|
154
|
-
|
|
155
|
-
const service = new BodySyncService(
|
|
156
|
-
messageService,
|
|
157
|
-
storageService,
|
|
158
|
-
threadMessageService,
|
|
159
|
-
addressService,
|
|
160
|
-
envelopeService,
|
|
161
|
-
{ info: () => {}, error: () => {} },
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
return {
|
|
165
|
-
service,
|
|
166
|
-
message: messageRow,
|
|
167
|
-
rows,
|
|
168
|
-
messageUpdates,
|
|
169
|
-
threadUpdates,
|
|
170
|
-
get getAddressCalls() {
|
|
171
|
-
return getAddressCalls;
|
|
172
|
-
},
|
|
173
|
-
};
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
const noSuchKeyError = () =>
|
|
177
|
-
Object.assign(new Error("missing"), { name: "NoSuchKey" });
|
|
178
|
-
|
|
179
|
-
const overrideFlags = (
|
|
180
|
-
category: (typeof MessageCategory)[keyof typeof MessageCategory],
|
|
181
|
-
): AddressItem["flags"] =>
|
|
182
|
-
({
|
|
183
|
-
category: { value: category, setAt: 1_000 },
|
|
184
|
-
}) as unknown as AddressItem["flags"];
|
|
185
|
-
|
|
186
|
-
describe("Address.flags.category overrides classification at sync time (issue #299)", () => {
|
|
187
|
-
it("classifies a new message by the sender's override, not the header-derived category", async () => {
|
|
188
|
-
const harness = buildHarness(
|
|
189
|
-
{ messageId: "m-1", category: MessageCategory.uncategorized },
|
|
190
|
-
overrideFlags(MessageCategory.personal),
|
|
191
|
-
);
|
|
192
|
-
|
|
193
|
-
const connection = {
|
|
194
|
-
openBox: async () => {},
|
|
195
|
-
fetchMessageBody: async () => LINKEDIN_EML,
|
|
196
|
-
} as unknown as IImapConnection;
|
|
197
|
-
|
|
198
|
-
await harness.service.fetchAndGetBody(
|
|
199
|
-
"m-1",
|
|
200
|
-
"acc-1",
|
|
201
|
-
"cfg-1",
|
|
202
|
-
{ fullPath: "INBOX", placement: "inbox" },
|
|
203
|
-
async () => connection,
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
assert.equal(harness.messageUpdates.length, 1);
|
|
207
|
-
assert.equal(
|
|
208
|
-
harness.messageUpdates[0].input.category,
|
|
209
|
-
MessageCategory.personal,
|
|
210
|
-
);
|
|
211
|
-
assert.equal(harness.message.category, MessageCategory.personal);
|
|
212
|
-
// No placementConfig is wired in this harness, so the override's own
|
|
213
|
-
// Address read is the only one classification makes per message.
|
|
214
|
-
assert.equal(harness.getAddressCalls, 1);
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
it("denormalizes the override onto the ThreadMessage, matching the Message row", async () => {
|
|
218
|
-
const harness = buildHarness(
|
|
219
|
-
{ messageId: "m-1", category: MessageCategory.uncategorized },
|
|
220
|
-
overrideFlags(MessageCategory.personal),
|
|
221
|
-
);
|
|
222
|
-
|
|
223
|
-
const connection = {
|
|
224
|
-
openBox: async () => {},
|
|
225
|
-
fetchMessageBody: async () => LINKEDIN_EML,
|
|
226
|
-
} as unknown as IImapConnection;
|
|
227
|
-
|
|
228
|
-
await harness.service.fetchAndGetBody(
|
|
229
|
-
"m-1",
|
|
230
|
-
"acc-1",
|
|
231
|
-
"cfg-1",
|
|
232
|
-
{ fullPath: "INBOX", placement: "inbox" },
|
|
233
|
-
async () => connection,
|
|
234
|
-
);
|
|
235
|
-
|
|
236
|
-
assert.equal(harness.rows[0].category, MessageCategory.personal);
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
it("classifies by headers as usual when the sender has no category override", async () => {
|
|
240
|
-
const harness = buildHarness(
|
|
241
|
-
{ messageId: "m-1", category: MessageCategory.uncategorized },
|
|
242
|
-
undefined,
|
|
243
|
-
);
|
|
244
|
-
|
|
245
|
-
const connection = {
|
|
246
|
-
openBox: async () => {},
|
|
247
|
-
fetchMessageBody: async () => LINKEDIN_EML,
|
|
248
|
-
} as unknown as IImapConnection;
|
|
249
|
-
|
|
250
|
-
await harness.service.fetchAndGetBody(
|
|
251
|
-
"m-1",
|
|
252
|
-
"acc-1",
|
|
253
|
-
"cfg-1",
|
|
254
|
-
{ fullPath: "INBOX", placement: "inbox" },
|
|
255
|
-
async () => connection,
|
|
256
|
-
);
|
|
257
|
-
|
|
258
|
-
assert.equal(
|
|
259
|
-
harness.messageUpdates[0].input.category,
|
|
260
|
-
MessageCategory.social,
|
|
261
|
-
);
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
it("classifies by headers as usual when the sender has flags but no category entry", async () => {
|
|
265
|
-
const harness = buildHarness(
|
|
266
|
-
{ messageId: "m-1", category: MessageCategory.uncategorized },
|
|
267
|
-
{ vip: { value: true, setAt: 1 } } as unknown as AddressItem["flags"],
|
|
268
|
-
);
|
|
269
|
-
|
|
270
|
-
const connection = {
|
|
271
|
-
openBox: async () => {},
|
|
272
|
-
fetchMessageBody: async () => LINKEDIN_EML,
|
|
273
|
-
} as unknown as IImapConnection;
|
|
274
|
-
|
|
275
|
-
await harness.service.fetchAndGetBody(
|
|
276
|
-
"m-1",
|
|
277
|
-
"acc-1",
|
|
278
|
-
"cfg-1",
|
|
279
|
-
{ fullPath: "INBOX", placement: "inbox" },
|
|
280
|
-
async () => connection,
|
|
281
|
-
);
|
|
282
|
-
|
|
283
|
-
assert.equal(
|
|
284
|
-
harness.messageUpdates[0].input.category,
|
|
285
|
-
MessageCategory.social,
|
|
286
|
-
);
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
it("reaches a message still awaiting examination on the batch sync path too", async () => {
|
|
290
|
-
const harness = buildHarness(
|
|
291
|
-
{ messageId: "m-1", category: MessageCategory.uncategorized },
|
|
292
|
-
overrideFlags(MessageCategory.transactional),
|
|
293
|
-
);
|
|
294
|
-
|
|
295
|
-
const result = await harness.service.syncBodies(
|
|
296
|
-
["m-1"],
|
|
297
|
-
"acc-1",
|
|
298
|
-
"cfg-1",
|
|
299
|
-
{ fullPath: "INBOX", placement: "inbox" },
|
|
300
|
-
async () =>
|
|
301
|
-
({
|
|
302
|
-
openBox: async () => {},
|
|
303
|
-
async *fetchMessageBodies(uids: number[]) {
|
|
304
|
-
for (const uid of uids) {
|
|
305
|
-
yield { uid, source: Readable.from([LINKEDIN_EML]) };
|
|
306
|
-
}
|
|
307
|
-
},
|
|
308
|
-
}) as unknown as IImapConnection,
|
|
309
|
-
);
|
|
310
|
-
|
|
311
|
-
assert.deepEqual(result.syncedMessageIds, ["m-1"]);
|
|
312
|
-
assert.equal(harness.messageUpdates.length, 1);
|
|
313
|
-
assert.equal(
|
|
314
|
-
harness.messageUpdates[0].input.category,
|
|
315
|
-
MessageCategory.transactional,
|
|
316
|
-
);
|
|
317
|
-
assert.equal(harness.rows[0].category, MessageCategory.transactional);
|
|
318
|
-
assert.equal(
|
|
319
|
-
harness.messageUpdates[0].input.classificationState,
|
|
320
|
-
"Examined",
|
|
321
|
-
);
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
it("does not reach back to mail it already examined when the sender is reclassified later", async () => {
|
|
325
|
-
const harness = buildHarness(
|
|
326
|
-
{
|
|
327
|
-
messageId: "m-1",
|
|
328
|
-
bodyStorageKey: "s3://bodies/m-1",
|
|
329
|
-
category: MessageCategory.uncategorized,
|
|
330
|
-
classificationState: "Examined",
|
|
331
|
-
} as Partial<MessageItem> & Pick<MessageItem, "messageId">,
|
|
332
|
-
overrideFlags(MessageCategory.transactional),
|
|
333
|
-
);
|
|
334
|
-
|
|
335
|
-
const result = await harness.service.syncBodies(
|
|
336
|
-
["m-1"],
|
|
337
|
-
"acc-1",
|
|
338
|
-
"cfg-1",
|
|
339
|
-
{ fullPath: "INBOX", placement: "inbox" },
|
|
340
|
-
async () => {
|
|
341
|
-
throw new Error("an examined message must not be fetched again");
|
|
342
|
-
},
|
|
343
|
-
);
|
|
344
|
-
|
|
345
|
-
// The harness's default `retrieve` throws, so a storage read would fail
|
|
346
|
-
// this outright. Reaching back is the back-apply job's work (#415,
|
|
347
|
-
// `backApplySenderCategory`), fired by the flag PATCH; a sync pass is
|
|
348
|
-
// still not it.
|
|
349
|
-
assert.equal(result.skippedCount, 1);
|
|
350
|
-
assert.deepEqual(result.failedMessageIds, []);
|
|
351
|
-
assert.deepEqual(harness.messageUpdates, []);
|
|
352
|
-
assert.deepEqual(harness.threadUpdates, []);
|
|
353
|
-
assert.equal(harness.message.category, MessageCategory.uncategorized);
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
describe("survives a re-entrant pass with a differing override already set", () => {
|
|
357
|
-
it("keeps the already-decided category through the NoSuchKey IMAP re-fetch", async () => {
|
|
358
|
-
const harness = buildHarness(
|
|
359
|
-
{
|
|
360
|
-
messageId: "m-1",
|
|
361
|
-
bodyStorageKey: "s3://bodies/m-1",
|
|
362
|
-
category: MessageCategory.marketing,
|
|
363
|
-
},
|
|
364
|
-
overrideFlags(MessageCategory.personal),
|
|
365
|
-
async () => {
|
|
366
|
-
throw noSuchKeyError();
|
|
367
|
-
},
|
|
368
|
-
);
|
|
369
|
-
|
|
370
|
-
const connection = {
|
|
371
|
-
openBox: async () => {},
|
|
372
|
-
fetchMessageBody: async () => LINKEDIN_EML,
|
|
373
|
-
} as unknown as IImapConnection;
|
|
374
|
-
|
|
375
|
-
await harness.service.fetchAndGetBody(
|
|
376
|
-
"m-1",
|
|
377
|
-
"acc-1",
|
|
378
|
-
"cfg-1",
|
|
379
|
-
{ fullPath: "INBOX", placement: "inbox" },
|
|
380
|
-
async () => connection,
|
|
381
|
-
);
|
|
382
|
-
|
|
383
|
-
assert.equal(harness.messageUpdates.length, 1);
|
|
384
|
-
// Re-store writes only bodyStorageKey — category untouched on row + thread.
|
|
385
|
-
assert.equal(harness.messageUpdates[0].input.category, undefined);
|
|
386
|
-
assert.equal(harness.message.category, MessageCategory.marketing);
|
|
387
|
-
assert.equal(harness.rows[0].category, MessageCategory.marketing);
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
it("keeps the already-decided category when syncBodies re-fetches with force", async () => {
|
|
391
|
-
const harness = buildHarness(
|
|
392
|
-
{
|
|
393
|
-
messageId: "m-1",
|
|
394
|
-
bodyStorageKey: "s3://bodies/m-1",
|
|
395
|
-
category: MessageCategory.marketing,
|
|
396
|
-
},
|
|
397
|
-
overrideFlags(MessageCategory.personal),
|
|
398
|
-
async () => {
|
|
399
|
-
throw new Error("force path must not retrieve from storage");
|
|
400
|
-
},
|
|
401
|
-
);
|
|
402
|
-
|
|
403
|
-
const connection = {
|
|
404
|
-
openBox: async () => {},
|
|
405
|
-
async *fetchMessageBodies(uids: number[]) {
|
|
406
|
-
for (const uid of uids) {
|
|
407
|
-
yield { uid, source: Readable.from([LINKEDIN_EML]) };
|
|
408
|
-
}
|
|
409
|
-
},
|
|
410
|
-
} as unknown as IImapConnection;
|
|
411
|
-
|
|
412
|
-
const result = await harness.service.syncBodies(
|
|
413
|
-
["m-1"],
|
|
414
|
-
"acc-1",
|
|
415
|
-
"cfg-1",
|
|
416
|
-
{ fullPath: "INBOX", placement: "inbox" },
|
|
417
|
-
async () => connection,
|
|
418
|
-
true,
|
|
419
|
-
);
|
|
420
|
-
|
|
421
|
-
assert.deepEqual(result.syncedMessageIds, ["m-1"]);
|
|
422
|
-
assert.equal(harness.messageUpdates.length, 1);
|
|
423
|
-
// Re-store writes only bodyStorageKey — category untouched on row + thread.
|
|
424
|
-
assert.equal(harness.messageUpdates[0].input.category, undefined);
|
|
425
|
-
assert.equal(harness.message.category, MessageCategory.marketing);
|
|
426
|
-
assert.equal(harness.rows[0].category, MessageCategory.marketing);
|
|
427
|
-
});
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
it("propagates a non-NotFound Address lookup failure instead of silently classifying by headers", async () => {
|
|
431
|
-
const message = {
|
|
432
|
-
messageId: "m-1",
|
|
433
|
-
category: MessageCategory.uncategorized,
|
|
434
|
-
};
|
|
435
|
-
const messageRow = { uid: 1, mailboxId: "mb-1", ...message } as MessageItem;
|
|
436
|
-
|
|
437
|
-
const messageService = {
|
|
438
|
-
get: async () => messageRow,
|
|
439
|
-
update: async () => {},
|
|
440
|
-
} as unknown as IMessageRepository;
|
|
441
|
-
|
|
442
|
-
const threadMessageService = {
|
|
443
|
-
findAllByMessageId: async () => [
|
|
444
|
-
{
|
|
445
|
-
threadMessageId: "tm-1",
|
|
446
|
-
mailboxId: "mb-1",
|
|
447
|
-
sentDate: 1,
|
|
448
|
-
isRead: false,
|
|
449
|
-
isDeleted: false,
|
|
450
|
-
hasStars: false,
|
|
451
|
-
hasAttachment: false,
|
|
452
|
-
},
|
|
453
|
-
],
|
|
454
|
-
update: async () => {},
|
|
455
|
-
} as unknown as IThreadMessageRepository;
|
|
456
|
-
|
|
457
|
-
const storageService = {
|
|
458
|
-
storeMessageBody: async () => ({ uri: "s3://bodies/m-1" }),
|
|
459
|
-
storeParsedBody: async () => {},
|
|
460
|
-
listBodyParts: async () => [],
|
|
461
|
-
} as unknown as StorageService;
|
|
462
|
-
|
|
463
|
-
const addressService = {
|
|
464
|
-
getAddress: async () => {
|
|
465
|
-
const error = new Error("ProvisionedThroughputExceededException");
|
|
466
|
-
error.name = "ProvisionedThroughputExceededException";
|
|
467
|
-
throw error;
|
|
468
|
-
},
|
|
469
|
-
incrementInboundCount: async () => {},
|
|
470
|
-
} as unknown as IAddressRepository;
|
|
471
|
-
|
|
472
|
-
const envelopeService = {
|
|
473
|
-
listBodyParts: async () => [],
|
|
474
|
-
} as unknown as IEnvelopeRepository;
|
|
475
|
-
|
|
476
|
-
const service = new BodySyncService(
|
|
477
|
-
messageService,
|
|
478
|
-
storageService,
|
|
479
|
-
threadMessageService,
|
|
480
|
-
addressService,
|
|
481
|
-
envelopeService,
|
|
482
|
-
{ info: () => {}, error: () => {} },
|
|
483
|
-
);
|
|
484
|
-
|
|
485
|
-
const connection = {
|
|
486
|
-
openBox: async () => {},
|
|
487
|
-
fetchMessageBody: async () => LINKEDIN_EML,
|
|
488
|
-
} as unknown as IImapConnection;
|
|
489
|
-
|
|
490
|
-
await assert.rejects(
|
|
491
|
-
service.fetchAndGetBody(
|
|
492
|
-
"m-1",
|
|
493
|
-
"acc-1",
|
|
494
|
-
"cfg-1",
|
|
495
|
-
{ fullPath: "INBOX", placement: "inbox" },
|
|
496
|
-
async () => connection,
|
|
497
|
-
),
|
|
498
|
-
/ProvisionedThroughputExceededException/,
|
|
499
|
-
);
|
|
500
|
-
});
|
|
501
|
-
});
|