@remit/web-client 0.0.347 → 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.
- package/dist/src/components/mail/BriefPane.js +3 -3
- package/dist/src/components/mail/CheckAgainProvider.d.ts +30 -0
- package/dist/src/components/mail/CheckAgainProvider.js +194 -0
- package/dist/src/components/mail/CollectionList.js +4 -2
- package/dist/src/components/mail/CollectionPane.js +3 -3
- package/dist/src/components/mail/ConversationView.d.ts +7 -8
- package/dist/src/components/mail/ConversationView.js +4 -4
- package/dist/src/components/mail/DailyBrief.js +6 -4
- package/dist/src/components/mail/IntelligencePane.d.ts +2 -2
- package/dist/src/components/mail/IntelligencePane.js +33 -4
- package/dist/src/components/mail/MailboxPane.js +10 -12
- package/dist/src/components/mail/MessageActionMenu.d.ts +3 -1
- package/dist/src/components/mail/MessageActionMenu.js +3 -3
- package/dist/src/components/mail/MessageCard.js +9 -1
- package/dist/src/components/mail/MessageList.js +11 -2
- package/dist/src/components/mail/MessageListItem.d.ts +4 -2
- package/dist/src/components/mail/MessageListItem.js +4 -6
- package/dist/src/components/mail/SpamBannerSlot.d.ts +10 -0
- package/dist/src/components/mail/SpamBannerSlot.js +56 -0
- package/dist/src/components/mail/SwipeableMessageRow.d.ts +3 -2
- package/dist/src/components/mail/SwipeableMessageRow.js +6 -6
- package/dist/src/components/mail/ThreadListInteraction.d.ts +2 -0
- package/dist/src/components/mail/ThreadListInteraction.js +12 -2
- package/dist/src/components/settings/classification/FailureBanner.js +3 -4
- package/dist/src/components/settings/spam/SpamSettingsPanel.d.ts +6 -0
- package/dist/src/components/settings/spam/SpamSettingsPanel.js +176 -0
- package/dist/src/hooks/useIntelligenceData.d.ts +2 -4
- package/dist/src/hooks/useIntelligenceData.js +1 -127
- package/dist/src/hooks/useJunkMailboxIds.d.ts +2 -0
- package/dist/src/hooks/useJunkMailboxIds.js +17 -0
- package/dist/src/lib/brief.d.ts +1 -1
- package/dist/src/lib/brief.js +3 -3
- package/dist/src/lib/check-again.d.ts +33 -0
- package/dist/src/lib/check-again.js +66 -0
- package/dist/src/lib/conversation-target.d.ts +3 -2
- package/dist/src/lib/spam-overview.d.ts +23 -0
- package/dist/src/lib/spam-overview.js +44 -0
- package/dist/src/lib/spam.d.ts +32 -0
- package/dist/src/lib/spam.js +38 -0
- package/dist/src/lib/thread-search-tokens.js +3 -1
- package/dist/src/routeTree.gen.d.ts +27 -5
- package/dist/src/routeTree.gen.js +7 -0
- package/dist/src/routes/__root.js +2 -1
- package/dist/src/routes/settings/filters.d.ts +6 -2
- package/dist/src/routes/settings/filters.js +10 -3
- package/dist/src/routes/settings/senders.d.ts +14 -2
- package/dist/src/routes/settings/senders.js +32 -15
- package/dist/src/routes/settings/spam.d.ts +1 -0
- package/dist/src/routes/settings/spam.js +15 -0
- package/dist/src/routes/settings.js +6 -1
- package/dist/src/routing/spam-link.d.ts +3 -0
- package/dist/src/routing/spam-link.js +12 -0
- package/package.json +2 -2
- package/dist/src/components/mail/AuthenticityBanner.d.ts +0 -14
- package/dist/src/components/mail/AuthenticityBanner.js +0 -18
|
@@ -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,
|
|
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,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
|
+
};
|
package/dist/src/lib/brief.d.ts
CHANGED
|
@@ -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;
|
package/dist/src/lib/brief.js
CHANGED
|
@@ -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
|
-
|
|
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
|
+
});
|
|
@@ -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 {
|
|
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
|
-
|
|
15
|
+
/** The row the reader pointed at, whose spam verdict the banner states. */
|
|
16
|
+
row?: RemitImapThreadMessageResponse;
|
|
16
17
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { RemitImapClassifierStats } from "@remit/api-http-client/types.gen.ts";
|
|
2
|
+
import type { SpamDay } from "@remit/ui";
|
|
3
|
+
export declare const SPAM_OVERVIEW_DAYS = 30;
|
|
4
|
+
/**
|
|
5
|
+
* Local midnight `days - 1` days before `now`, as an ISO 8601 date-time with
|
|
6
|
+
* the reader's zone offset: the stats bucket arrival days in the zone of
|
|
7
|
+
* `since`, so the chart's days are the reader's days.
|
|
8
|
+
*/
|
|
9
|
+
export declare const spamOverviewSince: (now: Date, days?: number) => string;
|
|
10
|
+
/** Every day of the window, oldest first, as the stats name them. */
|
|
11
|
+
export declare const overviewDays: (now: Date, days?: number) => string[];
|
|
12
|
+
export interface SpamOverview {
|
|
13
|
+
checkedAny: boolean;
|
|
14
|
+
moved: number;
|
|
15
|
+
warned: number;
|
|
16
|
+
spam: SpamDay[];
|
|
17
|
+
phishing: SpamDay[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* One bar per day for each kind. A day the stats leave out had no verdicts,
|
|
21
|
+
* so it draws as an empty bar rather than closing the gap.
|
|
22
|
+
*/
|
|
23
|
+
export declare const buildSpamOverview: (stats: Pick<RemitImapClassifierStats, "spamByDay" | "spamScoreBands">, days: readonly string[]) => SpamOverview;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export const SPAM_OVERVIEW_DAYS = 30;
|
|
2
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
3
|
+
const localDay = (date) => `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
4
|
+
const zoneOffset = (date) => {
|
|
5
|
+
const minutes = -date.getTimezoneOffset();
|
|
6
|
+
const sign = minutes >= 0 ? "+" : "-";
|
|
7
|
+
const abs = Math.abs(minutes);
|
|
8
|
+
return `${sign}${pad(Math.floor(abs / 60))}:${pad(abs % 60)}`;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Local midnight `days - 1` days before `now`, as an ISO 8601 date-time with
|
|
12
|
+
* the reader's zone offset: the stats bucket arrival days in the zone of
|
|
13
|
+
* `since`, so the chart's days are the reader's days.
|
|
14
|
+
*/
|
|
15
|
+
export const spamOverviewSince = (now, days = SPAM_OVERVIEW_DAYS) => {
|
|
16
|
+
const start = new Date(now.getFullYear(), now.getMonth(), now.getDate() - (days - 1));
|
|
17
|
+
return `${localDay(start)}T00:00:00${zoneOffset(start)}`;
|
|
18
|
+
};
|
|
19
|
+
/** Every day of the window, oldest first, as the stats name them. */
|
|
20
|
+
export const overviewDays = (now, days = SPAM_OVERVIEW_DAYS) => Array.from({ length: days }, (_, i) => localDay(new Date(now.getFullYear(), now.getMonth(), now.getDate() - (days - 1 - i))));
|
|
21
|
+
/**
|
|
22
|
+
* One bar per day for each kind. A day the stats leave out had no verdicts,
|
|
23
|
+
* so it draws as an empty bar rather than closing the gap.
|
|
24
|
+
*/
|
|
25
|
+
export const buildSpamOverview = (stats, days) => {
|
|
26
|
+
const daysOf = (kind) => days.map((date) => {
|
|
27
|
+
const count = (action) => stats.spamByDay
|
|
28
|
+
.filter((entry) => entry.date === date &&
|
|
29
|
+
entry.kind === kind &&
|
|
30
|
+
entry.action === action)
|
|
31
|
+
.reduce((sum, entry) => sum + entry.count, 0);
|
|
32
|
+
return { date, moved: count("Junk"), warned: count("Warn") };
|
|
33
|
+
});
|
|
34
|
+
const spam = daysOf("Spam");
|
|
35
|
+
const phishing = daysOf("Phishing");
|
|
36
|
+
const total = (pick) => [...spam, ...phishing].reduce((sum, day) => sum + pick(day), 0);
|
|
37
|
+
return {
|
|
38
|
+
checkedAny: stats.spamScoreBands.some((band) => band.count > 0),
|
|
39
|
+
moved: total((day) => day.moved),
|
|
40
|
+
warned: total((day) => day.warned),
|
|
41
|
+
spam,
|
|
42
|
+
phishing,
|
|
43
|
+
};
|
|
44
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { RemitImapLabelSummaryResponse, RemitImapMessageSpamVerdict, RemitImapSpamChecked } from "@remit/api-http-client/types.gen.ts";
|
|
2
|
+
import type { ThreadRowSpam } from "@remit/ui";
|
|
3
|
+
/**
|
|
4
|
+
* The Remit Spam or Phishing label the message carries, found by name. The
|
|
5
|
+
* label, not the verdict, says Remit flagged the message: Not spam removes it.
|
|
6
|
+
*/
|
|
7
|
+
export declare const remitSpamLabel: (labels: readonly RemitImapLabelSummaryResponse[] | undefined) => RemitImapLabelSummaryResponse | undefined;
|
|
8
|
+
/** A checked verdict that warned about the message or sent it to Spam. */
|
|
9
|
+
export declare const flaggedVerdict: (verdict: RemitImapMessageSpamVerdict) => (RemitImapSpamChecked & {
|
|
10
|
+
action: "Warn" | "Junk";
|
|
11
|
+
}) | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* The row's one spam mark: the Remit label it carries, suspected while the
|
|
14
|
+
* message sits outside a Spam folder. A message the reader cleared carries none.
|
|
15
|
+
*/
|
|
16
|
+
export declare const spamRowMark: (row: {
|
|
17
|
+
mailboxId: string;
|
|
18
|
+
spamCleared: boolean;
|
|
19
|
+
labels?: RemitImapLabelSummaryResponse[];
|
|
20
|
+
}, junkMailboxIds: ReadonlySet<string>) => ThreadRowSpam | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Whether the message view raises the spam banner and the rail for it: a
|
|
23
|
+
* failed check, or a Remit label on a message outside Spam, unless the reader
|
|
24
|
+
* cleared it with Not spam.
|
|
25
|
+
*/
|
|
26
|
+
export declare const raisesSpamWarning: (row: {
|
|
27
|
+
spamVerdict: RemitImapMessageSpamVerdict;
|
|
28
|
+
spamCleared: boolean;
|
|
29
|
+
labels?: RemitImapLabelSummaryResponse[];
|
|
30
|
+
}, inSpamFolder: boolean) => boolean;
|
|
31
|
+
export declare const spamReportHref: (title: string, detail: string) => string;
|
|
32
|
+
export declare const unknownReasonReportHref: (symbol: string) => string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { buildBugReportContext, buildGitHubIssueUrl } from "./bug-report";
|
|
2
|
+
const SPAM_KINDS = ["Phishing", "Spam"];
|
|
3
|
+
/**
|
|
4
|
+
* The Remit Spam or Phishing label the message carries, found by name. The
|
|
5
|
+
* label, not the verdict, says Remit flagged the message: Not spam removes it.
|
|
6
|
+
*/
|
|
7
|
+
export const remitSpamLabel = (labels) => SPAM_KINDS.flatMap((kind) => labels?.filter((label) => label.name === kind) ?? [])[0];
|
|
8
|
+
/** A checked verdict that warned about the message or sent it to Spam. */
|
|
9
|
+
export const flaggedVerdict = (verdict) => verdict.state === "Checked" && verdict.action !== "None"
|
|
10
|
+
? { ...verdict, action: verdict.action }
|
|
11
|
+
: undefined;
|
|
12
|
+
/**
|
|
13
|
+
* The row's one spam mark: the Remit label it carries, suspected while the
|
|
14
|
+
* message sits outside a Spam folder. A message the reader cleared carries none.
|
|
15
|
+
*/
|
|
16
|
+
export const spamRowMark = (row, junkMailboxIds) => {
|
|
17
|
+
if (row.spamCleared)
|
|
18
|
+
return undefined;
|
|
19
|
+
const label = remitSpamLabel(row.labels);
|
|
20
|
+
if (!label)
|
|
21
|
+
return undefined;
|
|
22
|
+
return { label, suspected: !junkMailboxIds.has(row.mailboxId) };
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Whether the message view raises the spam banner and the rail for it: a
|
|
26
|
+
* failed check, or a Remit label on a message outside Spam, unless the reader
|
|
27
|
+
* cleared it with Not spam.
|
|
28
|
+
*/
|
|
29
|
+
export const raisesSpamWarning = (row, inSpamFolder) => !row.spamCleared &&
|
|
30
|
+
(row.spamVerdict.state === "Failed" ||
|
|
31
|
+
(remitSpamLabel(row.labels) !== undefined &&
|
|
32
|
+
row.spamVerdict.state === "Checked" &&
|
|
33
|
+
!inSpamFolder));
|
|
34
|
+
export const spamReportHref = (title, detail) => buildGitHubIssueUrl(buildBugReportContext({
|
|
35
|
+
title: `Spam check: ${title}`,
|
|
36
|
+
errorMessage: `${title}. ${detail}`,
|
|
37
|
+
}));
|
|
38
|
+
export const unknownReasonReportHref = (symbol) => spamReportHref(`Unknown spam reason ${symbol}`, `The spam check named ${symbol}, which this version has no sentence for.`);
|
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
* nothing — which is the honest answer to a contradiction).
|
|
23
23
|
*/
|
|
24
24
|
import { matchesSearchTokens, toThreadRowData } from "./brief.js";
|
|
25
|
+
/** Search tokens read no spam mark, so the row needs no Spam folders. */
|
|
26
|
+
const NO_SPAM_FOLDERS = new Set();
|
|
25
27
|
/**
|
|
26
28
|
* Every parameter `searchThreads` takes, the default set.
|
|
27
29
|
*
|
|
@@ -110,7 +112,7 @@ export function applyResidualTokens(threads, residual, accountId) {
|
|
|
110
112
|
return threads;
|
|
111
113
|
const tokens = [...residual];
|
|
112
114
|
return threads.filter((thread) => {
|
|
113
|
-
const row = toThreadRowData(thread);
|
|
115
|
+
const row = toThreadRowData(thread, NO_SPAM_FOLDERS);
|
|
114
116
|
return matchesSearchTokens({ ...row, accountId: row.accountId ?? accountId }, tokens);
|
|
115
117
|
});
|
|
116
118
|
}
|