@remit/mailbox-service 0.0.112 → 0.0.114
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/dist/account-credentials.d.ts +83 -0
- package/dist/account-credentials.js +104 -0
- package/dist/attribute-mapper.d.ts +36 -0
- package/dist/attribute-mapper.js +119 -0
- package/dist/body-parse.d.ts +28 -0
- package/{src/body-parse.ts → dist/body-parse.js} +18 -26
- package/dist/body-part-mapper.d.ts +92 -0
- package/dist/body-part-mapper.js +301 -0
- package/dist/body-sync-queue.d.ts +59 -0
- package/dist/body-sync-queue.js +56 -0
- package/dist/body-sync-terminal.d.ts +58 -0
- package/dist/body-sync-terminal.js +95 -0
- package/dist/body-sync.d.ts +351 -0
- package/dist/body-sync.js +1204 -0
- package/dist/calendar-parts.d.ts +23 -0
- package/dist/calendar-parts.js +18 -0
- package/dist/classification-backfill.d.ts +91 -0
- package/dist/classification-backfill.js +180 -0
- package/dist/classify-message.d.ts +31 -0
- package/dist/classify-message.js +89 -0
- package/dist/connection-factory.d.ts +54 -0
- package/dist/connection-factory.js +54 -0
- package/dist/connection-test.d.ts +41 -0
- package/dist/connection-test.js +152 -0
- package/dist/external-move.d.ts +94 -0
- package/dist/external-move.js +173 -0
- package/dist/filter-operations.d.ts +42 -0
- package/dist/filter-operations.js +211 -0
- package/dist/filters/filter-config.d.ts +14 -0
- package/dist/filters/filter-config.js +10 -0
- package/{src/filters/list-id.ts → dist/filters/list-id.d.ts} +2 -16
- package/dist/filters/list-id.js +26 -0
- package/dist/filters/match.d.ts +69 -0
- package/dist/filters/match.js +165 -0
- package/dist/filters/pipeline.d.ts +64 -0
- package/dist/filters/pipeline.js +100 -0
- package/{src/flag-push-terminal.ts → dist/flag-push-terminal.d.ts} +16 -72
- package/dist/flag-push-terminal.js +63 -0
- package/dist/flag-push.d.ts +69 -0
- package/dist/flag-push.js +111 -0
- package/dist/flag-queue.d.ts +175 -0
- package/dist/flag-queue.js +291 -0
- package/dist/folder-operations.d.ts +39 -0
- package/dist/folder-operations.js +112 -0
- package/dist/folder-placement.d.ts +13 -0
- package/dist/folder-placement.js +23 -0
- package/dist/heuristics/authenticationResults.d.ts +10 -0
- package/dist/heuristics/authenticationResults.js +187 -0
- package/dist/heuristics/classifyByHeaders.d.ts +82 -0
- package/dist/heuristics/classifyByHeaders.js +365 -0
- package/dist/heuristics/classifyPlacement.d.ts +67 -0
- package/dist/heuristics/classifyPlacement.js +153 -0
- package/dist/heuristics/machineSenders.d.ts +21 -0
- package/{src/heuristics/machineSenders.ts → dist/heuristics/machineSenders.js} +34 -40
- package/dist/heuristics/senderMismatch.d.ts +81 -0
- package/dist/heuristics/senderMismatch.js +192 -0
- package/dist/heuristics/socialDomains.d.ts +14 -0
- package/{src/heuristics/socialDomains.ts → dist/heuristics/socialDomains.js} +9 -9
- package/dist/heuristics/transactionalDomains.d.ts +18 -0
- package/{src/heuristics/transactionalDomains.ts → dist/heuristics/transactionalDomains.js} +8 -8
- package/dist/imapflow-connection.d.ts +377 -0
- package/dist/imapflow-connection.js +1147 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +65 -0
- package/dist/list-id-backfill.d.ts +83 -0
- package/dist/list-id-backfill.js +132 -0
- package/dist/mailbox-cursor-rebuild.d.ts +74 -0
- package/dist/mailbox-cursor-rebuild.js +71 -0
- package/{src/mailbox-cursor.ts → dist/mailbox-cursor.d.ts} +20 -98
- package/dist/mailbox-cursor.js +102 -0
- package/dist/mailbox-intent.d.ts +41 -0
- package/{src/mailbox-intent.ts → dist/mailbox-intent.js} +38 -64
- package/dist/mailbox-management.d.ts +240 -0
- package/dist/mailbox-management.js +576 -0
- package/dist/mailbox-presence.d.ts +52 -0
- package/{src/mailbox-presence.ts → dist/mailbox-presence.js} +19 -30
- package/dist/mailbox-queue.d.ts +129 -0
- package/dist/mailbox-queue.js +216 -0
- package/dist/mailbox-sync.d.ts +93 -0
- package/dist/mailbox-sync.js +490 -0
- package/dist/mailbox-upstream.d.ts +38 -0
- package/{src/mailbox-upstream.ts → dist/mailbox-upstream.js} +37 -47
- package/dist/message-category.d.ts +51 -0
- package/{src/message-category.ts → dist/message-category.js} +28 -71
- package/dist/message-move.d.ts +285 -0
- package/dist/message-move.js +858 -0
- package/dist/message-parser.d.ts +14 -0
- package/dist/message-parser.js +17 -0
- package/{src/message-presence.ts → dist/message-presence.d.ts} +1 -13
- package/dist/message-presence.js +29 -0
- package/dist/message-read.d.ts +51 -0
- package/dist/message-read.js +31 -0
- package/dist/message-sync.d.ts +345 -0
- package/dist/message-sync.js +1358 -0
- package/dist/mime-walker.d.ts +102 -0
- package/dist/mime-walker.js +198 -0
- package/dist/organize-job.d.ts +20 -0
- package/dist/organize-job.js +37 -0
- package/dist/outbox-attachment-content.d.ts +37 -0
- package/dist/outbox-attachment-content.js +50 -0
- package/dist/outbox-attachment-filename.d.ts +19 -0
- package/dist/outbox-attachment-filename.js +64 -0
- package/dist/outbox-attachment.d.ts +148 -0
- package/dist/outbox-attachment.js +273 -0
- package/dist/outbox-queue.d.ts +73 -0
- package/dist/outbox-queue.js +280 -0
- package/{src/outbox-status.ts → dist/outbox-status.d.ts} +1 -6
- package/dist/outbox-status.js +18 -0
- package/dist/ownership.d.ts +24 -0
- package/dist/ownership.js +83 -0
- package/dist/placement-move-terminal.d.ts +67 -0
- package/dist/placement-move-terminal.js +88 -0
- package/dist/placement-move.d.ts +83 -0
- package/dist/placement-move.js +216 -0
- package/{src/placement-settled.ts → dist/placement-settled.d.ts} +13 -68
- package/dist/placement-settled.js +75 -0
- package/dist/quarantine.d.ts +95 -0
- package/dist/quarantine.js +131 -0
- package/dist/refusal.d.ts +31 -0
- package/dist/refusal.js +3 -0
- package/{src/restore-source-placement.ts → dist/restore-source-placement.d.ts} +29 -97
- package/dist/restore-source-placement.js +79 -0
- package/dist/search-text-backfill.d.ts +15 -0
- package/dist/search-text-backfill.js +33 -0
- package/dist/snippet.d.ts +61 -0
- package/dist/snippet.js +129 -0
- package/dist/spam-report.d.ts +86 -0
- package/dist/spam-report.js +241 -0
- package/dist/sync-warning.d.ts +21 -0
- package/dist/sync-warning.js +26 -0
- package/dist/sync-watermarks.d.ts +138 -0
- package/dist/sync-watermarks.js +205 -0
- package/dist/test-helpers/fake-imap.d.ts +151 -0
- package/dist/test-helpers/fake-imap.js +508 -0
- package/dist/test-helpers/folder-roles.d.ts +34 -0
- package/dist/test-helpers/folder-roles.js +47 -0
- package/dist/test-helpers/mime-tree-generator.d.ts +82 -0
- package/dist/test-helpers/mime-tree-generator.js +329 -0
- package/dist/test-helpers/test-store.d.ts +69 -0
- package/dist/test-helpers/test-store.js +193 -0
- package/dist/text/normalizer.d.ts +20 -0
- package/dist/text/normalizer.js +102 -0
- package/dist/thread-message-rows.d.ts +69 -0
- package/dist/thread-message-rows.js +40 -0
- package/dist/thread-root.d.ts +7 -0
- package/dist/thread-root.js +25 -0
- package/dist/types.d.ts +343 -0
- package/dist/types.js +19 -0
- package/package.json +86 -88
- package/src/account-credentials.ts +0 -210
- package/src/attribute-mapper.test.ts +0 -104
- package/src/attribute-mapper.ts +0 -148
- package/src/body-parse.test.ts +0 -55
- package/src/body-part-mapper.property.test.ts +0 -354
- package/src/body-part-mapper.ts +0 -410
- package/src/body-sync-queue.test.ts +0 -64
- package/src/body-sync-queue.ts +0 -131
- package/src/body-sync-terminal.test.ts +0 -148
- package/src/body-sync-terminal.ts +0 -174
- package/src/body-sync.test.ts +0 -925
- package/src/body-sync.ts +0 -1891
- package/src/calendar-parts.ts +0 -41
- package/src/classification-backfill.test.ts +0 -285
- package/src/classification-backfill.ts +0 -363
- package/src/classify-message.test.ts +0 -142
- package/src/classify-message.ts +0 -116
- package/src/connection-factory.ts +0 -102
- package/src/connection-test.ts +0 -208
- package/src/credentials.test.ts +0 -181
- package/src/external-move.test.ts +0 -262
- package/src/external-move.ts +0 -285
- package/src/filter-operations.test.ts +0 -319
- package/src/filter-operations.ts +0 -377
- package/src/filter-update.test.ts +0 -313
- package/src/filters/filter-config.test.ts +0 -87
- package/src/filters/filter-config.ts +0 -34
- package/src/filters/list-id.test.ts +0 -50
- package/src/filters/match.test.ts +0 -392
- package/src/filters/match.ts +0 -225
- package/src/filters/pipeline.test.ts +0 -199
- package/src/filters/pipeline.ts +0 -170
- package/src/flag-push.test.ts +0 -112
- package/src/flag-push.ts +0 -198
- package/src/flag-queue.test.ts +0 -197
- package/src/flag-queue.ts +0 -509
- package/src/folder-operations.test.ts +0 -273
- package/src/folder-operations.ts +0 -217
- package/src/folder-placement.ts +0 -56
- package/src/forwarded-message.test.ts +0 -122
- package/src/heuristics/authenticationResults.test.ts +0 -189
- package/src/heuristics/authenticationResults.ts +0 -212
- package/src/heuristics/classifyByHeaders.test.ts +0 -889
- package/src/heuristics/classifyByHeaders.ts +0 -467
- package/src/heuristics/classifyPlacement.test.ts +0 -366
- package/src/heuristics/classifyPlacement.ts +0 -211
- package/src/heuristics/classifyRealMail.test.ts +0 -242
- package/src/heuristics/machineSenders.test.ts +0 -101
- package/src/heuristics/senderMismatch.test.ts +0 -346
- package/src/heuristics/senderMismatch.ts +0 -259
- package/src/imapflow-connect-retry.test.ts +0 -97
- package/src/imapflow-connection.test.ts +0 -503
- package/src/imapflow-connection.ts +0 -1476
- package/src/index.ts +0 -397
- package/src/list-id-backfill.test.ts +0 -207
- package/src/list-id-backfill.ts +0 -274
- package/src/mailbox-cursor-rebuild.test.ts +0 -171
- package/src/mailbox-cursor-rebuild.ts +0 -146
- package/src/mailbox-cursor.test.ts +0 -141
- package/src/mailbox-delete-intent.test.ts +0 -119
- package/src/mailbox-management.test.ts +0 -243
- package/src/mailbox-management.ts +0 -838
- package/src/mailbox-presence.test.ts +0 -74
- package/src/mailbox-queue.ts +0 -397
- package/src/mailbox-rename-intent.test.ts +0 -220
- package/src/mailbox-rename-subtree.test.ts +0 -287
- package/src/mailbox-sync.test.ts +0 -286
- package/src/mailbox-sync.ts +0 -724
- package/src/message-move.test.ts +0 -726
- package/src/message-move.ts +0 -1518
- package/src/message-parser.ts +0 -26
- package/src/message-presence.test.ts +0 -50
- package/src/message-read.ts +0 -87
- package/src/message-save-retry.test.ts +0 -90
- package/src/message-sync-flags.test.ts +0 -167
- package/src/message-sync.test.ts +0 -762
- package/src/message-sync.ts +0 -2133
- package/src/mime-walker.test.ts +0 -311
- package/src/mime-walker.ts +0 -306
- package/src/organize-job.ts +0 -93
- package/src/outbox-attachment-content.test.ts +0 -153
- package/src/outbox-attachment-content.ts +0 -104
- package/src/outbox-attachment-filename.test.ts +0 -132
- package/src/outbox-attachment-filename.ts +0 -76
- package/src/outbox-attachment.test.ts +0 -626
- package/src/outbox-attachment.ts +0 -536
- package/src/outbox-failed-recovery.test.ts +0 -299
- package/src/outbox-queue.test.ts +0 -315
- package/src/outbox-queue.ts +0 -525
- package/src/ownership.ts +0 -140
- package/src/placement-move-terminal.ts +0 -145
- package/src/placement-move.ts +0 -363
- package/src/placement-settled.test.ts +0 -147
- package/src/placement.test.ts +0 -404
- package/src/quarantine.test.ts +0 -133
- package/src/quarantine.ts +0 -229
- package/src/refusal.ts +0 -29
- package/src/snippet.test.ts +0 -213
- package/src/snippet.ts +0 -152
- package/src/spam-report.test.ts +0 -329
- package/src/spam-report.ts +0 -357
- package/src/sync-warning.test.ts +0 -213
- package/src/sync-warning.ts +0 -56
- package/src/sync-watermarks.test.ts +0 -409
- package/src/sync-watermarks.ts +0 -319
- package/src/system-flag-wire-format.test.ts +0 -77
- package/src/test-helpers/fake-imap.ts +0 -690
- package/src/test-helpers/folder-roles.ts +0 -66
- package/src/test-helpers/mime-tree-generator.ts +0 -461
- package/src/test-helpers/test-queue.ts +0 -56
- package/src/test-helpers/test-store.ts +0 -299
- package/src/text/normalizer.test.ts +0 -223
- package/src/text/normalizer.ts +0 -140
- package/src/thread-message-rows.ts +0 -77
- package/src/thread-root.test.ts +0 -29
- package/src/thread-root.ts +0 -51
- package/src/types/mailparser-augment.d.ts +0 -23
- package/src/types/natural-porter-stemmer.d.ts +0 -50
- package/src/types/stopword.d.ts +0 -69
- package/src/types.ts +0 -371
- package/tsconfig.json +0 -8
package/src/placement.test.ts
DELETED
|
@@ -1,404 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { afterEach, beforeEach, describe, it } from "node:test";
|
|
3
|
-
import type {
|
|
4
|
-
AccountItem,
|
|
5
|
-
CreateMessageInput,
|
|
6
|
-
MailboxItem,
|
|
7
|
-
MessageItem,
|
|
8
|
-
} from "@remit/data-ports";
|
|
9
|
-
import { MessagePlacementUnsettledError } from "@remit/data-ports/errors";
|
|
10
|
-
import { deriveAddressId } from "@remit/data-ports/id";
|
|
11
|
-
import { MessageMoveService } from "./message-move.js";
|
|
12
|
-
import { PlacementMoveService } from "./placement-move.js";
|
|
13
|
-
import { resolveExhaustedPlacementMoveFailure } from "./placement-move-terminal.js";
|
|
14
|
-
import { eml, FakeImapServer } from "./test-helpers/fake-imap.js";
|
|
15
|
-
import {
|
|
16
|
-
arriveAt,
|
|
17
|
-
beforeNext,
|
|
18
|
-
captureQueue,
|
|
19
|
-
openStore,
|
|
20
|
-
type QueueCapture,
|
|
21
|
-
type QueuedEvent,
|
|
22
|
-
type Store,
|
|
23
|
-
seedAccount,
|
|
24
|
-
seedMailbox,
|
|
25
|
-
seedMessage,
|
|
26
|
-
silentLog,
|
|
27
|
-
} from "./test-helpers/test-store.js";
|
|
28
|
-
|
|
29
|
-
let store: Store;
|
|
30
|
-
let capture: QueueCapture;
|
|
31
|
-
let queue: QueuedEvent[];
|
|
32
|
-
let imap: FakeImapServer;
|
|
33
|
-
let account: AccountItem;
|
|
34
|
-
let inbox: MailboxItem;
|
|
35
|
-
let archive: MailboxItem;
|
|
36
|
-
let junk: MailboxItem;
|
|
37
|
-
let trash: MailboxItem;
|
|
38
|
-
|
|
39
|
-
beforeEach(async () => {
|
|
40
|
-
capture = captureQueue();
|
|
41
|
-
queue = capture.sent;
|
|
42
|
-
store = await openStore();
|
|
43
|
-
imap = new FakeImapServer();
|
|
44
|
-
account = await seedAccount(store);
|
|
45
|
-
inbox = await seedMailbox(store, account, "INBOX");
|
|
46
|
-
archive = await seedMailbox(store, account, "Archive");
|
|
47
|
-
junk = await seedMailbox(store, account, "Junk", { specialUse: "Junk" });
|
|
48
|
-
trash = await seedMailbox(store, account, "Trash", { specialUse: "Trash" });
|
|
49
|
-
for (const mailbox of await store.mailbox.listAllByAccount(
|
|
50
|
-
account.accountId,
|
|
51
|
-
)) {
|
|
52
|
-
imap.addFolder(mailbox.fullPath);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
afterEach(async () => {
|
|
57
|
-
capture.restore();
|
|
58
|
-
await store.close();
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
const filing = () =>
|
|
62
|
-
new PlacementMoveService({
|
|
63
|
-
messageService: store.message,
|
|
64
|
-
threadMessageService: store.threadMessage,
|
|
65
|
-
markerService: store.placementMove,
|
|
66
|
-
addressService: store.address,
|
|
67
|
-
mailboxSpecialUseService: store.mailboxSpecialUse,
|
|
68
|
-
mailboxService: store.mailbox,
|
|
69
|
-
sqsQueueUrl: "https://sqs.test/message-mgmt",
|
|
70
|
-
moveSettleTimeoutMs: 200,
|
|
71
|
-
moveSettlePollMs: 10,
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
const userMoves = () =>
|
|
75
|
-
new MessageMoveService({
|
|
76
|
-
messageService: store.message,
|
|
77
|
-
mailboxService: store.mailbox,
|
|
78
|
-
mailboxSpecialUseService: store.mailboxSpecialUse,
|
|
79
|
-
threadMessageService: store.threadMessage,
|
|
80
|
-
addressService: store.address,
|
|
81
|
-
sqsQueueUrl: "http://localhost:9324/000000000000/remit-messages.fifo",
|
|
82
|
-
moveSettleTimeoutMs: 200,
|
|
83
|
-
moveSettlePollMs: 10,
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
const rowIn = async (
|
|
87
|
-
mailbox: MailboxItem,
|
|
88
|
-
uid: number,
|
|
89
|
-
message: Partial<CreateMessageInput> = {},
|
|
90
|
-
) =>
|
|
91
|
-
(await seedMessage(store, account, mailbox, uid, { message })).message
|
|
92
|
-
.messageId;
|
|
93
|
-
|
|
94
|
-
const row = (messageId: string) => store.message.get(messageId);
|
|
95
|
-
|
|
96
|
-
const listing = async (messageId: string) =>
|
|
97
|
-
(
|
|
98
|
-
await store.threadMessage.findAllByMessageId(
|
|
99
|
-
account.accountConfigId,
|
|
100
|
-
messageId,
|
|
101
|
-
)
|
|
102
|
-
)[0];
|
|
103
|
-
|
|
104
|
-
const file = (messageId: string, destination: MailboxItem) =>
|
|
105
|
-
filing().moveMessage(
|
|
106
|
-
account.accountConfigId,
|
|
107
|
-
messageId,
|
|
108
|
-
destination.mailboxId,
|
|
109
|
-
account.accountId,
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
const confirmMove = async (messageId: string, uid: number) => {
|
|
113
|
-
const marker = await store.placementMove.find(messageId);
|
|
114
|
-
await store.message.updateUid(
|
|
115
|
-
messageId,
|
|
116
|
-
uid,
|
|
117
|
-
marker?.destinationMailboxId ?? "",
|
|
118
|
-
);
|
|
119
|
-
await store.placementMove.delete(messageId);
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const settleElsewhere = (messageId: string) => () =>
|
|
123
|
-
store.message.updateUid(messageId, 907, archive.mailboxId);
|
|
124
|
-
|
|
125
|
-
describe("a classification filing", () => {
|
|
126
|
-
it("moves the row and its listing locally, leaves a queued marker and enqueues the push", async () => {
|
|
127
|
-
const messageId = await rowIn(inbox, 42);
|
|
128
|
-
|
|
129
|
-
await file(messageId, junk);
|
|
130
|
-
|
|
131
|
-
const moved = await row(messageId);
|
|
132
|
-
assert.equal(moved.mailboxId, junk.mailboxId);
|
|
133
|
-
assert.equal(moved.status, "moving");
|
|
134
|
-
assert.equal(moved.originalUid, 42);
|
|
135
|
-
assert.equal((await listing(messageId)).mailboxId, junk.mailboxId);
|
|
136
|
-
assert.equal((await store.placementMove.find(messageId))?.state, "queued");
|
|
137
|
-
assert.deepEqual(
|
|
138
|
-
queue.map((event) => event.body.type),
|
|
139
|
-
["PLACEMENT_MOVE_PUSH"],
|
|
140
|
-
);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it("withholds the sender of a message it files into Junk", async () => {
|
|
144
|
-
const messageId = await arriveAt(
|
|
145
|
-
store,
|
|
146
|
-
imap,
|
|
147
|
-
account,
|
|
148
|
-
inbox,
|
|
149
|
-
eml({ From: "Spam <spam@example.com>" }),
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
await file(messageId, junk);
|
|
153
|
-
|
|
154
|
-
const sender = await store.address.getAddress(
|
|
155
|
-
account.accountConfigId,
|
|
156
|
-
deriveAddressId(account.accountConfigId, "spam@example.com"),
|
|
157
|
-
);
|
|
158
|
-
assert.equal(sender.flags.junkOnly?.value, true);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it("does nothing for a message already in the destination", async () => {
|
|
162
|
-
const messageId = await rowIn(junk, 42);
|
|
163
|
-
|
|
164
|
-
await file(messageId, junk);
|
|
165
|
-
|
|
166
|
-
assert.equal(await store.placementMove.find(messageId), null);
|
|
167
|
-
assert.equal(queue.length, 0);
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it("binds a second filing to the confirmed row once the first move settles", async () => {
|
|
171
|
-
const messageId = await rowIn(inbox, 42);
|
|
172
|
-
await file(messageId, archive);
|
|
173
|
-
|
|
174
|
-
setTimeout(() => void confirmMove(messageId, 907), 30);
|
|
175
|
-
await file(messageId, junk);
|
|
176
|
-
|
|
177
|
-
const marker = await store.placementMove.find(messageId);
|
|
178
|
-
assert.equal(marker?.sourceMailboxId, archive.mailboxId);
|
|
179
|
-
assert.equal((await row(messageId)).originalUid, 907);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it("leaves the first move standing when it never settles", async () => {
|
|
183
|
-
const messageId = await rowIn(inbox, 42);
|
|
184
|
-
await file(messageId, archive);
|
|
185
|
-
|
|
186
|
-
await assert.rejects(file(messageId, junk), /has not settled/);
|
|
187
|
-
|
|
188
|
-
const marker = await store.placementMove.find(messageId);
|
|
189
|
-
assert.equal(marker?.sourceMailboxId, inbox.mailboxId);
|
|
190
|
-
assert.equal(marker?.destinationMailboxId, archive.mailboxId);
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it("drives a marker whose push never went out forward without moving again", async () => {
|
|
194
|
-
const messageId = await rowIn(inbox, 42);
|
|
195
|
-
await file(messageId, archive);
|
|
196
|
-
await store.placementMove.updateState(messageId, "pending");
|
|
197
|
-
|
|
198
|
-
await file(messageId, archive);
|
|
199
|
-
|
|
200
|
-
assert.equal((await store.placementMove.find(messageId))?.state, "queued");
|
|
201
|
-
assert.equal((await row(messageId)).originalUid, 42);
|
|
202
|
-
assert.equal(queue.length, 2);
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it("skips a message a delete has claimed without waiting", async () => {
|
|
206
|
-
const messageId = await rowIn(inbox, 42);
|
|
207
|
-
await userMoves().deleteMessages(
|
|
208
|
-
account.accountConfigId,
|
|
209
|
-
[messageId],
|
|
210
|
-
account.accountId,
|
|
211
|
-
{ permanent: true },
|
|
212
|
-
);
|
|
213
|
-
assert.equal((await row(messageId)).status, "deleting");
|
|
214
|
-
queue.length = 0;
|
|
215
|
-
|
|
216
|
-
const startedAt = Date.now();
|
|
217
|
-
await file(messageId, junk);
|
|
218
|
-
|
|
219
|
-
assert.ok(Date.now() - startedAt < 100);
|
|
220
|
-
assert.equal(await store.placementMove.find(messageId), null);
|
|
221
|
-
assert.equal(queue.length, 0);
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it("writes nothing, listing included, when the row settles elsewhere mid-decision", async () => {
|
|
225
|
-
const messageId = await rowIn(inbox, 42);
|
|
226
|
-
beforeNext(store.placementMove, "put", settleElsewhere(messageId));
|
|
227
|
-
|
|
228
|
-
await file(messageId, junk);
|
|
229
|
-
|
|
230
|
-
const after = await row(messageId);
|
|
231
|
-
assert.equal(after.mailboxId, archive.mailboxId);
|
|
232
|
-
assert.equal(after.uid, 907);
|
|
233
|
-
assert.equal((await listing(messageId)).mailboxId, inbox.mailboxId);
|
|
234
|
-
assert.equal(await store.placementMove.find(messageId), null);
|
|
235
|
-
assert.equal(queue.length, 0);
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
describe("a user mutation writes only against the placement it read", () => {
|
|
240
|
-
it("refuses a move when the row settles elsewhere mid-decision", async () => {
|
|
241
|
-
const messageId = await rowIn(inbox, 42);
|
|
242
|
-
beforeNext(store.mailbox, "get", settleElsewhere(messageId));
|
|
243
|
-
|
|
244
|
-
await assert.rejects(
|
|
245
|
-
userMoves().moveMessage(
|
|
246
|
-
account.accountConfigId,
|
|
247
|
-
messageId,
|
|
248
|
-
junk.mailboxId,
|
|
249
|
-
account.accountId,
|
|
250
|
-
),
|
|
251
|
-
MessagePlacementUnsettledError,
|
|
252
|
-
);
|
|
253
|
-
|
|
254
|
-
const after = await row(messageId);
|
|
255
|
-
assert.equal(after.mailboxId, archive.mailboxId);
|
|
256
|
-
assert.equal(after.status, "active");
|
|
257
|
-
assert.equal(queue.length, 0);
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
for (const source of ["INBOX", "Trash"] as const) {
|
|
261
|
-
it(`reports a delete out of ${source} it could not claim`, async () => {
|
|
262
|
-
const messageId = await rowIn(source === "Trash" ? trash : inbox, 42);
|
|
263
|
-
beforeNext(
|
|
264
|
-
store.mailboxSpecialUse,
|
|
265
|
-
"resolveTrashRole",
|
|
266
|
-
settleElsewhere(messageId),
|
|
267
|
-
);
|
|
268
|
-
|
|
269
|
-
const { refusedMessageIds } = await userMoves().deleteMessages(
|
|
270
|
-
account.accountConfigId,
|
|
271
|
-
[messageId],
|
|
272
|
-
account.accountId,
|
|
273
|
-
);
|
|
274
|
-
|
|
275
|
-
assert.deepEqual(refusedMessageIds, [messageId]);
|
|
276
|
-
assert.equal((await row(messageId)).mailboxId, archive.mailboxId);
|
|
277
|
-
assert.equal(queue.length, 0);
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
it("reports a row whose folder belongs to another account", async () => {
|
|
282
|
-
const other = await seedAccount(store);
|
|
283
|
-
const foreign = await seedMailbox(store, other, "INBOX");
|
|
284
|
-
const messageId = await rowIn(foreign, 42);
|
|
285
|
-
|
|
286
|
-
const { refusedMessageIds } = await userMoves().deleteMessages(
|
|
287
|
-
account.accountConfigId,
|
|
288
|
-
[messageId],
|
|
289
|
-
account.accountId,
|
|
290
|
-
);
|
|
291
|
-
|
|
292
|
-
assert.deepEqual(refusedMessageIds, [messageId]);
|
|
293
|
-
assert.equal(queue.length, 0);
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
describe("a filing that exhausted its retries", () => {
|
|
298
|
-
const resolve = (
|
|
299
|
-
messageId: string,
|
|
300
|
-
uid: number,
|
|
301
|
-
source: MailboxItem,
|
|
302
|
-
placement: Pick<MessageItem, "status" | "mailboxId" | "uid">,
|
|
303
|
-
) =>
|
|
304
|
-
resolveExhaustedPlacementMoveFailure(
|
|
305
|
-
{
|
|
306
|
-
messageService: store.message,
|
|
307
|
-
threadMessageService: store.threadMessage,
|
|
308
|
-
markerService: store.placementMove,
|
|
309
|
-
log: silentLog,
|
|
310
|
-
},
|
|
311
|
-
{
|
|
312
|
-
placement,
|
|
313
|
-
accountId: account.accountId,
|
|
314
|
-
accountConfigId: account.accountConfigId,
|
|
315
|
-
messageId,
|
|
316
|
-
uid,
|
|
317
|
-
sourceMailboxId: source.mailboxId,
|
|
318
|
-
sourceMailboxPath: source.fullPath,
|
|
319
|
-
getConnection: async () => imap.connection(),
|
|
320
|
-
},
|
|
321
|
-
);
|
|
322
|
-
|
|
323
|
-
const filedFromInbox = async () => {
|
|
324
|
-
const uid = imap.deliver("INBOX", eml({}));
|
|
325
|
-
const messageId = await rowIn(inbox, uid);
|
|
326
|
-
await file(messageId, junk);
|
|
327
|
-
const read = await row(messageId);
|
|
328
|
-
return {
|
|
329
|
-
messageId,
|
|
330
|
-
uid,
|
|
331
|
-
placement: {
|
|
332
|
-
status: read.status,
|
|
333
|
-
mailboxId: read.mailboxId,
|
|
334
|
-
uid: read.uid,
|
|
335
|
-
},
|
|
336
|
-
};
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
it("removes the row of a message gone from the folder it left", async () => {
|
|
340
|
-
const { messageId, uid, placement } = await filedFromInbox();
|
|
341
|
-
imap.expunge("INBOX", uid);
|
|
342
|
-
|
|
343
|
-
const { outcome } = await resolve(messageId, uid, inbox, placement);
|
|
344
|
-
|
|
345
|
-
assert.equal(outcome, "reconciled");
|
|
346
|
-
await assert.rejects(row(messageId));
|
|
347
|
-
assert.equal(await store.placementMove.find(messageId), null);
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
it("puts a message still in its source back there instead of leaving it moving", async () => {
|
|
351
|
-
const { messageId, uid, placement } = await filedFromInbox();
|
|
352
|
-
|
|
353
|
-
const { outcome } = await resolve(messageId, uid, inbox, placement);
|
|
354
|
-
|
|
355
|
-
assert.equal(outcome, "broken");
|
|
356
|
-
const restored = await row(messageId);
|
|
357
|
-
assert.equal(restored.mailboxId, inbox.mailboxId);
|
|
358
|
-
assert.equal(restored.uid, uid);
|
|
359
|
-
assert.equal(restored.status, "active");
|
|
360
|
-
assert.equal(restored.abandonedMutation, "none");
|
|
361
|
-
assert.equal((await listing(messageId)).mailboxId, inbox.mailboxId);
|
|
362
|
-
assert.equal(await store.placementMove.find(messageId), null);
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
it("does not read a dropped FETCH row as the message being gone", async () => {
|
|
366
|
-
const { messageId, uid, placement } = await filedFromInbox();
|
|
367
|
-
const connection = imap.connection();
|
|
368
|
-
connection.fetchMessages = async () => [];
|
|
369
|
-
|
|
370
|
-
const { outcome } = await resolveExhaustedPlacementMoveFailure(
|
|
371
|
-
{
|
|
372
|
-
messageService: store.message,
|
|
373
|
-
threadMessageService: store.threadMessage,
|
|
374
|
-
markerService: store.placementMove,
|
|
375
|
-
log: silentLog,
|
|
376
|
-
},
|
|
377
|
-
{
|
|
378
|
-
placement,
|
|
379
|
-
accountId: account.accountId,
|
|
380
|
-
accountConfigId: account.accountConfigId,
|
|
381
|
-
messageId,
|
|
382
|
-
uid,
|
|
383
|
-
sourceMailboxId: inbox.mailboxId,
|
|
384
|
-
sourceMailboxPath: "INBOX",
|
|
385
|
-
getConnection: async () => connection,
|
|
386
|
-
},
|
|
387
|
-
);
|
|
388
|
-
|
|
389
|
-
assert.equal(outcome, "broken");
|
|
390
|
-
assert.ok(await row(messageId));
|
|
391
|
-
});
|
|
392
|
-
|
|
393
|
-
it("leaves a row another lane already settled to that lane", async () => {
|
|
394
|
-
const { messageId, uid, placement } = await filedFromInbox();
|
|
395
|
-
await confirmMove(messageId, 5);
|
|
396
|
-
|
|
397
|
-
const { outcome } = await resolve(messageId, uid, inbox, placement);
|
|
398
|
-
|
|
399
|
-
assert.equal(outcome, "broken");
|
|
400
|
-
const after = await row(messageId);
|
|
401
|
-
assert.equal(after.mailboxId, junk.mailboxId);
|
|
402
|
-
assert.equal((await listing(messageId)).mailboxId, junk.mailboxId);
|
|
403
|
-
});
|
|
404
|
-
});
|
package/src/quarantine.test.ts
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { afterEach, beforeEach, describe, it } from "node:test";
|
|
3
|
-
import type { AccountItem, MailboxItem } from "@remit/data-ports";
|
|
4
|
-
import {
|
|
5
|
-
QuarantineService,
|
|
6
|
-
resolveMailboxRole,
|
|
7
|
-
shapeFromMessageData,
|
|
8
|
-
} from "./quarantine.js";
|
|
9
|
-
import { eml, FakeImapServer } from "./test-helpers/fake-imap.js";
|
|
10
|
-
import {
|
|
11
|
-
arriveAt,
|
|
12
|
-
openStore,
|
|
13
|
-
type Store,
|
|
14
|
-
seedAccount,
|
|
15
|
-
seedMailbox,
|
|
16
|
-
silentLog,
|
|
17
|
-
} from "./test-helpers/test-store.js";
|
|
18
|
-
|
|
19
|
-
let store: Store;
|
|
20
|
-
let account: AccountItem;
|
|
21
|
-
let spam: MailboxItem;
|
|
22
|
-
let service: QuarantineService;
|
|
23
|
-
|
|
24
|
-
beforeEach(async () => {
|
|
25
|
-
store = await openStore();
|
|
26
|
-
account = await seedAccount(store);
|
|
27
|
-
spam = await seedMailbox(store, account, "Spam", { specialUse: "Junk" });
|
|
28
|
-
service = new QuarantineService(
|
|
29
|
-
store.quarantine,
|
|
30
|
-
store.mailboxSpecialUse,
|
|
31
|
-
"sha-abc",
|
|
32
|
-
silentLog,
|
|
33
|
-
);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
afterEach(() => store.close());
|
|
37
|
-
|
|
38
|
-
const failure = {
|
|
39
|
-
stage: "BodyParse" as const,
|
|
40
|
-
code: "UnreadableBody" as const,
|
|
41
|
-
message: "the parser said no",
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const record = (uid: number, mailboxPath = "Spam") =>
|
|
45
|
-
service.record(
|
|
46
|
-
{
|
|
47
|
-
accountId: account.accountId,
|
|
48
|
-
accountConfigId: account.accountConfigId,
|
|
49
|
-
mailboxId: spam.mailboxId,
|
|
50
|
-
mailboxPath,
|
|
51
|
-
uidValidity: 1_712_000_000,
|
|
52
|
-
attempts: 2,
|
|
53
|
-
},
|
|
54
|
-
uid,
|
|
55
|
-
failure,
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
const rows = () =>
|
|
59
|
-
store.quarantine.listByAccountConfigId(account.accountConfigId);
|
|
60
|
-
|
|
61
|
-
describe("QuarantineService.record", () => {
|
|
62
|
-
it("keeps one record per uid however often the message is set aside", async () => {
|
|
63
|
-
await record(40217);
|
|
64
|
-
await record(40217);
|
|
65
|
-
|
|
66
|
-
const recorded = (await rows()).filter((row) => row.uid === 40217);
|
|
67
|
-
assert.equal(recorded.length, 1);
|
|
68
|
-
assert.equal(recorded[0].uidValidity, 1_712_000_000);
|
|
69
|
-
assert.equal(recorded[0].workerVersion, "sha-abc");
|
|
70
|
-
assert.equal(recorded[0].failurePartPath, undefined);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("reads the folder's role off the server's SPECIAL-USE", async () => {
|
|
74
|
-
await record(7);
|
|
75
|
-
|
|
76
|
-
const [row] = (await rows()).filter((entry) => entry.uid === 7);
|
|
77
|
-
assert.equal(row.mailboxRole, "Junk");
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("loads what it recorded as the set a sync round skips", async () => {
|
|
81
|
-
await record(8);
|
|
82
|
-
|
|
83
|
-
const loaded = await service.load(account.accountConfigId);
|
|
84
|
-
assert.ok(loaded.has(spam.mailboxId, 1_712_000_000, 8));
|
|
85
|
-
assert.ok(!loaded.has(spam.mailboxId, 1_712_000_001, 8));
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe("resolveMailboxRole", () => {
|
|
90
|
-
it("gives INBOX its role without a SPECIAL-USE flag, which it never has", () => {
|
|
91
|
-
assert.equal(resolveMailboxRole("INBOX", []), "Inbox");
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("leaves a plain folder roleless instead of inventing one", () => {
|
|
95
|
-
assert.equal(resolveMailboxRole("Clients/Acme", []), undefined);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it("drops a SPECIAL-USE that is not a canonical role", () => {
|
|
99
|
-
assert.equal(resolveMailboxRole("Priority", ["Important"]), undefined);
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
describe("shapeFromMessageData", () => {
|
|
104
|
-
it("describes the message from the rows metadata sync wrote", async () => {
|
|
105
|
-
const imap = new FakeImapServer();
|
|
106
|
-
imap.addFolder("Spam");
|
|
107
|
-
const raw = eml({
|
|
108
|
-
"Message-ID": "<xyz@example.com>",
|
|
109
|
-
"Content-Type": "text/plain; charset=iso-8859-1",
|
|
110
|
-
"Content-Transfer-Encoding": "quoted-printable",
|
|
111
|
-
});
|
|
112
|
-
const messageId = await arriveAt(store, imap, account, spam, raw);
|
|
113
|
-
|
|
114
|
-
const shape = shapeFromMessageData(
|
|
115
|
-
await store.message.get(messageId),
|
|
116
|
-
await store.envelope.getMessageData(messageId),
|
|
117
|
-
(
|
|
118
|
-
await store.threadMessage.findByMessageId(
|
|
119
|
-
account.accountConfigId,
|
|
120
|
-
messageId,
|
|
121
|
-
)
|
|
122
|
-
)?.messageIdHeader,
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
assert.equal(shape.structure.length, 1);
|
|
126
|
-
assert.equal(shape.structure[0].depth, 0);
|
|
127
|
-
assert.match(shape.structure[0].contentType, /^text\/plain$/i);
|
|
128
|
-
assert.equal(shape.charset, "iso-8859-1");
|
|
129
|
-
assert.equal(shape.transferEncoding?.toLowerCase(), "quoted-printable");
|
|
130
|
-
assert.equal(shape.sizeBytes, raw.length);
|
|
131
|
-
assert.ok(shape.messageIdHash);
|
|
132
|
-
});
|
|
133
|
-
});
|