@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.
Files changed (123) hide show
  1. package/package.json +21 -6
  2. package/src/body-part-mapper.ts +51 -1
  3. package/src/body-sync-queue.test.ts +39 -99
  4. package/src/body-sync-terminal.test.ts +115 -277
  5. package/src/body-sync-terminal.ts +10 -12
  6. package/src/body-sync.test.ts +925 -0
  7. package/src/body-sync.ts +226 -200
  8. package/src/classification-backfill.test.ts +197 -527
  9. package/src/classify-message.test.ts +11 -74
  10. package/src/external-move.test.ts +102 -209
  11. package/src/external-move.ts +13 -0
  12. package/src/filter-operations.test.ts +319 -0
  13. package/src/filter-operations.ts +377 -0
  14. package/src/filter-update.test.ts +313 -0
  15. package/src/filters/filter-config.test.ts +55 -197
  16. package/src/filters/filter-config.ts +4 -39
  17. package/src/filters/match.test.ts +1 -38
  18. package/src/filters/match.ts +3 -52
  19. package/src/filters/pipeline.test.ts +158 -289
  20. package/src/filters/pipeline.ts +56 -170
  21. package/src/flag-push-terminal.ts +9 -11
  22. package/src/flag-push.test.ts +76 -372
  23. package/src/flag-queue.test.ts +197 -0
  24. package/src/folder-operations.test.ts +273 -0
  25. package/src/folder-operations.ts +217 -0
  26. package/src/forwarded-message.test.ts +122 -0
  27. package/src/imapflow-connect-retry.test.ts +76 -113
  28. package/src/imapflow-connection.test.ts +34 -0
  29. package/src/imapflow-connection.ts +19 -15
  30. package/src/index.ts +59 -12
  31. package/src/list-id-backfill.test.ts +133 -499
  32. package/src/mailbox-cursor.test.ts +81 -189
  33. package/src/mailbox-delete-intent.test.ts +78 -205
  34. package/src/mailbox-intent.ts +5 -3
  35. package/src/mailbox-management.test.ts +107 -220
  36. package/src/mailbox-management.ts +1 -2
  37. package/src/mailbox-presence.test.ts +36 -34
  38. package/src/mailbox-queue.ts +2 -20
  39. package/src/mailbox-rename-intent.test.ts +156 -325
  40. package/src/mailbox-rename-subtree.test.ts +205 -582
  41. package/src/mailbox-sync.test.ts +182 -744
  42. package/src/message-move.test.ts +726 -0
  43. package/src/message-move.ts +227 -57
  44. package/src/message-read.ts +87 -0
  45. package/src/message-save-retry.test.ts +90 -0
  46. package/src/message-sync-flags.test.ts +10 -1
  47. package/src/message-sync.test.ts +762 -0
  48. package/src/message-sync.ts +409 -239
  49. package/src/mime-walker.ts +16 -15
  50. package/src/organize-job.ts +93 -0
  51. package/src/outbox-attachment.test.ts +97 -209
  52. package/src/outbox-failed-recovery.test.ts +198 -269
  53. package/src/outbox-queue.test.ts +24 -0
  54. package/src/outbox-queue.ts +25 -8
  55. package/src/ownership.ts +140 -0
  56. package/src/placement-move-terminal.ts +9 -12
  57. package/src/placement-move.ts +33 -6
  58. package/src/placement-settled.ts +28 -4
  59. package/src/placement.test.ts +404 -0
  60. package/src/quarantine.test.ts +90 -148
  61. package/src/quarantine.ts +3 -2
  62. package/src/refusal.ts +29 -0
  63. package/src/restore-source-placement.ts +0 -4
  64. package/src/spam-report.test.ts +238 -710
  65. package/src/sync-warning.test.ts +213 -0
  66. package/src/sync-warning.ts +56 -0
  67. package/src/test-helpers/fake-imap.ts +690 -0
  68. package/src/test-helpers/test-queue.ts +56 -0
  69. package/src/test-helpers/test-store.ts +299 -0
  70. package/src/thread-root.test.ts +29 -0
  71. package/src/thread-root.ts +51 -0
  72. package/src/types/mailparser-augment.d.ts +8 -0
  73. package/src/types.ts +1 -1
  74. package/src/adversarial-mime.e2e.test.ts +0 -307
  75. package/src/body-sync-auto-read-writeonce.test.ts +0 -219
  76. package/src/body-sync-calendar-suggestion.test.ts +0 -433
  77. package/src/body-sync-category-denormalize.test.ts +0 -352
  78. package/src/body-sync-category-override.test.ts +0 -501
  79. package/src/body-sync-category-writeonce.test.ts +0 -234
  80. package/src/body-sync-filter.test.ts +0 -237
  81. package/src/body-sync-placement-flags.test.ts +0 -347
  82. package/src/body-sync-placement-writeonce.test.ts +0 -337
  83. package/src/body-sync-quarantine.test.ts +0 -276
  84. package/src/body-sync-resync.test.ts +0 -605
  85. package/src/body-sync-unclassifiable-once.test.ts +0 -260
  86. package/src/body-sync-unsubscribed-auto-read.test.ts +0 -176
  87. package/src/filters/anchor-drift.ts +0 -55
  88. package/src/filters/message-embedder.test.ts +0 -39
  89. package/src/filters/message-embedder.ts +0 -33
  90. package/src/flag-push-terminal.test.ts +0 -209
  91. package/src/flag-queue-stars.test.ts +0 -171
  92. package/src/imapflow-connection.e2e.test.ts +0 -335
  93. package/src/imapflow-connection.integ.test.ts +0 -316
  94. package/src/message-delete-junk-reconcile.test.ts +0 -117
  95. package/src/message-delete-no-trash.test.ts +0 -245
  96. package/src/message-delete-unsettled-placement.test.ts +0 -396
  97. package/src/message-move-copy.test.ts +0 -562
  98. package/src/message-move-empty-trash.test.ts +0 -326
  99. package/src/message-move-same-mailbox.test.ts +0 -139
  100. package/src/message-move-unsettled-placement.test.ts +0 -378
  101. package/src/message-sync-address-spoof.test.ts +0 -293
  102. package/src/message-sync-category.test.ts +0 -142
  103. package/src/message-sync-changedsince.test.ts +0 -840
  104. package/src/message-sync-junk-harvest.test.ts +0 -244
  105. package/src/message-sync-quarantine.test.ts +0 -416
  106. package/src/message-sync-repoint.test.ts +0 -419
  107. package/src/outbox-queue-settled-row.test.ts +0 -140
  108. package/src/pass-through-unit-of-work.ts +0 -17
  109. package/src/placement-move-terminal.test.ts +0 -300
  110. package/src/placement-move-unsettled.test.ts +0 -275
  111. package/src/placement-transition-race.test.ts +0 -482
  112. package/src/stale-message-reconcile.test.ts +0 -82
  113. package/src/stale-message-reconcile.ts +0 -55
  114. package/src/test-helpers/isolated-mailbox.ts +0 -44
  115. package/src/test-helpers/mailfuzz-connection.ts +0 -27
  116. package/test/fixtures/mime-adversarial-e2e/01-octet-stream-pdf.eml +0 -21
  117. package/test/fixtures/mime-adversarial-e2e/02-nested-related-cid-image.eml +0 -31
  118. package/test/fixtures/mime-adversarial-e2e/03-calendar-invite.eml +0 -33
  119. package/test/fixtures/mime-adversarial-e2e/04-forwarded-rfc822-with-attachments.eml +0 -42
  120. package/test/fixtures/mime-adversarial-e2e/05-tnef-winmail.eml +0 -25
  121. package/test/fixtures/mime-adversarial-e2e/06-8bit-non-ascii.eml +0 -15
  122. package/test/fixtures/mime-adversarial-e2e/07-quoted-printable-soft-breaks.eml +0 -17
  123. package/test/fixtures/mime-adversarial-e2e/08-alternative-empty-text.eml +0 -18
