@remit/web-client 0.0.346 → 0.0.348

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 (108) hide show
  1. package/dist/src/components/mail/BriefPane.js +3 -3
  2. package/dist/src/components/mail/CheckAgainProvider.d.ts +30 -0
  3. package/dist/src/components/mail/CheckAgainProvider.js +194 -0
  4. package/dist/src/components/mail/{FlaggedList.d.ts → CollectionList.d.ts} +7 -3
  5. package/dist/src/components/mail/{FlaggedList.js → CollectionList.js} +29 -24
  6. package/dist/src/components/mail/CollectionPane.d.ts +32 -0
  7. package/dist/src/components/mail/{FlaggedPane.js → CollectionPane.js} +35 -33
  8. package/dist/src/components/mail/ConversationView.d.ts +7 -8
  9. package/dist/src/components/mail/ConversationView.js +4 -4
  10. package/dist/src/components/mail/DailyBrief.js +6 -4
  11. package/dist/src/components/mail/IntelligencePane.d.ts +2 -2
  12. package/dist/src/components/mail/IntelligencePane.js +33 -4
  13. package/dist/src/components/mail/MailSidebarAdapter.js +29 -7
  14. package/dist/src/components/mail/MailboxPane.js +10 -12
  15. package/dist/src/components/mail/MessageActionMenu.d.ts +3 -1
  16. package/dist/src/components/mail/MessageActionMenu.js +3 -3
  17. package/dist/src/components/mail/MessageCard.js +9 -1
  18. package/dist/src/components/mail/MessageList.js +11 -2
  19. package/dist/src/components/mail/MessageListItem.d.ts +4 -2
  20. package/dist/src/components/mail/MessageListItem.js +4 -6
  21. package/dist/src/components/mail/SpamBannerSlot.d.ts +10 -0
  22. package/dist/src/components/mail/SpamBannerSlot.js +56 -0
  23. package/dist/src/components/mail/SwipeableMessageRow.d.ts +3 -2
  24. package/dist/src/components/mail/SwipeableMessageRow.js +6 -6
  25. package/dist/src/components/mail/ThreadListInteraction.d.ts +2 -0
  26. package/dist/src/components/mail/ThreadListInteraction.js +12 -2
  27. package/dist/src/components/settings/classification/FailureBanner.js +3 -4
  28. package/dist/src/components/settings/spam/SpamSettingsPanel.d.ts +6 -0
  29. package/dist/src/components/settings/spam/SpamSettingsPanel.js +176 -0
  30. package/dist/src/hooks/{useStarredThreads.d.ts → useCollectionThreads.d.ts} +10 -8
  31. package/dist/src/hooks/{useStarredThreads.js → useCollectionThreads.js} +16 -14
  32. package/dist/src/hooks/useCurrentMailboxName.d.ts +1 -0
  33. package/dist/src/hooks/useCurrentMailboxName.js +6 -1
  34. package/dist/src/hooks/useIntelligenceData.d.ts +2 -4
  35. package/dist/src/hooks/useIntelligenceData.js +1 -127
  36. package/dist/src/hooks/useJunkMailboxIds.d.ts +2 -0
  37. package/dist/src/hooks/useJunkMailboxIds.js +17 -0
  38. package/dist/src/hooks/useLabels.d.ts +10 -9
  39. package/dist/src/hooks/useLabels.js +25 -6
  40. package/dist/src/lib/brief.d.ts +1 -1
  41. package/dist/src/lib/brief.js +3 -3
  42. package/dist/src/lib/check-again.d.ts +33 -0
  43. package/dist/src/lib/check-again.js +66 -0
  44. package/dist/src/lib/{flagged-criteria.d.ts → collection-criteria.d.ts} +18 -6
  45. package/dist/src/lib/{flagged-criteria.js → collection-criteria.js} +4 -3
  46. package/dist/src/lib/conversation-target.d.ts +3 -2
  47. package/dist/src/lib/label-folders.d.ts +6 -0
  48. package/dist/src/lib/label-folders.js +10 -0
  49. package/dist/src/lib/mail-route.d.ts +10 -5
  50. package/dist/src/lib/mail-route.js +9 -1
  51. package/dist/src/lib/mail-search.d.ts +11 -0
  52. package/dist/src/lib/mail-search.js +4 -0
  53. package/dist/src/lib/search-scope.d.ts +2 -2
  54. package/dist/src/lib/search-scope.js +4 -4
  55. package/dist/src/lib/search-tokens.d.ts +1 -1
  56. package/dist/src/lib/search-tokens.js +2 -2
  57. package/dist/src/lib/spam-overview.d.ts +23 -0
  58. package/dist/src/lib/spam-overview.js +44 -0
  59. package/dist/src/lib/spam.d.ts +32 -0
  60. package/dist/src/lib/spam.js +38 -0
  61. package/dist/src/lib/thread-search-tokens.js +3 -1
  62. package/dist/src/routeTree.gen.d.ts +312 -5
  63. package/dist/src/routeTree.gen.js +72 -0
  64. package/dist/src/routes/__root.js +2 -1
  65. package/dist/src/routes/mail/flagged/$threadId/$messageId.js +2 -2
  66. package/dist/src/routes/mail/flagged/$threadId/index.js +2 -2
  67. package/dist/src/routes/mail/flagged/index.js +2 -2
  68. package/dist/src/routes/mail/flagged.js +3 -2
  69. package/dist/src/routes/mail/label/$labelId/$threadId/$messageId/$mode.{-$outboxMessageId}.d.ts +18 -0
  70. package/dist/src/routes/mail/label/$labelId/$threadId/$messageId/$mode.{-$outboxMessageId}.js +8 -0
  71. package/dist/src/routes/mail/label/$labelId/$threadId/$messageId.d.ts +15 -0
  72. package/dist/src/routes/mail/label/$labelId/$threadId/$messageId.js +14 -0
  73. package/dist/src/routes/mail/label/$labelId/$threadId/index.d.ts +15 -0
  74. package/dist/src/routes/mail/label/$labelId/$threadId/index.js +9 -0
  75. package/dist/src/routes/mail/label/$labelId/$threadId.d.ts +15 -0
  76. package/dist/src/routes/mail/label/$labelId/$threadId.js +8 -0
  77. package/dist/src/routes/mail/label/$labelId/compose.{-$outboxMessageId}.d.ts +15 -0
  78. package/dist/src/routes/mail/label/$labelId/compose.{-$outboxMessageId}.js +10 -0
  79. package/dist/src/routes/mail/label/$labelId/index.d.ts +15 -0
  80. package/dist/src/routes/mail/label/$labelId/index.js +9 -0
  81. package/dist/src/routes/mail/label/$labelId.d.ts +15 -0
  82. package/dist/src/routes/mail/label/$labelId.js +30 -0
  83. package/dist/src/routes/mail/label/index.d.ts +29 -0
  84. package/dist/src/routes/mail/label/index.js +18 -0
  85. package/dist/src/routes/settings/filters.d.ts +6 -2
  86. package/dist/src/routes/settings/filters.js +10 -3
  87. package/dist/src/routes/settings/senders.d.ts +14 -2
  88. package/dist/src/routes/settings/senders.js +32 -15
  89. package/dist/src/routes/settings/spam.d.ts +1 -0
  90. package/dist/src/routes/settings/spam.js +15 -0
  91. package/dist/src/routes/settings.js +6 -1
  92. package/dist/src/routing/browsed-list.d.ts +1 -1
  93. package/dist/src/routing/browsed-list.js +15 -4
  94. package/dist/src/routing/compose.js +10 -6
  95. package/dist/src/routing/index.d.ts +1 -1
  96. package/dist/src/routing/index.js +1 -1
  97. package/dist/src/routing/nav-selection.d.ts +5 -0
  98. package/dist/src/routing/nav-selection.js +15 -0
  99. package/dist/src/routing/open-thread.js +23 -3
  100. package/dist/src/routing/reply.js +28 -11
  101. package/dist/src/routing/search-mirror.d.ts +5 -0
  102. package/dist/src/routing/search-mirror.js +20 -2
  103. package/dist/src/routing/spam-link.d.ts +3 -0
  104. package/dist/src/routing/spam-link.js +12 -0
  105. package/package.json +2 -2
  106. package/dist/src/components/mail/AuthenticityBanner.d.ts +0 -14
  107. package/dist/src/components/mail/AuthenticityBanner.js +0 -18
  108. package/dist/src/components/mail/FlaggedPane.d.ts +0 -29
