@remit/imap-worker 0.0.43 → 0.0.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/imap-worker",
3
- "version": "0.0.43",
3
+ "version": "0.0.45",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "exports": {
@@ -16,6 +16,7 @@ import { afterEach, beforeEach, describe, it, mock } from "node:test";
16
16
  import { SQSClient } from "@aws-sdk/client-sqs";
17
17
  import { getClient, type RemitClient, setClient } from "@remit/backend/client";
18
18
  import type {
19
+ IAddressRepository,
19
20
  IMessageFlagPushRepository,
20
21
  IMessageFlagRepository,
21
22
  IMessagePlacementMoveRepository,
@@ -177,6 +178,9 @@ const buildHarness = (): Harness => {
177
178
  messageService,
178
179
  threadMessageService,
179
180
  markerService: placementMarkerService,
181
+ addressService: {
182
+ reconcileJunkOnlyForMessage: async () => {},
183
+ } as unknown as IAddressRepository,
180
184
  sqsQueueUrl: "https://sqs.eu-west-1.amazonaws.com/000/message-mgmt",
181
185
  });
182
186
 
@@ -178,6 +178,7 @@ export const syncMessageBody = async (
178
178
  messageService,
179
179
  threadMessageService,
180
180
  markerService,
181
+ addressService,
181
182
  sqsQueueUrl: placementMoveQueueUrl,
182
183
  })
183
184
  : undefined;
@@ -1,38 +1,12 @@
1
1
  import type { MailboxItem } from "@remit/data-ports";
2
+ import { resolveMailboxByLeafName } from "@remit/data-ports/mailbox-name";
2
3
 
3
4
  export type SentMailboxCandidate = Pick<
4
5
  MailboxItem,
5
6
  "mailboxId" | "fullPath" | "hierarchyDelimiter"
6
7
  >;
7
8
 
8
- const SENT_FOLDER_NAMES = [
9
- "sent",
10
- "sent items",
11
- "sent messages",
12
- "sent mail",
13
- ] as const;
14
-
15
- // A flat mailbox namespace reports no delimiter at all — ImapFlow gives `""`
16
- // for a NIL LIST delimiter — and splitting on "" returns single characters, so
17
- // the path is its own leaf.
18
- const segments = (mailbox: SentMailboxCandidate): string[] =>
19
- mailbox.hierarchyDelimiter.length === 0
20
- ? [mailbox.fullPath]
21
- : mailbox.fullPath.split(mailbox.hierarchyDelimiter);
22
-
23
- const rank = (mailbox: SentMailboxCandidate): number | null => {
24
- const parts = segments(mailbox);
25
- const leaf = parts[parts.length - 1] ?? mailbox.fullPath;
26
- const nameIndex = SENT_FOLDER_NAMES.indexOf(
27
- leaf.toLowerCase() as (typeof SENT_FOLDER_NAMES)[number],
28
- );
29
- if (nameIndex < 0) {
30
- return null;
31
- }
32
- // Depth outranks the name: a "Sent" buried under Trash or an archive must
33
- // never beat the account's real "Sent Items" one level up.
34
- return parts.length * SENT_FOLDER_NAMES.length + nameIndex;
35
- };
9
+ const SENT_FOLDER_NAMES = ["sent", "sent items", "sent messages", "sent mail"];
36
10
 
37
11
  /**
38
12
  * The Sent folder by conventional name, for servers that advertise no `\Sent`
@@ -42,19 +16,5 @@ const rank = (mailbox: SentMailboxCandidate): number | null => {
42
16
  */
43
17
  export const resolveSentMailboxByName = (
44
18
  mailboxes: SentMailboxCandidate[],
45
- ): SentMailboxCandidate | null => {
46
- let best: { mailbox: SentMailboxCandidate; rank: number } | null = null;
47
- for (const mailbox of mailboxes) {
48
- const candidate = rank(mailbox);
49
- if (candidate === null) continue;
50
- if (
51
- !best ||
52
- candidate < best.rank ||
53
- (candidate === best.rank &&
54
- mailbox.fullPath.localeCompare(best.mailbox.fullPath) < 0)
55
- ) {
56
- best = { mailbox, rank: candidate };
57
- }
58
- }
59
- return best?.mailbox ?? null;
60
- };
19
+ ): SentMailboxCandidate | null =>
20
+ resolveMailboxByLeafName(mailboxes, SENT_FOLDER_NAMES);