@@ -1,326 +0,0 @@
1
- /**
2
- * Empty Trash is an EXPUNGE with no undo, so it demands confirmed evidence:
3
- * what the user appointed, or what the server flagged `\Trash`. The name
4
- * proposal that serves every other lookup is a guess, and a wrong guess here
5
- * destroys mail (#837, audit #841). Each way that evidence can be missing
6
- * refuses under its own reason, so the surface can name the repair (#887).
7
- */
8
- import assert from "node:assert/strict";
9
- import { describe, it } from "node:test";
10
- import type {
11
- IAddressRepository,
12
- IMailboxRepository,
13
- IMailboxSpecialUseRepository,
14
- IMessageRepository,
15
- IThreadMessageRepository,
16
- } from "@remit/data-ports";
17
- import type { RoleResolution } from "@remit/data-ports/folder-role";
18
- import {
19
- type MessageMoveConfig,
20
- MessageMoveService,
21
- NoTrashMailboxError,
22
- StaleTrashAppointmentError,
23
- UnconfirmedTrashMailboxError,
24
- } from "./message-move.js";
25
- import { NO_JUNK_ROLES } from "./test-helpers/folder-roles.js";
26
-
27
- const ACCOUNT = "acc-1";
28
- const ACCOUNT_CONFIG = "cfg-1";
29
- const DELETED_FOLDER = "mbx-deleted";
30
- const REAL_TRASH = "mbx-trash";
31
-
32
- type TrashMailbox = { mailboxId: string; fullPath: string };
33
-
34
- const appointedTrash: RoleResolution<TrashMailbox> = {
35
- kind: "appointed",
36
- mailbox: { mailboxId: REAL_TRASH, fullPath: "[Gmail]/Trash" },
37
- };
38
-
39
- // A folder merely named `Deleted` is what the name proposal returns, and the
40
- // confirmed gate is what this path asks for.
41
- const proposedDeletedFolder: RoleResolution<TrashMailbox> = {
42
- kind: "proposed",
43
- mailbox: { mailboxId: DELETED_FOLDER, fullPath: "Deleted" },
44
- };
45
-
46
- interface TrashMessage {
47
- messageId: string;
48
- syncStatus: string;
49
- status?: string;
50
- mailboxId?: string;
51
- uid?: number;
52
- originalMailboxId?: string;
53
- originalUid?: number;
54
- }
55
-
56
- /**
57
- * A row mid-move into Trash: the folder is already written, the uid is still
58
- * the inbox's, and only `status: moving` says so.
59
- */
60
- const movingIntoTrash = (messageId: string, uid: number): TrashMessage => ({
61
- messageId,
62
- syncStatus: "pending",
63
- status: "moving",
64
- mailboxId: REAL_TRASH,
65
- uid,
66
- originalMailboxId: "mbx-inbox",
67
- originalUid: uid,
68
- });
69
-
70
- interface EnqueuedEvent {
71
- type: string;
72
- schemaVersion?: number;
73
- trashMailboxId?: string;
74
- trashUidValidity?: number;
75
- }
76
-
77
- const buildWorld = (
78
- trashResolution: RoleResolution<TrashMailbox>,
79
- trashContents: TrashMessage[] = [
80
- { messageId: "junk-1", syncStatus: "synced" },
81
- ],
82
- /** Message ids whose placement another lane changed after the read. */
83
- transitionsLost: string[] = [],
84
- ) => {
85
- const emptied: string[] = [];
86
- const markedDeleting: string[] = [];
87
- const markPredicates = new Map<string, unknown>();
88
- const events: EnqueuedEvent[] = [];
89
- const messagesByMailbox = new Map<string, TrashMessage[]>([
90
- [DELETED_FOLDER, [{ messageId: "keepsake-1", syncStatus: "synced" }]],
91
- [REAL_TRASH, trashContents],
92
- ]);
93
-
94
- const messageService = {
95
- listAllByMailbox: async (mailboxId: string) => {
96
- emptied.push(mailboxId);
97
- return messagesByMailbox.get(mailboxId) ?? [];
98
- },
99
- update: async (messageId: string) => {
100
- markedDeleting.push(messageId);
101
- },
102
- transitionPlacement: async (messageId: string, expected: unknown) => {
103
- markPredicates.set(messageId, expected);
104
- if (transitionsLost.includes(messageId)) return undefined;
105
- markedDeleting.push(messageId);
106
- return { messageId };
107
- },
108
- } as unknown as IMessageRepository;
109
-
110
- const threadMessageService = {
111
- getByMessageId: async () => ({
112
- accountConfigId: ACCOUNT_CONFIG,
113
- threadMessageId: "tm-1",
114
- sentDate: 1_700_000_000_000,
115
- }),
116
- update: async () => {},
117
- } as unknown as IThreadMessageRepository;
118
-
119
- const config: MessageMoveConfig = {
120
- messageService,
121
- mailboxService: {
122
- get: async (_accountId: string, mailboxId: string) => ({
123
- mailboxId,
124
- uidValidity: 42,
125
- }),
126
- } as unknown as IMailboxRepository,
127
- addressService: {
128
- reconcileJunkOnlyForMessage: async () => {},
129
- } as unknown as IAddressRepository,
130
- mailboxSpecialUseService: {
131
- resolveTrashRole: async () => trashResolution,
132
- resolveJunkRolesForConfig: async () => NO_JUNK_ROLES,
133
- } as unknown as IMailboxSpecialUseRepository,
134
- threadMessageService,
135
- sqsQueueUrl: "http://localhost:9324/000000000000/remit-messages.fifo",
136
- };
137
-
138
- const service = new MessageMoveService(config);
139
- (
140
- service as unknown as {
141
- enqueueEvent: (event: EnqueuedEvent) => Promise<void>;
142
- }
143
- ).enqueueEvent = async (event) => {
144
- events.push(event);
145
- };
146
-
147
- return { service, emptied, markedDeleting, markPredicates, events };
148
- };
149
-
150
- describe("MessageMoveService.emptyTrash", () => {
151
- it("empties the appointed Trash, never the user folder called Deleted", async () => {
152
- const { service, emptied } = buildWorld(appointedTrash);
153
-
154
- await service.emptyTrash(ACCOUNT_CONFIG, ACCOUNT);
155
-
156
- assert.deepEqual(emptied, [REAL_TRASH]);
157
- });
158
-
159
- it("refuses and names the remedy when no folder is appointed or flagged", async () => {
160
- const { service, emptied } = buildWorld({ kind: "none" });
161
-
162
- await assert.rejects(
163
- service.emptyTrash(ACCOUNT_CONFIG, ACCOUNT),
164
- (error: unknown) =>
165
- error instanceof NoTrashMailboxError &&
166
- error.publicApiError?.details?.reason === "none",
167
- );
168
-
169
- // Nothing was read, so nothing was marked for deletion and no expunge
170
- // was enqueued: an unresolved Trash stops the operation dead.
171
- assert.deepEqual(emptied, []);
172
- });
173
-
174
- it("refuses a Trash that only resolves by name, under its own reason", async () => {
175
- // D18: a plausible folder nobody confirmed is a third answer, distinct
176
- // from having none. The refusal is what mints the appointment.
177
- const { service, emptied, markedDeleting } = buildWorld(
178
- proposedDeletedFolder,
179
- );
180
-
181
- await assert.rejects(
182
- service.emptyTrash(ACCOUNT_CONFIG, ACCOUNT),
183
- (error: unknown) =>
184
- error instanceof UnconfirmedTrashMailboxError &&
185
- error.statusCode === 409 &&
186
- error.publicApiError?.details?.reason === "unconfirmed" &&
187
- error.publicApiError?.details?.accountId === ACCOUNT,
188
- );
189
-
190
- assert.deepEqual(emptied, []);
191
- assert.deepEqual(markedDeleting, []);
192
- });
193
-
194
- it("refuses a stale appointment rather than emptying its fallback", async () => {
195
- const { service, emptied, markedDeleting } = buildWorld({
196
- kind: "appointment_stale",
197
- appointedMailboxId: "mbx-appointed-and-gone",
198
- fallback: { kind: "flagged", mailbox: appointedTrash.mailbox },
199
- });
200
-
201
- await assert.rejects(
202
- service.emptyTrash(ACCOUNT_CONFIG, ACCOUNT),
203
- (error: unknown) =>
204
- error instanceof StaleTrashAppointmentError &&
205
- error.publicApiError?.details?.reason === "stale",
206
- );
207
-
208
- assert.deepEqual(emptied, []);
209
- assert.deepEqual(markedDeleting, []);
210
- });
211
-
212
- it("reports what it marked, from the one read that decided it", async () => {
213
- const { service, markedDeleting } = buildWorld(appointedTrash, [
214
- { messageId: "junk-1", syncStatus: "synced" },
215
- { messageId: "junk-2", syncStatus: "synced" },
216
- { messageId: "junk-3", syncStatus: "synced" },
217
- ]);
218
-
219
- const { deletedCount } = await service.emptyTrash(ACCOUNT_CONFIG, ACCOUNT);
220
-
221
- assert.equal(deletedCount, markedDeleting.length);
222
- assert.equal(deletedCount, 3);
223
- });
224
-
225
- it("marks and counts a message whose sync is merely pending", async () => {
226
- // `syncStatus: pending` is where every freshly synced inbound row sits
227
- // forever; it says nothing about where the message is. The user saw it in
228
- // Trash and asked for the folder to be emptied, and skipping it would
229
- // report a number the folder contradicts.
230
- const { service, markedDeleting } = buildWorld(appointedTrash, [
231
- { messageId: "settled-1", syncStatus: "synced" },
232
- { messageId: "pending-1", syncStatus: "pending" },
233
- ]);
234
-
235
- const { deletedCount } = await service.emptyTrash(ACCOUNT_CONFIG, ACCOUNT);
236
-
237
- assert.deepEqual(markedDeleting, ["settled-1", "pending-1"]);
238
- assert.equal(deletedCount, 2);
239
- });
240
-
241
- it("leaves a row whose move into Trash has not settled unmarked and uncounted", async () => {
242
- // Issue #1217. Marking it `deleting` overwrites the `moving` its own
243
- // MESSAGE_MOVE reads to decide there is still work to do, so that move
244
- // returns without touching IMAP and the worker's expunge then binds the
245
- // inbox's uid against whatever Trash really holds at it.
246
- const { service, markedDeleting } = buildWorld(appointedTrash, [
247
- { messageId: "settled-1", syncStatus: "synced" },
248
- movingIntoTrash("moving-1", 10),
249
- ]);
250
-
251
- const { deletedCount } = await service.emptyTrash(ACCOUNT_CONFIG, ACCOUNT);
252
-
253
- assert.deepEqual(markedDeleting, ["settled-1"]);
254
- assert.equal(deletedCount, 1);
255
- });
256
-
257
- it("predicates each mark on the row it just read, and drops the ones it loses", async () => {
258
- // The rows are held by nothing between the listing and the mark, and
259
- // PLACEMENT_MOVE_PUSH rides a standard queue this account's FIFO group
260
- // does not order (imap-mutations R3). A row that moved under the sweep
261
- // must not be marked `deleting` for an expunge that would bind a uid it
262
- // no longer has.
263
- const { service, markedDeleting, markPredicates } = buildWorld(
264
- appointedTrash,
265
- [
266
- {
267
- messageId: "settled-1",
268
- syncStatus: "synced",
269
- status: "active",
270
- mailboxId: REAL_TRASH,
271
- uid: 10,
272
- },
273
- {
274
- messageId: "raced-1",
275
- syncStatus: "synced",
276
- status: "active",
277
- mailboxId: REAL_TRASH,
278
- uid: 11,
279
- },
280
- ],
281
- ["raced-1"],
282
- );
283
-
284
- const { deletedCount } = await service.emptyTrash(ACCOUNT_CONFIG, ACCOUNT);
285
-
286
- assert.deepEqual(markedDeleting, ["settled-1"]);
287
- assert.equal(deletedCount, 1, "a row that lost is not counted either");
288
- assert.deepEqual(markPredicates.get("settled-1"), {
289
- status: "active",
290
- mailboxId: REAL_TRASH,
291
- uid: 10,
292
- });
293
- });
294
-
295
- it("reports the same count when pressed twice before the worker runs", async () => {
296
- // The rows it marked are still in that folder, so N stays true and the
297
- // re-mark is idempotent. Reporting 0 the second time while still
298
- // enqueuing an expunge would read as success over an untouched Trash.
299
- const { service, events } = buildWorld(appointedTrash, [
300
- { messageId: "junk-1", syncStatus: "synced" },
301
- { messageId: "junk-2", syncStatus: "synced" },
302
- ]);
303
-
304
- const first = await service.emptyTrash(ACCOUNT_CONFIG, ACCOUNT);
305
- const second = await service.emptyTrash(ACCOUNT_CONFIG, ACCOUNT);
306
-
307
- assert.equal(first.deletedCount, 2);
308
- assert.equal(second.deletedCount, 2);
309
- assert.deepEqual(
310
- events.map((event) => event.type),
311
- ["EMPTY_TRASH", "EMPTY_TRASH"],
312
- );
313
- });
314
-
315
- it("carries the folder's identity as it stood at consent time", async () => {
316
- // The worker compares this against what its own SELECT serves. Without
317
- // it the expunge would be authorised by a path, and a path is reusable.
318
- const { service, events } = buildWorld(appointedTrash);
319
-
320
- await service.emptyTrash(ACCOUNT_CONFIG, ACCOUNT);
321
-
322
- assert.equal(events[0]?.schemaVersion, 2);
323
- assert.equal(events[0]?.trashMailboxId, REAL_TRASH);
324
- assert.equal(events[0]?.trashUidValidity, 42);
325
- });
326
- });
@@ -1,139 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { describe, it } from "node:test";
3
- import type {
4
- IAddressRepository,
5
- IMailboxRepository,
6
- IMailboxSpecialUseRepository,
7
- IMessageRepository,
8
- IThreadMessageRepository,
9
- } from "@remit/data-ports";
10
- import { type MessageMoveConfig, MessageMoveService } from "./message-move.js";
11
- import { NO_JUNK_ROLES, trashRole } from "./test-helpers/folder-roles.js";
12
-
13
- const stubAddressService = (): IAddressRepository =>
14
- ({
15
- reconcileJunkOnlyForMessage: async () => {},
16
- }) as unknown as IAddressRepository;
17
-
18
- const ACCOUNT = "acc-1";
19
- const ACCOUNT_CONFIG = "cfg-1";
20
- const INBOX = "mbx-inbox";
21
- const ARCHIVE = "mbx-archive";
22
- const MESSAGE_ID = "msg-1";
23
-
24
- const buildWorld = () => {
25
- const message = {
26
- messageId: MESSAGE_ID,
27
- mailboxId: INBOX,
28
- uid: 337,
29
- status: "active",
30
- syncStatus: "synced",
31
- };
32
-
33
- const threadRow = {
34
- accountConfigId: ACCOUNT_CONFIG,
35
- threadMessageId: "tm-1",
36
- messageId: MESSAGE_ID,
37
- mailboxId: INBOX,
38
- sentDate: 1_700_000_000_000,
39
- isRead: false,
40
- isDeleted: false,
41
- hasStars: false,
42
- hasAttachment: false,
43
- };
44
-
45
- const mailboxes = new Map<string, Record<string, unknown>>([
46
- [INBOX, { mailboxId: INBOX, fullPath: "INBOX", accountId: ACCOUNT }],
47
- [ARCHIVE, { mailboxId: ARCHIVE, fullPath: "Archive", accountId: ACCOUNT }],
48
- ]);
49
-
50
- const messageService = {
51
- get: async (ids: string | string[]) =>
52
- Array.isArray(ids) ? [message] : message,
53
- update: async (_id: string, patch: Record<string, unknown>) =>
54
- Object.assign(message, patch),
55
- transitionPlacement: async (
56
- _id: string,
57
- _expected: Record<string, unknown>,
58
- patch: Record<string, unknown>,
59
- ) => Object.assign(message, patch),
60
- } as unknown as IMessageRepository;
61
-
62
- const threadMessageService = {
63
- getByMessageId: async () => threadRow,
64
- update: async (_cfg: string, _id: string, patch: Record<string, unknown>) =>
65
- Object.assign(threadRow, patch),
66
- } as unknown as IThreadMessageRepository;
67
-
68
- const mailboxService = {
69
- get: async (_acc: string, id: string) => mailboxes.get(id),
70
- } as unknown as IMailboxRepository;
71
-
72
- const mailboxSpecialUseService = {
73
- findTrashMailbox: async () => null,
74
- resolveTrashRole: async () => trashRole(null),
75
- resolveJunkRolesForConfig: async () => NO_JUNK_ROLES,
76
- } as unknown as IMailboxSpecialUseRepository;
77
-
78
- const config: MessageMoveConfig = {
79
- messageService,
80
- mailboxService,
81
- mailboxSpecialUseService,
82
- threadMessageService,
83
- addressService: stubAddressService(),
84
- sqsQueueUrl: "http://localhost:9324/000000000000/remit-messages.fifo",
85
- };
86
-
87
- const service = new MessageMoveService(config);
88
- const sent: unknown[] = [];
89
- (
90
- service as unknown as { sqs: { send: (c: unknown) => Promise<unknown> } }
91
- ).sqs = {
92
- send: async (command: unknown) => {
93
- sent.push(command);
94
- return {};
95
- },
96
- };
97
-
98
- return { service, message, threadRow, sent };
99
- };
100
-
101
- // IMAP has no in-place MOVE: a same-mailbox move expunges the message and
102
- // re-appends it under a new UID, so a request naming the folder the message is
103
- // already in destroys its identity for nothing. It reached the mail server
104
- // because the client can fire the same move twice — the second one after the
105
- // first has already landed.
106
- describe("MessageMoveService.moveMessage — same-mailbox move (#594)", () => {
107
- it("enqueues nothing when the destination is the mailbox the message is in", async () => {
108
- const { service, sent } = buildWorld();
109
-
110
- await service.moveMessages(ACCOUNT_CONFIG, [MESSAGE_ID], INBOX, ACCOUNT);
111
-
112
- assert.equal(sent.length, 0, "no IMAP move event was enqueued");
113
- });
114
-
115
- it("leaves the message row exactly as it was", async () => {
116
- const { service, message, threadRow } = buildWorld();
117
-
118
- await service.moveMessages(ACCOUNT_CONFIG, [MESSAGE_ID], INBOX, ACCOUNT);
119
-
120
- assert.deepEqual(message, {
121
- messageId: MESSAGE_ID,
122
- mailboxId: INBOX,
123
- uid: 337,
124
- status: "active",
125
- syncStatus: "synced",
126
- });
127
- assert.equal(threadRow.mailboxId, INBOX);
128
- });
129
-
130
- it("still moves a message whose destination is a different mailbox", async () => {
131
- const { service, message, sent } = buildWorld();
132
-
133
- await service.moveMessages(ACCOUNT_CONFIG, [MESSAGE_ID], ARCHIVE, ACCOUNT);
134
-
135
- assert.equal(sent.length, 1, "the real move is enqueued");
136
- assert.equal(message.mailboxId, ARCHIVE);
137
- assert.equal(message.syncStatus, "pending");
138
- });
139
- });