@@ -1,5 +1,4 @@
1
1
  import { addressOperationsSearchAddressesOptions } from "@remit/api-http-client/@tanstack/react-query.gen.ts";
2
- import { DisplayNameCorrespondence, SenderTrust } from "@remit/domain-enums";
3
2
  import { isThreadCategory } from "@remit/ui";
4
3
  import { useQuery } from "@tanstack/react-query";
5
4
  import { useMemo } from "react";
@@ -31,8 +30,6 @@ export function isSenderAddressUnverifiable(fromEmail) {
31
30
  return true;
32
31
  return !domain.includes(".");
33
32
  }
34
- const NO_SIGNAL_SUMMARY = "We can't verify the sender of this email, which could mean it's from an insecure source.";
35
- const UNREADABLE_SENDER_SUMMARY = "We couldn't read this sender's address, so we can't confirm who really sent this message.";
36
33
  /**
37
34
  * Build category intel from the thread message and address lookup.
38
35
  *
@@ -85,127 +82,6 @@ function buildSenderFlags(address) {
85
82
  blocked: address.flags.blocked?.value === true,
86
83
  };
87
84
  }
88
- /** The brand the display name asserts, or `undefined` when it asserts none. */
89
- function claimedBrandOf(thread) {
90
- if (!thread.fromName)
91
- return undefined;
92
- if (thread.fromName === thread.fromEmail)
93
- return undefined;
94
- return thread.fromName;
95
- }
96
- function joinDomains(domains) {
97
- if (domains.length === 1)
98
- return domains[0];
99
- return `${domains.slice(0, -1).join(", ")} and ${domains[domains.length - 1]}`;
100
- }
101
- /**
102
- * The clauses naming what does not line up on a message whose signature checks
103
- * out. Empty when everything the backend compared agreed — including when it
104
- * compared nothing, which is every message outside Junk that the provider's
105
- * filter did not already call spam.
106
- *
107
- * Each clause leads with the concern and names `auth.fromDomain` — the
108
- * domain `classifyDisplayNameCorrespondence` actually compared the display
109
- * name against (`senderMismatch.ts` calls it with the From address's own
110
- * domain, never the DKIM signing domain). Naming `auth.dkimDomain` instead
111
- * would assert a comparison that was never made: on a message signed by a
112
- * relay or ESP infrastructure domain, the display name was checked against
113
- * the sender's own address, not that domain. These clauses are the caution
114
- * tier's entire summary: there is no separate "verified" sentence in front
115
- * of them for the signing fact to hide behind.
116
- */
117
- function describeSenderMismatch(auth, claimedBrand, senderTrust) {
118
- const trusted = senderTrust === SenderTrust.Vip || senderTrust === SenderTrust.Wellknown;
119
- const clauses = [];
120
- const correspondence = auth.displayNameCorrespondence;
121
- if (claimedBrand) {
122
- if (correspondence === DisplayNameCorrespondence.Unrelated && !trusted) {
123
- clauses.push(`The name it shows, "${claimedBrand}", has nothing to do with ${auth.fromDomain}.`);
124
- }
125
- else if (correspondence === DisplayNameCorrespondence.Lookalike) {
126
- clauses.push(`The name it shows, "${claimedBrand}", only looks like ${auth.fromDomain}.`);
127
- }
128
- else if (correspondence === DisplayNameCorrespondence.ForeignAddress) {
129
- clauses.push(`The name it shows, "${claimedBrand}", is an address ${auth.fromDomain} cannot send from.`);
130
- }
131
- }
132
- const linkDomains = readDomainList(auth.offDomainLinkDomains);
133
- if (linkDomains.length > 0 && !trusted) {
134
- clauses.push(`Its links go to ${joinDomains(linkDomains.slice(0, 3))}.`);
135
- }
136
- return clauses;
137
- }
138
- /**
139
- * The field is a JSON blob on the message row, so a value written by an older
140
- * or drifted writer reaches here as whatever it happens to be. Anything that is
141
- * not a list of non-empty strings carries no destination to name.
142
- */
143
- function readDomainList(value) {
144
- if (!Array.isArray(value))
145
- return [];
146
- return value.filter((entry) => typeof entry === "string" && entry.length > 0);
147
- }
148
- /** Build authenticity intel from the thread message's authenticity field. */
149
- export function buildAuthenticityIntel(thread) {
150
- if (isSenderAddressUnverifiable(thread.fromEmail)) {
151
- return {
152
- verdict: "mismatch",
153
- fromDomain: "",
154
- addressUnreadable: true,
155
- summary: UNREADABLE_SENDER_SUMMARY,
156
- };
157
- }
158
- const auth = thread.authenticity;
159
- if (!auth) {
160
- return {
161
- verdict: "caution",
162
- fromDomain: thread.fromEmail?.split("@")[1] ?? "",
163
- summary: NO_SIGNAL_SUMMARY,
164
- };
165
- }
166
- if (!auth.dkimMismatch) {
167
- const claimed = claimedBrandOf(thread);
168
- const unlike = describeSenderMismatch(auth, claimed, thread.senderTrust);
169
- if (unlike.length > 0) {
170
- return {
171
- verdict: "caution",
172
- fromDomain: auth.fromDomain,
173
- dkimDomain: auth.dkimDomain,
174
- claimedBrand: claimed,
175
- summary: unlike.join(" "),
176
- };
177
- }
178
- return {
179
- verdict: "aligned",
180
- fromDomain: auth.fromDomain,
181
- dkimDomain: auth.dkimDomain,
182
- summary: auth.dkimDomain
183
- ? `This message was signed by ${auth.dkimDomain}.`
184
- : `Nothing looks unusual about this sender.`,
185
- };
186
- }
187
- const fromDomain = auth.fromDomain;
188
- const dkimDomain = auth.dkimDomain;
189
- const claimedBrand = claimedBrandOf(thread);
190
- // dkimDomain is known whenever a mismatch was named against a real
191
- // domain; the fallback covers the (defensive, not currently reachable)
192
- // case where a mismatch fires with none — say what actually happened
193
- // (a signature failed to verify) rather than inventing a sender identity
194
- // we do not have.
195
- const whatHappened = dkimDomain
196
- ? `it was actually sent from ${dkimDomain}`
197
- : "its signature failed to verify";
198
- const summary = claimedBrand
199
- ? `The display name claims "${claimedBrand}", but ${whatHappened}${dkimDomain ? ` — not ${fromDomain}` : ""}. Real senders use their own address.`
200
- : `This message claims to be from ${fromDomain}, but ${whatHappened}.`;
201
- return {
202
- verdict: "mismatch",
203
- fromDomain,
204
- dkimDomain,
205
- claimedBrand,
206
- summary,
207
- };
208
- }
209
85
  export function buildPlacementIntel(thread) {
210
86
  const verdict = thread.placementVerdict;
211
87
  if (!verdict)
@@ -222,7 +98,7 @@ export function buildPlacementIntel(thread) {
222
98
  * Maps a `RemitImapThreadMessageResponse` into `IntelligenceData` for the
223
99
  * `IntelligencePanel` component. Two data sources:
224
100
  *
225
- * 1. The thread row itself (already loaded) → sender basics, trust, authenticity, category.
101
+ * 1. The thread row itself (already loaded) → sender basics, trust, category.
226
102
  * 2. `GET /addresses/search?q=<email>` → address flags (VIP/muted/blocked/etc.)
227
103
  * and first-seen timestamp. One round-trip per unique sender.
228
104
  */
@@ -241,12 +117,10 @@ export function useIntelligenceData(thread) {
241
117
  if (!thread)
242
118
  return null;
243
119
  const sender = buildSenderIntel(thread, address);
244
- const authenticity = buildAuthenticityIntel(thread);
245
120
  const category = buildCategoryIntel(thread, address);
246
121
  const flags = buildSenderFlags(address);
247
122
  return {
248
123
  sender,
249
- authenticity,
250
124
  category,
251
125
  flags,
252
126
  placement: buildPlacementIntel(thread),
@@ -0,0 +1,2 @@
1
+ /** Every account's appointed Spam folder, which decides moved from suspected. */
2
+ export declare const useJunkMailboxIds: () => ReadonlySet<string>;
@@ -0,0 +1,17 @@
1
+ import { configOperationsGetConfigOptions } from "@remit/api-http-client/@tanstack/react-query.gen.ts";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { useMemo } from "react";
4
+ const NONE = new Set();
5
+ /** Every account's appointed Spam folder, which decides moved from suspected. */
6
+ export const useJunkMailboxIds = () => {
7
+ const { data } = useQuery({
8
+ ...configOperationsGetConfigOptions(),
9
+ staleTime: Infinity,
10
+ });
11
+ return useMemo(() => {
12
+ const ids = (data?.accounts ?? []).flatMap((account) => account.folderAppointments.flatMap((appointment) => appointment.role === "Junk" && appointment.mailboxId
13
+ ? [appointment.mailboxId]
14
+ : []));
15
+ return ids.length === 0 ? NONE : new Set(ids);
16
+ }, [data?.accounts]);
17
+ };
@@ -1,4 +1,4 @@
1
- import type { RemitImapLabelColor, RemitImapUpdateLabelInput } from "@remit/api-http-client/types.gen.ts";
1
+ import type { RemitImapLabelColor, RemitImapLabelResponse, RemitImapUpdateLabelInput } from "@remit/api-http-client/types.gen.ts";
2
2
  /**
3
3
  * The query key the label list reads and every mutation invalidates on
4
4
  * success — the same contract `buildFilterListKey` pins for filters, so the
@@ -10,19 +10,20 @@ export declare const buildLabelListKey: (accountId: string) => [Pick<import("@re
10
10
  _infinite?: boolean;
11
11
  tags?: ReadonlyArray<string>;
12
12
  }];
13
- /** List the account's labels. */
13
+ /**
14
+ * The user's labels, every page of them. Labels belong to the user rather than
15
+ * to one account, so any of their accounts answers for all of them.
16
+ */
14
17
  export declare const useLabelList: (accountId: string | undefined) => {
15
- labels: import("@remit/api-http-client").RemitImapLabelResponse[];
18
+ labels: RemitImapLabelResponse[];
19
+ isSuccess: boolean;
16
20
  isPending: boolean;
17
21
  isError: boolean;
18
- error: import("@remit/api-http-client").LabelOperationsListLabelsError | null;
19
- refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<NoInfer<{
20
- continuationToken?: import("@remit/api-http-client").String800;
21
- items: Array<import("@remit/api-http-client").RemitImapLabelResponse>;
22
- }>, import("@remit/api-http-client").LabelOperationsListLabelsError>>;
22
+ error: Error | null;
23
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<NoInfer<RemitImapLabelResponse[]>, Error>>;
23
24
  };
24
25
  export declare const useCreateLabel: (accountId: string | undefined) => {
25
- createLabel: (name: string, color?: RemitImapLabelColor) => Promise<import("@remit/api-http-client").RemitImapLabelResponse>;
26
+ createLabel: (name: string, color?: RemitImapLabelColor) => Promise<RemitImapLabelResponse>;
26
27
  isPending: boolean;
27
28
  isError: boolean;
28
29
  error: import("@remit/api-http-client").ApiError | null;
@@ -1,4 +1,5 @@
1
- import { labelDetailOperationsDeleteLabelMutation, labelDetailOperationsUpdateLabelMutation, labelOperationsCreateLabelMutation, labelOperationsListLabelsOptions, labelOperationsListLabelsQueryKey, } from "@remit/api-http-client/@tanstack/react-query.gen.ts";
1
+ import { labelDetailOperationsDeleteLabelMutation, labelDetailOperationsUpdateLabelMutation, labelOperationsCreateLabelMutation, labelOperationsListLabelsQueryKey, } from "@remit/api-http-client/@tanstack/react-query.gen.ts";
2
+ import { labelOperationsListLabels } from "@remit/api-http-client/sdk.gen.ts";
2
3
  import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
3
4
  import { useCallback } from "react";
4
5
  /**
@@ -8,16 +9,34 @@ import { useCallback } from "react";
8
9
  * label is created, renamed, recolored, or deleted (issue #26).
9
10
  */
10
11
  export const buildLabelListKey = (accountId) => labelOperationsListLabelsQueryKey({ path: { accountId } });
11
- /** List the account's labels. */
12
+ const listAllLabels = async (accountId) => {
13
+ const labels = [];
14
+ let continuationToken;
15
+ do {
16
+ const { data } = await labelOperationsListLabels({
17
+ path: { accountId },
18
+ query: { continuationToken },
19
+ throwOnError: true,
20
+ });
21
+ labels.push(...data.items);
22
+ continuationToken = data.continuationToken;
23
+ } while (continuationToken);
24
+ return labels;
25
+ };
26
+ const NO_LABELS = [];
27
+ /**
28
+ * The user's labels, every page of them. Labels belong to the user rather than
29
+ * to one account, so any of their accounts answers for all of them.
30
+ */
12
31
  export const useLabelList = (accountId) => {
13
32
  const query = useQuery({
14
- ...labelOperationsListLabelsOptions({
15
- path: { accountId: accountId ?? "" },
16
- }),
33
+ queryKey: buildLabelListKey(accountId ?? ""),
34
+ queryFn: () => listAllLabels(accountId ?? ""),
17
35
  enabled: !!accountId,
18
36
  });
19
37
  return {
20
- labels: query.data?.items ?? [],
38
+ labels: query.data ?? NO_LABELS,
39
+ isSuccess: query.isSuccess,
21
40
  isPending: query.isPending,
22
41
  isError: query.isError,
23
42
  error: query.error,
@@ -42,7 +42,7 @@ import type { SearchToken } from "./search-tokens.js";
42
42
  * remit-ui row body components. Mirrors the logic in MessageListItem so the
43
43
  * brief rows render identically to per-mailbox rows.
44
44
  */
45
- export declare function toThreadRowData(thread: RemitImapThreadMessageResponse): ThreadRowData;
45
+ export declare function toThreadRowData(thread: RemitImapThreadMessageResponse, junkMailboxIds: ReadonlySet<string>): ThreadRowData;
46
46
  /**
47
47
  * The categories the brief asks for, in the order it renders them. A category
48
48
  * is both the section's own scope and the query parameter its request carries;
@@ -38,13 +38,13 @@ import { CATEGORY_SECTION_ORDER, categoryLabels, } from "@remit/ui";
38
38
  import { toDisplayCategory } from "./display-category.js";
39
39
  import { formatEmailDate } from "./format.js";
40
40
  import { rowSettlement } from "./row-settlement.js";
41
+ import { spamRowMark } from "./spam.js";
41
42
  /**
42
43
  * Map a `RemitImapThreadMessageResponse` to the `ThreadRowData` shape used by
43
44
  * remit-ui row body components. Mirrors the logic in MessageListItem so the
44
45
  * brief rows render identically to per-mailbox rows.
45
46
  */
46
- export function toThreadRowData(thread) {
47
- const suspicious = thread.authenticity?.dkimMismatch === true;
47
+ export function toThreadRowData(thread, junkMailboxIds) {
48
48
  return {
49
49
  id: thread.messageId,
50
50
  accountId: thread.accountId,
@@ -61,7 +61,7 @@ export function toThreadRowData(thread) {
61
61
  starred: thread.hasStars === true,
62
62
  trust: thread.senderTrust,
63
63
  category: toDisplayCategory(thread.category),
64
- suspicious,
64
+ spam: spamRowMark(thread, junkMailboxIds),
65
65
  ...rowSettlement(thread),
66
66
  };
67
67
  }
@@ -0,0 +1,33 @@
1
+ import type { RemitImapMessageSpamVerdict, RemitImapRescanFailureCode, RemitImapRescanResult } from "@remit/api-http-client/types.gen.ts";
2
+ import type { CheckAgainFailure, CheckAgainSummary, ThreadRowSpam } from "@remit/ui";
3
+ /** The most message ids one rescan call accepts. */
4
+ export declare const RESCAN_BATCH_SIZE = 10;
5
+ export interface CheckAgainTarget {
6
+ messageId: string;
7
+ accountId: string;
8
+ mailboxId: string;
9
+ threadId: string | undefined;
10
+ subject: string;
11
+ /** The row's spam mark before the check, to say what changed. */
12
+ before: ThreadRowSpam | undefined;
13
+ }
14
+ export interface RescanBatch {
15
+ accountId: string;
16
+ targets: CheckAgainTarget[];
17
+ }
18
+ /**
19
+ * The calls a run makes: rescan is per account and takes ten ids, so the
20
+ * selection splits by account first, then into tens, keeping its order.
21
+ */
22
+ export declare const rescanBatches: (targets: readonly CheckAgainTarget[]) => RescanBatch[];
23
+ export declare const EMPTY_SUMMARY: CheckAgainSummary;
24
+ /** Adds one checked message to the run's summary of what changed. */
25
+ export declare const tallyOutcome: (summary: CheckAgainSummary, before: ThreadRowSpam | undefined, after: RemitImapMessageSpamVerdict) => CheckAgainSummary;
26
+ export interface BatchOutcome {
27
+ summary: CheckAgainSummary;
28
+ failures: CheckAgainFailure[];
29
+ }
30
+ /** Folds one rescan answer into the run: what changed, and what failed why. */
31
+ export declare const applyRescanResult: (outcome: BatchOutcome, batch: RescanBatch, result: RemitImapRescanResult) => BatchOutcome;
32
+ /** A refusal of the whole call, read as the same refusal for every id in it. */
33
+ export declare const refusedBatch: (batch: RescanBatch, code: Extract<RemitImapRescanFailureCode, "NotFound" | "NotPermitted">) => RemitImapRescanResult;
@@ -0,0 +1,66 @@
1
+ import { flaggedVerdict } from "./spam";
2
+ /** The most message ids one rescan call accepts. */
3
+ export const RESCAN_BATCH_SIZE = 10;
4
+ /**
5
+ * The calls a run makes: rescan is per account and takes ten ids, so the
6
+ * selection splits by account first, then into tens, keeping its order.
7
+ */
8
+ export const rescanBatches = (targets) => {
9
+ const byAccount = new Map();
10
+ for (const target of targets) {
11
+ const group = byAccount.get(target.accountId) ?? [];
12
+ group.push(target);
13
+ byAccount.set(target.accountId, group);
14
+ }
15
+ const batches = [];
16
+ for (const [accountId, group] of byAccount) {
17
+ for (let start = 0; start < group.length; start += RESCAN_BATCH_SIZE) {
18
+ batches.push({
19
+ accountId,
20
+ targets: group.slice(start, start + RESCAN_BATCH_SIZE),
21
+ });
22
+ }
23
+ }
24
+ return batches;
25
+ };
26
+ export const EMPTY_SUMMARY = {
27
+ nowSpam: 0,
28
+ nowSuspected: 0,
29
+ noLongerSuspected: 0,
30
+ };
31
+ /** Adds one checked message to the run's summary of what changed. */
32
+ export const tallyOutcome = (summary, before, after) => {
33
+ const now = flaggedVerdict(after)?.action;
34
+ const was = before ? (before.suspected ? "Warn" : "Junk") : undefined;
35
+ if (now === was)
36
+ return summary;
37
+ if (now === "Junk")
38
+ return { ...summary, nowSpam: summary.nowSpam + 1 };
39
+ if (now === "Warn")
40
+ return { ...summary, nowSuspected: summary.nowSuspected + 1 };
41
+ return { ...summary, noLongerSuspected: summary.noLongerSuspected + 1 };
42
+ };
43
+ /** Folds one rescan answer into the run: what changed, and what failed why. */
44
+ export const applyRescanResult = (outcome, batch, result) => {
45
+ const byId = new Map(batch.targets.map((t) => [t.messageId, t]));
46
+ const summary = result.successful.reduce((sum, success) => tallyOutcome(sum, byId.get(success.messageId)?.before, success.verdict), outcome.summary);
47
+ const failures = [
48
+ ...outcome.failures,
49
+ ...result.failed.map((failure) => ({
50
+ messageId: failure.messageId,
51
+ subject: byId.get(failure.messageId)?.subject ?? "(No subject)",
52
+ code: failure.code,
53
+ retryable: failure.retryable,
54
+ })),
55
+ ];
56
+ return { summary, failures };
57
+ };
58
+ /** A refusal of the whole call, read as the same refusal for every id in it. */
59
+ export const refusedBatch = (batch, code) => ({
60
+ successful: [],
61
+ failed: batch.targets.map((target) => ({
62
+ messageId: target.messageId,
63
+ code,
64
+ retryable: false,
65
+ })),
66
+ });
@@ -1,5 +1,6 @@
1
1
  /**
2
- * What the Flagged view asks `listAllThreads` for, and what is left over.
2
+ * What a collection view — Starred or a label — asks `listAllThreads` for, and
3
+ * what is left over.
3
4
  *
4
5
  * Every criterion the view offers — the category chip, the Unread and Has
5
6
  * attachment chips, and the `from:` / `subject:` / `category:` / `is:unread` /
@@ -9,8 +10,9 @@
9
10
  * starred collection is paged, so anything below the newest page was invisible
10
11
  * to it (#308, #1128).
11
12
  *
12
- * `starred` is the view rather than a criterion: the request always carries it,
13
- * which is what makes `is:starred` a carried token instead of residue.
13
+ * On Starred, `starred` is the view rather than a criterion: the request always
14
+ * carries it, which is what makes `is:starred` a carried token instead of
15
+ * residue. On a label it is a criterion like any other.
14
16
  *
15
17
  * A chip beats a token where both set the same parameter — a control on screen
16
18
  * beats text in a field — and the overruled token drops to the residue, where
@@ -19,6 +21,16 @@
19
21
  import type { InboxFilterCriteria } from "./inbox-filters.js";
20
22
  import type { SearchToken } from "./search-tokens.js";
21
23
  import { type ThreadSearchTokenParamName, type ThreadSearchTokenParams } from "./thread-search-tokens.js";
24
+ /**
25
+ * A list that spans accounts and folders, as the listing parameter that names
26
+ * it: the starred mail, or one label's folders.
27
+ */
28
+ export type ThreadCollection = {
29
+ starred: true;
30
+ } | {
31
+ labelId: string;
32
+ };
33
+ export declare const STARRED: ThreadCollection;
22
34
  /**
23
35
  * The token parameters `listAllThreads` carries, which is every parameter it
24
36
  * takes. `from` and `subject` joined them once the operation grew a parameter
@@ -26,11 +38,11 @@ import { type ThreadSearchTokenParamName, type ThreadSearchTokenParams } from ".
26
38
  * token could be asked for on its own and both were applied over the pages
27
39
  * already fetched — a match below them never appeared (#1128).
28
40
  */
29
- export declare const FLAGGED_TOKEN_PARAMS: readonly ThreadSearchTokenParamName[];
30
- export interface FlaggedCriteria {
41
+ export declare const COLLECTION_TOKEN_PARAMS: readonly ThreadSearchTokenParamName[];
42
+ export interface CollectionRequest {
31
43
  /** What the request narrows by, chips and carried tokens together. */
32
44
  criteria: ThreadSearchTokenParams;
33
45
  /** The tokens no parameter carries; apply these over the returned rows. */
34
46
  residual: SearchToken[];
35
47
  }
36
- export declare const flaggedCriteria: (chips: InboxFilterCriteria, tokens: readonly SearchToken[]) => FlaggedCriteria;
48
+ export declare const collectionCriteria: (collection: ThreadCollection, chips: InboxFilterCriteria, tokens: readonly SearchToken[]) => CollectionRequest;
@@ -1,5 +1,6 @@
1
1
  import { inboxFilterParams } from "./inbox-filters.js";
2
2
  import { threadSearchTokens, } from "./thread-search-tokens.js";
3
+ export const STARRED = { starred: true };
3
4
  /**
4
5
  * The token parameters `listAllThreads` carries, which is every parameter it
5
6
  * takes. `from` and `subject` joined them once the operation grew a parameter
@@ -7,7 +8,7 @@ import { threadSearchTokens, } from "./thread-search-tokens.js";
7
8
  * token could be asked for on its own and both were applied over the pages
8
9
  * already fetched — a match below them never appeared (#1128).
9
10
  */
10
- export const FLAGGED_TOKEN_PARAMS = [
11
+ export const COLLECTION_TOKEN_PARAMS = [
11
12
  "from",
12
13
  "subject",
13
14
  "category",
@@ -15,8 +16,8 @@ export const FLAGGED_TOKEN_PARAMS = [
15
16
  "starred",
16
17
  "attachments",
17
18
  ];
18
- export const flaggedCriteria = (chips, tokens) => {
19
+ export const collectionCriteria = (collection, chips, tokens) => {
19
20
  const chipParams = inboxFilterParams(chips);
20
- const { params, residual } = threadSearchTokens(tokens, { ...chipParams, starred: true }, FLAGGED_TOKEN_PARAMS);
21
+ const { params, residual } = threadSearchTokens(tokens, { ...chipParams, ...collection }, COLLECTION_TOKEN_PARAMS);
21
22
  return { criteria: { ...params, ...chipParams }, residual };
22
23
  };
@@ -6,11 +6,12 @@
6
6
  * the pane paints a subject before the thread's own messages arrive. A thread no
7
7
  * list holds carries none of it and still opens.
8
8
  */
9
- import type { RemitImapMessageAuthenticity } from "@remit/api-http-client/types.gen.ts";
9
+ import type { RemitImapThreadMessageResponse } from "@remit/api-http-client/types.gen.ts";
10
10
  export interface ConversationTarget {
11
11
  threadId: string;
12
12
  mailboxId: string;
13
13
  subject?: string;
14
14
  messageId?: string;
15
- authenticity?: RemitImapMessageAuthenticity;
15
+ /** The row the reader pointed at, whose spam verdict the banner states. */
16
+ row?: RemitImapThreadMessageResponse;
16
17
  }
@@ -0,0 +1,6 @@
1
+ import type { RemitImapLabelResponse, RemitImapMailboxResponse } from "@remit/api-http-client/types.gen.ts";
2
+ /**
3
+ * An account's folders without the label folders and the `_remit` root above
4
+ * them, which the sidebar lists once per label instead.
5
+ */
6
+ export declare function withoutLabelFolders(mailboxes: readonly RemitImapMailboxResponse[], labels: readonly RemitImapLabelResponse[]): RemitImapMailboxResponse[];
@@ -0,0 +1,10 @@
1
+ const parentPath = ({ fullPath, hierarchyDelimiter, }) => fullPath.split(hierarchyDelimiter).slice(0, -1).join(hierarchyDelimiter);
2
+ /**
3
+ * An account's folders without the label folders and the `_remit` root above
4
+ * them, which the sidebar lists once per label instead.
5
+ */
6
+ export function withoutLabelFolders(mailboxes, labels) {
7
+ const labelIds = new Set(labels.flatMap((label) => label.folders.flatMap((f) => f.state === "Missing" ? [] : [f.mailboxId])));
8
+ const roots = new Set(mailboxes.filter((mb) => labelIds.has(mb.mailboxId)).map(parentPath));
9
+ return mailboxes.filter((mb) => !labelIds.has(mb.mailboxId) && !roots.has(mb.fullPath));
10
+ }
@@ -17,9 +17,10 @@ export declare const MAIL_BRIEF_ROUTE_ID: "/mail/brief";
17
17
  export declare const MAIL_MAILBOX_ROUTE_ID: "/mail/$mailboxId";
18
18
  export declare const MAIL_OUTBOX_ROUTE_ID: "/mail/outbox";
19
19
  export declare const MAIL_FLAGGED_ROUTE_ID: "/mail/flagged";
20
+ export declare const MAIL_LABEL_ROUTE_ID: "/mail/label/$labelId";
20
21
  /**
21
- * The list a location is browsing. A mailbox route carries its id, which is
22
- * absent only in the frame before the router has resolved the param.
22
+ * The list a location is browsing. A mailbox or label route carries its id,
23
+ * which is absent only in the frame before the router has resolved the param.
23
24
  */
24
25
  export type MailListRoute = {
25
26
  list: "brief";
@@ -30,15 +31,19 @@ export type MailListRoute = {
30
31
  } | {
31
32
  list: "mailbox";
32
33
  mailboxId: string | undefined;
34
+ } | {
35
+ list: "label";
36
+ labelId: string | undefined;
33
37
  };
34
38
  /**
35
- * The list a caller is on, flattened to the two values a navigation to it — or
36
- * a decision about it — needs. Both are primitives, so a caller holding them in
37
- * a dependency array settles, and `list` is `undefined` outside the mail shell.
39
+ * The list a caller is on, flattened to the values a navigation to it — or a
40
+ * decision about it — needs. All are primitives, so a caller holding them in a
41
+ * dependency array settles, and `list` is `undefined` outside the mail shell.
38
42
  */
39
43
  export interface BrowsedList {
40
44
  list: MailListRoute["list"] | undefined;
41
45
  mailboxId: string | undefined;
46
+ labelId: string | undefined;
42
47
  }
43
48
  /**
44
49
  * The list layout among the matched routes, or `undefined` outside the mail
@@ -12,6 +12,7 @@ export const MAIL_BRIEF_ROUTE_ID = "/mail/brief";
12
12
  export const MAIL_MAILBOX_ROUTE_ID = "/mail/$mailboxId";
13
13
  export const MAIL_OUTBOX_ROUTE_ID = "/mail/outbox";
14
14
  export const MAIL_FLAGGED_ROUTE_ID = "/mail/flagged";
15
+ export const MAIL_LABEL_ROUTE_ID = "/mail/label/$labelId";
15
16
  /**
16
17
  * The list layout among the matched routes, or `undefined` outside the mail
17
18
  * shell.
@@ -27,6 +28,8 @@ export function mailListRoute(matches) {
27
28
  return { list: "flagged" };
28
29
  if (match.routeId === MAIL_OUTBOX_ROUTE_ID)
29
30
  return { list: "outbox" };
31
+ if (match.routeId === MAIL_LABEL_ROUTE_ID)
32
+ return { list: "label", labelId: match.params?.labelId };
30
33
  if (match.routeId === MAIL_MAILBOX_ROUTE_ID)
31
34
  return { list: "mailbox", mailboxId: match.params?.mailboxId };
32
35
  }
@@ -62,6 +65,8 @@ export function mailViewKey(pathname) {
62
65
  return MAIL_FLAGGED_ROUTE_ID;
63
66
  if (list === "outbox")
64
67
  return MAIL_OUTBOX_ROUTE_ID;
68
+ if (list === "label")
69
+ return `${MAIL_LABEL_ROUTE_ID}:${segments[2] ?? ""}`;
65
70
  return mailboxViewKey(list);
66
71
  }
67
72
  /**
@@ -111,5 +116,8 @@ export function locationIsOnList(pathname, listPath) {
111
116
  */
112
117
  export function locationOpensDetail(pathname) {
113
118
  const segments = pathname.split(/[?#]/)[0].split("/").filter(Boolean);
114
- return segments[0] === "mail" && segments.length > 2;
119
+ if (segments[0] !== "mail")
120
+ return false;
121
+ const listSegments = segments[1] === "label" ? 3 : 2;
122
+ return segments.length > listSegments;
115
123
  }
@@ -21,6 +21,10 @@ export declare const briefSearchSchema: z.ZodObject<{
21
21
  export declare const flaggedSearchSchema: z.ZodObject<{
22
22
  q: z.ZodOptional<z.ZodString>;
23
23
  }, z.core.$strip>;
24
+ /** The same, for `/mail/label/<label>/<thread>/<message>`. */
25
+ export declare const labelSearchSchema: z.ZodObject<{
26
+ q: z.ZodOptional<z.ZodString>;
27
+ }, z.core.$strip>;
24
28
  /**
25
29
  * The outbox's open message is a path segment
26
30
  * (`/mail/outbox/draft/<outboxMessageId>`), so the query carries nothing but
@@ -77,6 +81,9 @@ export declare const mailListSearchSchemas: {
77
81
  readonly "/mail/$mailboxId": z.ZodObject<{
78
82
  q: z.ZodOptional<z.ZodString>;
79
83
  }, z.core.$strip>;
84
+ readonly "/mail/label/$labelId": z.ZodObject<{
85
+ q: z.ZodOptional<z.ZodString>;
86
+ }, z.core.$strip>;
80
87
  };
81
88
  export declare const composeSeedSearch: z.ZodObject<{
82
89
  body: z.ZodOptional<z.ZodString>;
@@ -96,4 +103,8 @@ export declare const replySearchSchemas: {
96
103
  q: z.ZodOptional<z.ZodString>;
97
104
  body: z.ZodOptional<z.ZodString>;
98
105
  }, z.core.$strip>;
106
+ readonly label: z.ZodObject<{
107
+ q: z.ZodOptional<z.ZodString>;
108
+ body: z.ZodOptional<z.ZodString>;
109
+ }, z.core.$strip>;
99
110
  };
@@ -20,6 +20,8 @@ const listSearch = z.object({ q: z.string().optional() });
20
20
  export const briefSearchSchema = listSearch.extend({});
21
21
  /** The same, for `/mail/flagged/<thread>/<message>`. */
22
22
  export const flaggedSearchSchema = listSearch.extend({});
23
+ /** The same, for `/mail/label/<label>/<thread>/<message>`. */
24
+ export const labelSearchSchema = listSearch.extend({});
23
25
  /**
24
26
  * The outbox's open message is a path segment
25
27
  * (`/mail/outbox/draft/<outboxMessageId>`), so the query carries nothing but
@@ -53,6 +55,7 @@ export const mailListSearchSchemas = {
53
55
  "/mail/flagged": flaggedSearchSchema,
54
56
  "/mail/outbox": outboxSearchSchema,
55
57
  "/mail/$mailboxId": mailboxSearchSchema,
58
+ "/mail/label/$labelId": labelSearchSchema,
56
59
  };
57
60
  export const composeSeedSearch = z.object({ body: z.string().optional() });
58
61
  export const withoutComposeSeed = (prev) => {
@@ -63,4 +66,5 @@ export const replySearchSchemas = {
63
66
  brief: briefSearchSchema.extend(composeSeedSearch.shape),
64
67
  flagged: flaggedSearchSchema.extend(composeSeedSearch.shape),
65
68
  mailbox: mailboxSearchSchema.extend(composeSeedSearch.shape),
69
+ label: labelSearchSchema.extend(composeSeedSearch.shape),
66
70
  };
@@ -68,8 +68,8 @@ export declare function routeMailboxId(browsed: BrowsedList): string | undefined
68
68
  /**
69
69
  * The scope of the active route.
70
70
  *
71
- * `mailboxName` is the sidebar's own label for the mailbox route (resolved by
72
- * `useCurrentMailboxName`). Until it resolves the scope is `pending`: no chip,
71
+ * `mailboxName` is the sidebar's own name for the mailbox or label route
72
+ * (resolved by `useCurrentMailboxName`). Until it resolves the scope is `pending`: no chip,
73
73
  * because a chip reading a raw uuid is worse than none, but not `global`
74
74
  * either, because the list underneath is already narrowed.
75
75
  */