@remit/data-ports 0.0.42 → 0.0.43

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/data-ports",
3
- "version": "0.0.42",
3
+ "version": "0.0.43",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -1,6 +1,6 @@
1
1
  import assert from "node:assert/strict";
2
2
  import { describe, it } from "node:test";
3
- import { resolveMailboxByLeafName } from "./mailbox-name.js";
3
+ import { mailboxLeafName, resolveMailboxByLeafName } from "./mailbox-name.js";
4
4
 
5
5
  const JUNK_NAMES = ["junk", "spam", "junk e-mail", "junk email", "bulk mail"];
6
6
 
@@ -68,3 +68,39 @@ describe("resolveMailboxByLeafName", () => {
68
68
  assert.equal(found, null);
69
69
  });
70
70
  });
71
+
72
+ describe("mailboxLeafName", () => {
73
+ it("takes the leaf under a dot-delimited namespace", () => {
74
+ assert.equal(
75
+ mailboxLeafName({
76
+ fullPath: "INBOX.Projects.Q3",
77
+ hierarchyDelimiter: ".",
78
+ }),
79
+ "Q3",
80
+ );
81
+ });
82
+
83
+ it("takes the leaf under a slash-delimited namespace", () => {
84
+ assert.equal(
85
+ mailboxLeafName({
86
+ fullPath: "INBOX/Sent Messages",
87
+ hierarchyDelimiter: "/",
88
+ }),
89
+ "Sent Messages",
90
+ );
91
+ });
92
+
93
+ it("keeps the whole name when the server reports no delimiter", () => {
94
+ assert.equal(
95
+ mailboxLeafName({ fullPath: "Projects/Q3", hierarchyDelimiter: "" }),
96
+ "Projects/Q3",
97
+ );
98
+ });
99
+
100
+ it("keeps a top-level name that carries no delimiter", () => {
101
+ assert.equal(
102
+ mailboxLeafName({ fullPath: "INBOX", hierarchyDelimiter: "." }),
103
+ "INBOX",
104
+ );
105
+ });
106
+ });
@@ -1,24 +1,35 @@
1
- export interface MailboxNameCandidate {
2
- mailboxId: string;
1
+ export interface MailboxPath {
3
2
  fullPath: string;
4
3
  hierarchyDelimiter: string;
5
4
  }
6
5
 
6
+ export interface MailboxNameCandidate extends MailboxPath {
7
+ mailboxId: string;
8
+ }
9
+
7
10
  // A flat mailbox namespace reports no delimiter at all — ImapFlow gives `""`
8
11
  // for a NIL LIST delimiter — and splitting on "" returns single characters, so
9
12
  // the path is its own leaf.
10
- const segments = (mailbox: MailboxNameCandidate): string[] =>
13
+ const segments = (mailbox: MailboxPath): string[] =>
11
14
  mailbox.hierarchyDelimiter.length === 0
12
15
  ? [mailbox.fullPath]
13
16
  : mailbox.fullPath.split(mailbox.hierarchyDelimiter);
14
17
 
18
+ /**
19
+ * The folder's own name: the last segment of its path under the delimiter its
20
+ * own server reports (`INBOX/Spam` → `Spam`, `INBOX.Projects.Q3` → `Q3`).
21
+ */
22
+ export const mailboxLeafName = (mailbox: MailboxPath): string => {
23
+ const parts = segments(mailbox);
24
+ return parts[parts.length - 1] || mailbox.fullPath;
25
+ };
26
+
15
27
  const rank = (
16
28
  mailbox: MailboxNameCandidate,
17
29
  names: readonly string[],
18
30
  ): number | null => {
19
31
  const parts = segments(mailbox);
20
- const leaf = parts[parts.length - 1] ?? mailbox.fullPath;
21
- const nameIndex = names.indexOf(leaf.toLowerCase());
32
+ const nameIndex = names.indexOf(mailboxLeafName(mailbox).toLowerCase());
22
33
  if (nameIndex < 0) return null;
23
34
  // Depth outranks the name: a "Spam" buried under Trash or an archive must
24
35
  // never beat the account's real "Junk" one level up.