@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,378 +0,0 @@
1
- /**
2
- * Issue #665. While a placement move is in flight the Message row names the
3
- * destination folder but still carries the SOURCE folder's uid, so a user move
4
- * that binds the pair as it stands sends the worker to `openBox(destination)`
5
- * and `moveMessages([uid])` — the destination folder's own message at that uid,
6
- * carried off to wherever the user pointed. The reachable press is Undo on the
7
- * auto-moved badge, inside the seconds before the placement push confirms.
8
- */
9
-
10
- import assert from "node:assert/strict";
11
- import { describe, it } from "node:test";
12
- import type {
13
- IAddressRepository,
14
- IMailboxRepository,
15
- IMailboxSpecialUseRepository,
16
- IMessageRepository,
17
- IThreadMessageRepository,
18
- } from "@remit/data-ports";
19
- import { MessagePlacementUnsettledError } from "@remit/data-ports/errors";
20
- import { MessageMoveService } from "./message-move.js";
21
- import { NO_JUNK_ROLES } from "./test-helpers/folder-roles.js";
22
-
23
- const ACCOUNT = "acc-1";
24
- const ACCOUNT_CONFIG = "cfg-1";
25
- const INBOX = "mbx-inbox";
26
- const ARCHIVE = "mbx-archive";
27
-
28
- const MOVING_ID = "msg-moving";
29
- const SETTLED_ID = "msg-settled";
30
- const STRANDED_ID = "msg-stranded";
31
- const DELETING_ID = "msg-deleting";
32
- const COPY_ID = "msg-copy";
33
-
34
- const INBOX_UID = 42;
35
- const ARCHIVE_UID = 907;
36
- const SETTLED_UID = 11;
37
-
38
- interface CapturedEvent {
39
- type: string;
40
- messageId?: string;
41
- uid?: number;
42
- sourceMailboxPath?: string;
43
- destinationMailboxPath?: string;
44
- }
45
-
46
- const mailboxes = [
47
- { mailboxId: INBOX, fullPath: "INBOX", accountId: ACCOUNT },
48
- { mailboxId: ARCHIVE, fullPath: "Archive", accountId: ACCOUNT },
49
- ];
50
-
51
- /** A row mid-move: Archive is already written, the uid is still INBOX's. */
52
- const movingRow = () => ({
53
- messageId: MOVING_ID,
54
- mailboxId: ARCHIVE,
55
- uid: INBOX_UID,
56
- status: "moving",
57
- syncStatus: "pending",
58
- originalMailboxId: INBOX,
59
- originalUid: INBOX_UID,
60
- });
61
-
62
- /**
63
- * A row a mutation gave up on. R3 defines the give-up as a hand-back: the row
64
- * goes back on the placement the mail server confirmed, and only then carries
65
- * `abandoned`. The pair is honest, so nothing downstream refuses it — the
66
- * failure is a statement the reading pane makes, never a gate.
67
- */
68
- const strandedRow = () => ({
69
- messageId: STRANDED_ID,
70
- mailboxId: INBOX,
71
- uid: INBOX_UID,
72
- status: "active",
73
- syncStatus: "abandoned",
74
- abandonedMutation: "move",
75
- originalMailboxId: INBOX,
76
- });
77
-
78
- /**
79
- * The same shape a delete leaves: Trash is already written, the uid is still
80
- * INBOX's, and `deleting` is what says so. R3 calls this in flight exactly as
81
- * `moving` is — reading only `moving` let a move enqueued behind a delete bind
82
- * this pair and be dropped when the delete settled.
83
- */
84
- const deletingRow = () => ({
85
- messageId: DELETING_ID,
86
- mailboxId: ARCHIVE,
87
- uid: INBOX_UID,
88
- status: "deleting",
89
- syncStatus: "pending",
90
- originalMailboxId: INBOX,
91
- originalUid: INBOX_UID,
92
- });
93
-
94
- /** An ordinary settled row. */
95
- const settledRow = () => ({
96
- messageId: SETTLED_ID,
97
- mailboxId: INBOX,
98
- uid: SETTLED_UID,
99
- status: "active",
100
- syncStatus: "synced",
101
- });
102
-
103
- /**
104
- * A freshly copied row: `moving` until COPYUID lands, with no server-side uid
105
- * at all and no move behind it. Its uid is not ready; it does not name anyone.
106
- */
107
- const freshCopyRow = () => ({
108
- messageId: COPY_ID,
109
- mailboxId: ARCHIVE,
110
- uid: 0,
111
- status: "moving",
112
- syncStatus: "pending",
113
- });
114
-
115
- const buildWorld = (seed: Array<Record<string, unknown>>) => {
116
- const patches: Array<{ messageId: string; patch: Record<string, unknown> }> =
117
- [];
118
- const events: CapturedEvent[] = [];
119
- const rows = new Map<string, Record<string, unknown>>(
120
- seed.map((row): [string, Record<string, unknown>] => [
121
- String(row.messageId),
122
- row,
123
- ]),
124
- );
125
-
126
- /** What `updateUid` writes when the placement move confirms. */
127
- const settle = (messageId: string) => {
128
- Object.assign(rows.get(messageId) ?? {}, {
129
- uid: ARCHIVE_UID,
130
- status: "active",
131
- syncStatus: "synced",
132
- });
133
- };
134
-
135
- const messageService = {
136
- get: async (ids: string | string[]) =>
137
- Array.isArray(ids)
138
- ? ids.flatMap((id) => {
139
- const row = rows.get(id);
140
- return row ? [row] : [];
141
- })
142
- : rows.get(ids),
143
- update: async (id: string, patch: Record<string, unknown>) => {
144
- patches.push({ messageId: id, patch });
145
- return Object.assign(rows.get(id) ?? {}, patch);
146
- },
147
- transitionPlacement: async (
148
- id: string,
149
- _expected: Record<string, unknown>,
150
- patch: Record<string, unknown>,
151
- ) => {
152
- patches.push({ messageId: id, patch });
153
- return Object.assign(rows.get(id) ?? {}, patch);
154
- },
155
- } as unknown as IMessageRepository;
156
-
157
- const threadMessageService = {
158
- getByMessageId: async (_cfg: string, messageId: string) => ({
159
- accountConfigId: ACCOUNT_CONFIG,
160
- threadMessageId: `tm-${messageId}`,
161
- messageId,
162
- threadId: "thr-1",
163
- mailboxId: rows.get(messageId)?.mailboxId,
164
- sentDate: 1,
165
- isRead: false,
166
- isDeleted: false,
167
- hasStars: false,
168
- hasAttachment: false,
169
- }),
170
- update: async () => {},
171
- } as unknown as IThreadMessageRepository;
172
-
173
- const mailboxService = {
174
- get: async (_accountId: string, ids: string | string[]) =>
175
- Array.isArray(ids)
176
- ? mailboxes.filter((mailbox) => ids.includes(mailbox.mailboxId))
177
- : mailboxes.find((mailbox) => mailbox.mailboxId === ids),
178
- } as unknown as IMailboxRepository;
179
-
180
- const mailboxSpecialUseService = {
181
- findTrashMailbox: async () => null,
182
- resolveJunkRolesForConfig: async () => NO_JUNK_ROLES,
183
- } as unknown as IMailboxSpecialUseRepository;
184
-
185
- const addressService = {
186
- reconcileJunkOnlyForMessage: async () => {},
187
- } as unknown as IAddressRepository;
188
-
189
- const service = new MessageMoveService({
190
- messageService,
191
- mailboxService,
192
- mailboxSpecialUseService,
193
- threadMessageService,
194
- addressService,
195
- sqsQueueUrl: "http://localhost:9324/000000000000/remit-messages.fifo",
196
- moveSettleTimeoutMs: 200,
197
- moveSettlePollMs: 10,
198
- });
199
-
200
- (
201
- service as unknown as { enqueueEvent: (e: CapturedEvent) => Promise<void> }
202
- ).enqueueEvent = async (event) => {
203
- events.push(event);
204
- };
205
-
206
- return { service, patches, events, rows, settle };
207
- };
208
-
209
- describe("a move never binds the folder/uid pair of an in-flight move (#665)", () => {
210
- it("binds the confirmed pair once the placement move settles", async () => {
211
- const { service, events, settle } = buildWorld([movingRow()]);
212
-
213
- setTimeout(() => settle(MOVING_ID), 30);
214
- await service.moveMessage(ACCOUNT_CONFIG, MOVING_ID, INBOX, ACCOUNT);
215
-
216
- assert.equal(events.length, 1);
217
- assert.equal(events[0].type, "MESSAGE_MOVE");
218
- assert.equal(
219
- events[0].sourceMailboxPath,
220
- "Archive",
221
- "the folder the confirmed move left the message in",
222
- );
223
- assert.equal(
224
- events[0].uid,
225
- ARCHIVE_UID,
226
- "and that folder's own uid, never the source folder's",
227
- );
228
- assert.equal(events[0].destinationMailboxPath, "INBOX");
229
- });
230
-
231
- it("refuses the move, and touches nothing, when the placement never settles", async () => {
232
- const { service, patches, events, rows } = buildWorld([movingRow()]);
233
-
234
- await assert.rejects(
235
- () => service.moveMessage(ACCOUNT_CONFIG, MOVING_ID, INBOX, ACCOUNT),
236
- (error: unknown) =>
237
- error instanceof MessagePlacementUnsettledError &&
238
- error.statusCode === 409 &&
239
- error.publicApiError?.code === "message_placement_unsettled" &&
240
- error.publicApiError?.details?.messageId === MOVING_ID &&
241
- error.publicApiError?.details?.accountId === ACCOUNT &&
242
- error.publicApiError?.details?.reason === "in_flight",
243
- );
244
-
245
- assert.deepEqual(events, [], "nothing was enqueued");
246
- assert.deepEqual(patches, [], "and no local write was made");
247
- assert.equal(rows.get(MOVING_ID)?.mailboxId, ARCHIVE);
248
- assert.equal(rows.get(MOVING_ID)?.uid, INBOX_UID);
249
- });
250
-
251
- it("never answers the same-mailbox skip from a folder the message has not reached", async () => {
252
- // The skip compares the row's `mailboxId` against the destination. An
253
- // in-flight move has already written that folder optimistically, so the
254
- // comparison would report the message home and return a silent success
255
- // for a move the server has not made.
256
- const { service, events } = buildWorld([movingRow()]);
257
-
258
- await assert.rejects(
259
- () => service.moveMessage(ACCOUNT_CONFIG, MOVING_ID, ARCHIVE, ACCOUNT),
260
- MessagePlacementUnsettledError,
261
- );
262
-
263
- assert.deepEqual(events, []);
264
- });
265
-
266
- it("moves no part of a batch when one row is in flight", async () => {
267
- // All-or-nothing: the settled row is movable on its own and a per-row
268
- // gate would have moved it before reaching the refusal.
269
- const { service, patches, events } = buildWorld([
270
- settledRow(),
271
- movingRow(),
272
- ]);
273
-
274
- await assert.rejects(
275
- () =>
276
- service.moveMessages(
277
- ACCOUNT_CONFIG,
278
- [SETTLED_ID, MOVING_ID],
279
- ARCHIVE,
280
- ACCOUNT,
281
- ),
282
- MessagePlacementUnsettledError,
283
- );
284
-
285
- assert.deepEqual(
286
- events,
287
- [],
288
- "the settled row was not moved alongside the refusal",
289
- );
290
- assert.deepEqual(patches, []);
291
- });
292
-
293
- it("moves the whole batch once the in-flight row settles", async () => {
294
- const { service, events, settle } = buildWorld([settledRow(), movingRow()]);
295
-
296
- setTimeout(() => settle(MOVING_ID), 30);
297
- await service.moveMessages(
298
- ACCOUNT_CONFIG,
299
- [SETTLED_ID, MOVING_ID],
300
- INBOX,
301
- ACCOUNT,
302
- );
303
-
304
- assert.deepEqual(
305
- events.map((event) => [event.messageId, event.uid]),
306
- [[MOVING_ID, ARCHIVE_UID]],
307
- "the settled row was already in INBOX and skipped; the moved row went with the confirmed uid",
308
- );
309
- });
310
-
311
- it("waits one row's ceiling for a batch, not one per row", async () => {
312
- const rows = [movingRow(), movingRow(), movingRow()].map((row, index) => ({
313
- ...row,
314
- messageId: `${MOVING_ID}-${index}`,
315
- }));
316
- const { service } = buildWorld(rows);
317
-
318
- const startedAt = Date.now();
319
- await assert.rejects(
320
- () =>
321
- service.moveMessages(
322
- ACCOUNT_CONFIG,
323
- rows.map((row) => row.messageId),
324
- INBOX,
325
- ACCOUNT,
326
- ),
327
- MessagePlacementUnsettledError,
328
- );
329
-
330
- assert.ok(
331
- Date.now() - startedAt < 500,
332
- "three rows refused within one 200ms ceiling, not three",
333
- );
334
- });
335
- });
336
-
337
- describe("the move gate refuses only a uid that names somebody else (#665)", () => {
338
- it("moves a freshly copied row rather than waiting on it", async () => {
339
- // A copy is `moving` with no server-side uid yet. That uid is not ready,
340
- // which is not the same as naming another folder's message.
341
- const { service, events } = buildWorld([freshCopyRow()]);
342
-
343
- const startedAt = Date.now();
344
- await service.moveMessage(ACCOUNT_CONFIG, COPY_ID, INBOX, ACCOUNT);
345
-
346
- assert.equal(events.length, 1);
347
- assert.equal(events[0].type, "MESSAGE_MOVE");
348
- assert.ok(Date.now() - startedAt < 100, "and never entered the wait");
349
- });
350
-
351
- it("waits out a delete in flight rather than binding its borrowed uid", async () => {
352
- const { service, events, patches } = buildWorld([deletingRow()]);
353
-
354
- await assert.rejects(
355
- () => service.moveMessage(ACCOUNT_CONFIG, DELETING_ID, INBOX, ACCOUNT),
356
- (error: unknown) => error instanceof MessagePlacementUnsettledError,
357
- );
358
-
359
- assert.deepEqual(events, [], "nothing was enqueued");
360
- assert.deepEqual(patches, [], "and no local write was made");
361
- });
362
-
363
- it("acts on a row a move gave up on, rather than refusing it", async () => {
364
- // A give-up hands the row back to the placement the server confirmed
365
- // before it stops (R3), so the folder and uid name the same message and
366
- // the user's next move is an ordinary one. Refusing it — which is what a
367
- // give-up left `moving` used to earn — made the message unmovable for
368
- // good, with nothing routine to repair it.
369
- const { service, events } = buildWorld([strandedRow()]);
370
-
371
- const startedAt = Date.now();
372
- await service.moveMessage(ACCOUNT_CONFIG, STRANDED_ID, ARCHIVE, ACCOUNT);
373
-
374
- assert.equal(events.length, 1);
375
- assert.equal(events[0].type, "MESSAGE_MOVE");
376
- assert.ok(Date.now() - startedAt < 100, "and never entered the wait");
377
- });
378
- });