@remit/mailbox-service 0.0.111 → 0.0.113

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 (298) hide show
  1. package/dist/account-credentials.d.ts +83 -0
  2. package/dist/account-credentials.js +104 -0
  3. package/dist/attribute-mapper.d.ts +36 -0
  4. package/dist/attribute-mapper.js +119 -0
  5. package/dist/body-parse.d.ts +28 -0
  6. package/{src/body-parse.ts → dist/body-parse.js} +18 -26
  7. package/dist/body-part-mapper.d.ts +92 -0
  8. package/dist/body-part-mapper.js +301 -0
  9. package/dist/body-sync-queue.d.ts +59 -0
  10. package/dist/body-sync-queue.js +56 -0
  11. package/dist/body-sync-terminal.d.ts +58 -0
  12. package/dist/body-sync-terminal.js +95 -0
  13. package/dist/body-sync.d.ts +351 -0
  14. package/dist/body-sync.js +1204 -0
  15. package/dist/calendar-parts.d.ts +23 -0
  16. package/dist/calendar-parts.js +18 -0
  17. package/dist/classification-backfill.d.ts +91 -0
  18. package/dist/classification-backfill.js +180 -0
  19. package/dist/classify-message.d.ts +31 -0
  20. package/dist/classify-message.js +89 -0
  21. package/dist/connection-factory.d.ts +54 -0
  22. package/dist/connection-factory.js +54 -0
  23. package/dist/connection-test.d.ts +41 -0
  24. package/dist/connection-test.js +152 -0
  25. package/dist/external-move.d.ts +94 -0
  26. package/dist/external-move.js +173 -0
  27. package/dist/filter-operations.d.ts +42 -0
  28. package/dist/filter-operations.js +211 -0
  29. package/dist/filters/filter-config.d.ts +14 -0
  30. package/dist/filters/filter-config.js +10 -0
  31. package/{src/filters/list-id.ts → dist/filters/list-id.d.ts} +2 -16
  32. package/dist/filters/list-id.js +26 -0
  33. package/dist/filters/match.d.ts +69 -0
  34. package/dist/filters/match.js +165 -0
  35. package/dist/filters/pipeline.d.ts +64 -0
  36. package/dist/filters/pipeline.js +100 -0
  37. package/{src/flag-push-terminal.ts → dist/flag-push-terminal.d.ts} +19 -77
  38. package/dist/flag-push-terminal.js +63 -0
  39. package/dist/flag-push.d.ts +69 -0
  40. package/dist/flag-push.js +111 -0
  41. package/dist/flag-queue.d.ts +175 -0
  42. package/dist/flag-queue.js +291 -0
  43. package/dist/folder-operations.d.ts +39 -0
  44. package/dist/folder-operations.js +112 -0
  45. package/dist/folder-placement.d.ts +13 -0
  46. package/dist/folder-placement.js +23 -0
  47. package/dist/heuristics/authenticationResults.d.ts +10 -0
  48. package/dist/heuristics/authenticationResults.js +187 -0
  49. package/dist/heuristics/classifyByHeaders.d.ts +82 -0
  50. package/dist/heuristics/classifyByHeaders.js +365 -0
  51. package/dist/heuristics/classifyPlacement.d.ts +67 -0
  52. package/dist/heuristics/classifyPlacement.js +153 -0
  53. package/dist/heuristics/machineSenders.d.ts +21 -0
  54. package/{src/heuristics/machineSenders.ts → dist/heuristics/machineSenders.js} +34 -40
  55. package/dist/heuristics/senderMismatch.d.ts +81 -0
  56. package/dist/heuristics/senderMismatch.js +192 -0
  57. package/dist/heuristics/socialDomains.d.ts +14 -0
  58. package/{src/heuristics/socialDomains.ts → dist/heuristics/socialDomains.js} +9 -9
  59. package/dist/heuristics/transactionalDomains.d.ts +18 -0
  60. package/{src/heuristics/transactionalDomains.ts → dist/heuristics/transactionalDomains.js} +8 -8
  61. package/dist/imapflow-connection.d.ts +377 -0
  62. package/dist/imapflow-connection.js +1147 -0
  63. package/dist/index.d.ts +63 -0
  64. package/dist/index.js +65 -0
  65. package/dist/list-id-backfill.d.ts +83 -0
  66. package/dist/list-id-backfill.js +132 -0
  67. package/dist/mailbox-cursor-rebuild.d.ts +74 -0
  68. package/dist/mailbox-cursor-rebuild.js +71 -0
  69. package/{src/mailbox-cursor.ts → dist/mailbox-cursor.d.ts} +20 -98
  70. package/dist/mailbox-cursor.js +102 -0
  71. package/dist/mailbox-intent.d.ts +41 -0
  72. package/{src/mailbox-intent.ts → dist/mailbox-intent.js} +39 -63
  73. package/dist/mailbox-management.d.ts +240 -0
  74. package/dist/mailbox-management.js +576 -0
  75. package/dist/mailbox-presence.d.ts +52 -0
  76. package/{src/mailbox-presence.ts → dist/mailbox-presence.js} +19 -30
  77. package/dist/mailbox-queue.d.ts +126 -0
  78. package/dist/mailbox-queue.js +214 -0
  79. package/dist/mailbox-sync.d.ts +93 -0
  80. package/dist/mailbox-sync.js +490 -0
  81. package/dist/mailbox-upstream.d.ts +38 -0
  82. package/{src/mailbox-upstream.ts → dist/mailbox-upstream.js} +37 -47
  83. package/dist/message-category.d.ts +51 -0
  84. package/{src/message-category.ts → dist/message-category.js} +28 -71
  85. package/dist/message-move.d.ts +285 -0
  86. package/dist/message-move.js +858 -0
  87. package/dist/message-parser.d.ts +14 -0
  88. package/dist/message-parser.js +17 -0
  89. package/{src/message-presence.ts → dist/message-presence.d.ts} +1 -13
  90. package/dist/message-presence.js +29 -0
  91. package/dist/message-read.d.ts +51 -0
  92. package/dist/message-read.js +31 -0
  93. package/dist/message-sync.d.ts +345 -0
  94. package/dist/message-sync.js +1358 -0
  95. package/dist/mime-walker.d.ts +102 -0
  96. package/dist/mime-walker.js +198 -0
  97. package/dist/organize-job.d.ts +20 -0
  98. package/dist/organize-job.js +37 -0
  99. package/dist/outbox-attachment-content.d.ts +37 -0
  100. package/dist/outbox-attachment-content.js +50 -0
  101. package/dist/outbox-attachment-filename.d.ts +19 -0
  102. package/dist/outbox-attachment-filename.js +64 -0
  103. package/dist/outbox-attachment.d.ts +148 -0
  104. package/dist/outbox-attachment.js +273 -0
  105. package/dist/outbox-queue.d.ts +73 -0
  106. package/dist/outbox-queue.js +284 -0
  107. package/{src/outbox-status.ts → dist/outbox-status.d.ts} +1 -6
  108. package/dist/outbox-status.js +18 -0
  109. package/dist/ownership.d.ts +24 -0
  110. package/dist/ownership.js +83 -0
  111. package/dist/placement-move-terminal.d.ts +67 -0
  112. package/dist/placement-move-terminal.js +88 -0
  113. package/dist/placement-move.d.ts +83 -0
  114. package/dist/placement-move.js +216 -0
  115. package/{src/placement-settled.ts → dist/placement-settled.d.ts} +19 -50
  116. package/dist/placement-settled.js +75 -0
  117. package/dist/quarantine.d.ts +95 -0
  118. package/dist/quarantine.js +131 -0
  119. package/dist/refusal.d.ts +31 -0
  120. package/dist/refusal.js +3 -0
  121. package/{src/restore-source-placement.ts → dist/restore-source-placement.d.ts} +29 -101
  122. package/dist/restore-source-placement.js +79 -0
  123. package/dist/search-text-backfill.d.ts +15 -0
  124. package/dist/search-text-backfill.js +33 -0
  125. package/dist/snippet.d.ts +61 -0
  126. package/dist/snippet.js +129 -0
  127. package/dist/spam-report.d.ts +86 -0
  128. package/dist/spam-report.js +241 -0
  129. package/dist/sync-warning.d.ts +21 -0
  130. package/dist/sync-warning.js +26 -0
  131. package/dist/sync-watermarks.d.ts +138 -0
  132. package/dist/sync-watermarks.js +205 -0
  133. package/dist/test-helpers/fake-imap.d.ts +151 -0
  134. package/dist/test-helpers/fake-imap.js +508 -0
  135. package/dist/test-helpers/folder-roles.d.ts +34 -0
  136. package/dist/test-helpers/folder-roles.js +47 -0
  137. package/dist/test-helpers/mime-tree-generator.d.ts +82 -0
  138. package/dist/test-helpers/mime-tree-generator.js +329 -0
  139. package/dist/test-helpers/test-store.d.ts +69 -0
  140. package/dist/test-helpers/test-store.js +193 -0
  141. package/dist/text/normalizer.d.ts +20 -0
  142. package/dist/text/normalizer.js +102 -0
  143. package/dist/thread-message-rows.d.ts +69 -0
  144. package/dist/thread-message-rows.js +40 -0
  145. package/dist/thread-root.d.ts +7 -0
  146. package/dist/thread-root.js +25 -0
  147. package/dist/types.d.ts +343 -0
  148. package/dist/types.js +19 -0
  149. package/package.json +86 -73
  150. package/src/account-credentials.ts +0 -210
  151. package/src/adversarial-mime.e2e.test.ts +0 -307
  152. package/src/attribute-mapper.test.ts +0 -104
  153. package/src/attribute-mapper.ts +0 -148
  154. package/src/body-parse.test.ts +0 -55
  155. package/src/body-part-mapper.property.test.ts +0 -354
  156. package/src/body-part-mapper.ts +0 -360
  157. package/src/body-sync-auto-read-writeonce.test.ts +0 -219
  158. package/src/body-sync-calendar-suggestion.test.ts +0 -433
  159. package/src/body-sync-category-denormalize.test.ts +0 -352
  160. package/src/body-sync-category-override.test.ts +0 -501
  161. package/src/body-sync-category-writeonce.test.ts +0 -234
  162. package/src/body-sync-filter.test.ts +0 -237
  163. package/src/body-sync-message-gone.test.ts +0 -139
  164. package/src/body-sync-placement-flags.test.ts +0 -347
  165. package/src/body-sync-placement-writeonce.test.ts +0 -337
  166. package/src/body-sync-quarantine.test.ts +0 -276
  167. package/src/body-sync-queue.test.ts +0 -124
  168. package/src/body-sync-queue.ts +0 -131
  169. package/src/body-sync-resync.test.ts +0 -605
  170. package/src/body-sync-terminal.test.ts +0 -310
  171. package/src/body-sync-terminal.ts +0 -176
  172. package/src/body-sync-unclassifiable-once.test.ts +0 -260
  173. package/src/body-sync-unsubscribed-auto-read.test.ts +0 -176
  174. package/src/body-sync.ts +0 -1970
  175. package/src/calendar-parts.ts +0 -41
  176. package/src/classification-backfill.test.ts +0 -615
  177. package/src/classification-backfill.ts +0 -363
  178. package/src/classify-message.test.ts +0 -205
  179. package/src/classify-message.ts +0 -116
  180. package/src/connection-factory.ts +0 -102
  181. package/src/connection-test.ts +0 -208
  182. package/src/credentials.test.ts +0 -181
  183. package/src/external-move.test.ts +0 -369
  184. package/src/external-move.ts +0 -272
  185. package/src/filters/anchor-drift.ts +0 -55
  186. package/src/filters/filter-config.test.ts +0 -229
  187. package/src/filters/filter-config.ts +0 -69
  188. package/src/filters/list-id.test.ts +0 -50
  189. package/src/filters/match.test.ts +0 -429
  190. package/src/filters/match.ts +0 -274
  191. package/src/filters/message-embedder.test.ts +0 -39
  192. package/src/filters/message-embedder.ts +0 -33
  193. package/src/filters/pipeline.test.ts +0 -330
  194. package/src/filters/pipeline.ts +0 -284
  195. package/src/flag-push-terminal.test.ts +0 -209
  196. package/src/flag-push.test.ts +0 -408
  197. package/src/flag-push.ts +0 -198
  198. package/src/flag-queue-stars.test.ts +0 -171
  199. package/src/flag-queue.ts +0 -509
  200. package/src/folder-placement.ts +0 -56
  201. package/src/heuristics/authenticationResults.test.ts +0 -189
  202. package/src/heuristics/authenticationResults.ts +0 -212
  203. package/src/heuristics/classifyByHeaders.test.ts +0 -889
  204. package/src/heuristics/classifyByHeaders.ts +0 -467
  205. package/src/heuristics/classifyPlacement.test.ts +0 -366
  206. package/src/heuristics/classifyPlacement.ts +0 -211
  207. package/src/heuristics/classifyRealMail.test.ts +0 -242
  208. package/src/heuristics/machineSenders.test.ts +0 -101
  209. package/src/heuristics/senderMismatch.test.ts +0 -346
  210. package/src/heuristics/senderMismatch.ts +0 -259
  211. package/src/imapflow-connect-retry.test.ts +0 -134
  212. package/src/imapflow-connection.e2e.test.ts +0 -335
  213. package/src/imapflow-connection.integ.test.ts +0 -316
  214. package/src/imapflow-connection.test.ts +0 -469
  215. package/src/imapflow-connection.ts +0 -1475
  216. package/src/index.ts +0 -350
  217. package/src/list-id-backfill.test.ts +0 -573
  218. package/src/list-id-backfill.ts +0 -274
  219. package/src/mailbox-cursor-rebuild.test.ts +0 -171
  220. package/src/mailbox-cursor-rebuild.ts +0 -146
  221. package/src/mailbox-cursor.test.ts +0 -249
  222. package/src/mailbox-delete-intent.test.ts +0 -246
  223. package/src/mailbox-management.test.ts +0 -356
  224. package/src/mailbox-management.ts +0 -839
  225. package/src/mailbox-presence.test.ts +0 -72
  226. package/src/mailbox-queue.ts +0 -415
  227. package/src/mailbox-rename-intent.test.ts +0 -389
  228. package/src/mailbox-rename-subtree.test.ts +0 -664
  229. package/src/mailbox-sync.test.ts +0 -848
  230. package/src/mailbox-sync.ts +0 -724
  231. package/src/message-delete-junk-reconcile.test.ts +0 -117
  232. package/src/message-delete-no-trash.test.ts +0 -245
  233. package/src/message-delete-unsettled-placement.test.ts +0 -396
  234. package/src/message-move-copy.test.ts +0 -562
  235. package/src/message-move-empty-trash.test.ts +0 -326
  236. package/src/message-move-same-mailbox.test.ts +0 -139
  237. package/src/message-move-unsettled-placement.test.ts +0 -378
  238. package/src/message-move.ts +0 -1348
  239. package/src/message-parser.ts +0 -26
  240. package/src/message-presence.test.ts +0 -50
  241. package/src/message-sync-address-spoof.test.ts +0 -293
  242. package/src/message-sync-category.test.ts +0 -142
  243. package/src/message-sync-changedsince.test.ts +0 -840
  244. package/src/message-sync-flags.test.ts +0 -158
  245. package/src/message-sync-junk-harvest.test.ts +0 -244
  246. package/src/message-sync-quarantine.test.ts +0 -416
  247. package/src/message-sync-repoint.test.ts +0 -419
  248. package/src/message-sync.ts +0 -1963
  249. package/src/mime-walker.test.ts +0 -311
  250. package/src/mime-walker.ts +0 -305
  251. package/src/outbox-attachment-content.test.ts +0 -153
  252. package/src/outbox-attachment-content.ts +0 -104
  253. package/src/outbox-attachment-filename.test.ts +0 -132
  254. package/src/outbox-attachment-filename.ts +0 -76
  255. package/src/outbox-attachment.test.ts +0 -738
  256. package/src/outbox-attachment.ts +0 -536
  257. package/src/outbox-failed-recovery.test.ts +0 -370
  258. package/src/outbox-queue-settled-row.test.ts +0 -140
  259. package/src/outbox-queue.test.ts +0 -291
  260. package/src/outbox-queue.ts +0 -508
  261. package/src/pass-through-unit-of-work.ts +0 -17
  262. package/src/placement-move-terminal.test.ts +0 -300
  263. package/src/placement-move-terminal.ts +0 -148
  264. package/src/placement-move-unsettled.test.ts +0 -275
  265. package/src/placement-move.ts +0 -336
  266. package/src/placement-settled.test.ts +0 -147
  267. package/src/placement-transition-race.test.ts +0 -482
  268. package/src/quarantine.test.ts +0 -191
  269. package/src/quarantine.ts +0 -228
  270. package/src/snippet.test.ts +0 -213
  271. package/src/snippet.ts +0 -152
  272. package/src/spam-report.test.ts +0 -801
  273. package/src/spam-report.ts +0 -357
  274. package/src/stale-message-reconcile.test.ts +0 -82
  275. package/src/stale-message-reconcile.ts +0 -55
  276. package/src/sync-watermarks.test.ts +0 -409
  277. package/src/sync-watermarks.ts +0 -319
  278. package/src/system-flag-wire-format.test.ts +0 -77
  279. package/src/test-helpers/folder-roles.ts +0 -66
  280. package/src/test-helpers/isolated-mailbox.ts +0 -44
  281. package/src/test-helpers/mailfuzz-connection.ts +0 -27
  282. package/src/test-helpers/mime-tree-generator.ts +0 -461
  283. package/src/text/normalizer.test.ts +0 -223
  284. package/src/text/normalizer.ts +0 -140
  285. package/src/thread-message-rows.ts +0 -77
  286. package/src/types/mailparser-augment.d.ts +0 -15
  287. package/src/types/natural-porter-stemmer.d.ts +0 -50
  288. package/src/types/stopword.d.ts +0 -69
  289. package/src/types.ts +0 -371
  290. package/test/fixtures/mime-adversarial-e2e/01-octet-stream-pdf.eml +0 -21
  291. package/test/fixtures/mime-adversarial-e2e/02-nested-related-cid-image.eml +0 -31
  292. package/test/fixtures/mime-adversarial-e2e/03-calendar-invite.eml +0 -33
  293. package/test/fixtures/mime-adversarial-e2e/04-forwarded-rfc822-with-attachments.eml +0 -42
  294. package/test/fixtures/mime-adversarial-e2e/05-tnef-winmail.eml +0 -25
  295. package/test/fixtures/mime-adversarial-e2e/06-8bit-non-ascii.eml +0 -15
  296. package/test/fixtures/mime-adversarial-e2e/07-quoted-printable-soft-breaks.eml +0 -17
  297. package/test/fixtures/mime-adversarial-e2e/08-alternative-empty-text.eml +0 -18
  298. package/tsconfig.json +0 -8
@@ -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
- });