@remit/data-ports 0.0.41 → 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 +1 -1
- package/src/errors.ts +18 -0
- package/src/folder-role.test.ts +23 -1
- package/src/mailbox-name.test.ts +37 -1
- package/src/mailbox-name.ts +16 -5
package/package.json
CHANGED
package/src/errors.ts
CHANGED
|
@@ -80,6 +80,24 @@ export class FolderRoleUnresolvedError extends ConflictError {
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
/**
|
|
84
|
+
* A role cannot be appointed to a mailbox the mail server has not settled yet
|
|
85
|
+
* (imap-mutations R2: wait). Its own code, because the role is not unresolved —
|
|
86
|
+
* the target is: the client words a wait, not a retry. Clearing a role is never
|
|
87
|
+
* refused this way.
|
|
88
|
+
*/
|
|
89
|
+
export class MailboxNotSettledError extends ConflictError {
|
|
90
|
+
name = "MailboxNotSettledError";
|
|
91
|
+
|
|
92
|
+
constructor(message: string, mailboxId: string, syncStatus: string) {
|
|
93
|
+
super(message);
|
|
94
|
+
this.publicApiError = {
|
|
95
|
+
code: "mailbox_not_settled",
|
|
96
|
+
details: { mailboxId, syncStatus },
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
83
101
|
/**
|
|
84
102
|
* A message exists but its body could not be fetched/parsed after every
|
|
85
103
|
* body-sync retry was spent (issue #1270 / epic #1281 invariant 3). This is
|
package/src/folder-role.test.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { describe, it } from "node:test";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
CanonicalMailboxRole,
|
|
5
|
+
MailboxSpecialUse,
|
|
6
|
+
MailboxSyncStatus,
|
|
7
|
+
} from "@remit/domain-enums";
|
|
4
8
|
import {
|
|
5
9
|
composeFolderRoleAppointmentLabelName,
|
|
6
10
|
composeFolderRoleAppointmentName,
|
|
@@ -173,6 +177,24 @@ describe("resolveConfirmedMailboxForRole", () => {
|
|
|
173
177
|
});
|
|
174
178
|
|
|
175
179
|
describe("resolveRoleForAccount", () => {
|
|
180
|
+
it("resolves an appointment naming a mailbox whose last sync failed", () => {
|
|
181
|
+
// `failed` has three writers (imap-worker mailbox-management: create :166
|
|
182
|
+
// rolls nothing back, rename :275 restores oldPath, delete :384 leaves the
|
|
183
|
+
// folder) and in two the folder is really at the path the row names.
|
|
184
|
+
const failed: RoleMailboxCandidate & { syncStatus: string } = {
|
|
185
|
+
...mailbox("mb-trash", "INBOX/Prullenbak"),
|
|
186
|
+
syncStatus: MailboxSyncStatus.failed,
|
|
187
|
+
};
|
|
188
|
+
assert.deepEqual(
|
|
189
|
+
resolveRoleForAccount(
|
|
190
|
+
CanonicalMailboxRole.Trash,
|
|
191
|
+
[mailbox("mb-inbox", "INBOX"), failed],
|
|
192
|
+
"mb-trash",
|
|
193
|
+
),
|
|
194
|
+
{ kind: "appointed", mailbox: failed },
|
|
195
|
+
);
|
|
196
|
+
});
|
|
197
|
+
|
|
176
198
|
it("answers none when nothing names a Trash folder", () => {
|
|
177
199
|
// #887 Done item 4: an account whose folders happen to include a Dutch
|
|
178
200
|
// "Prullenbak" has no Trash reader may act on — no flag, no appointment,
|
package/src/mailbox-name.test.ts
CHANGED
|
@@ -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
|
+
});
|
package/src/mailbox-name.ts
CHANGED
|
@@ -1,24 +1,35 @@
|
|
|
1
|
-
export interface
|
|
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:
|
|
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
|
|
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.
|