@remit/web-client 0.0.347 → 0.0.349
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 +11 -6
- package/dist/src/components/mail/IntelligencePane.d.ts +2 -2
- package/dist/src/components/mail/IntelligencePane.js +33 -4
- package/dist/src/components/mail/MailSidebarAdapter.js +17 -6
- 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/result-folder.js +7 -0
- 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
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { classificationStatsOperationsGetClassificationStatsOptions, configOperationsGetConfigOptions, userSettingsOperationsGetUserSettingsOptions, } from "@remit/api-http-client/@tanstack/react-query.gen.ts";
|
|
3
|
+
import { unifiedThreadOperationsListAllThreads } from "@remit/api-http-client/sdk.gen.ts";
|
|
4
|
+
import { buttonClassName, cn, FailureBanner, formatErrorMessage, formatSpamScore, LabelChip, SegmentedControl, SpamDailyChart, topSpamReasonSentence, } from "@remit/ui";
|
|
5
|
+
import { useQuery } from "@tanstack/react-query";
|
|
6
|
+
import { useId, useState } from "react";
|
|
7
|
+
import { useSaveClassification } from "../../../hooks/useClassificationSettings";
|
|
8
|
+
import { useJunkMailboxIds } from "../../../hooks/useJunkMailboxIds";
|
|
9
|
+
import { useLabelList } from "../../../hooks/useLabels";
|
|
10
|
+
import { isUnauthenticated, softErrorStatuses, } from "../../../lib/error-classifier";
|
|
11
|
+
import { formatEmailDate } from "../../../lib/format";
|
|
12
|
+
import { flaggedVerdict, remitSpamLabel, spamReportHref, } from "../../../lib/spam";
|
|
13
|
+
import { buildSpamOverview, overviewDays, spamOverviewSince, } from "../../../lib/spam-overview";
|
|
14
|
+
import { NavLink } from "../../../routing";
|
|
15
|
+
const SECTION_TITLE = "text-xs font-semibold uppercase tracking-wider text-fg-subtle";
|
|
16
|
+
const sectionMeta = softErrorStatuses(400, 403, 404);
|
|
17
|
+
const LATEST_COUNT = 10;
|
|
18
|
+
function Section({ title, children, aside, }) {
|
|
19
|
+
const id = useId();
|
|
20
|
+
return (_jsxs("section", { "aria-labelledby": id, className: "space-y-3", children: [_jsxs("div", { className: "flex flex-wrap items-baseline justify-between gap-2", children: [_jsx("h2", { id: id, className: SECTION_TITLE, children: title }), aside] }), children] }));
|
|
21
|
+
}
|
|
22
|
+
function Skeleton({ className }) {
|
|
23
|
+
return (_jsx("div", { "aria-hidden": "true", className: cn("animate-pulse rounded-md bg-surface-sunken", className) }));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A section's load failure. An expired session raises the signed-out notice
|
|
27
|
+
* over the page, so the section stays a skeleton behind it rather than reading
|
|
28
|
+
* as empty.
|
|
29
|
+
*/
|
|
30
|
+
function SectionFailure({ title, error, onRetry, skeleton, }) {
|
|
31
|
+
if (isUnauthenticated(error))
|
|
32
|
+
return skeleton;
|
|
33
|
+
const message = formatErrorMessage(error);
|
|
34
|
+
return (_jsx(FailureBanner, { title: title, message: message, reportHref: spamReportHref(title, message), onRetry: onRetry }));
|
|
35
|
+
}
|
|
36
|
+
function OverviewSection() {
|
|
37
|
+
const [now] = useState(() => new Date());
|
|
38
|
+
const stats = useQuery({
|
|
39
|
+
...classificationStatsOperationsGetClassificationStatsOptions({
|
|
40
|
+
query: { since: spamOverviewSince(now) },
|
|
41
|
+
}),
|
|
42
|
+
meta: sectionMeta,
|
|
43
|
+
});
|
|
44
|
+
const skeleton = (_jsxs(_Fragment, { children: [_jsx(Skeleton, { className: "h-4 w-64" }), _jsxs("div", { className: "grid gap-6 sm:grid-cols-2", children: [_jsx(Skeleton, { className: "h-32" }), _jsx(Skeleton, { className: "h-32" })] })] }));
|
|
45
|
+
if (stats.isPending)
|
|
46
|
+
return _jsx(Section, { title: "Last 30 days", children: skeleton });
|
|
47
|
+
if (stats.isError) {
|
|
48
|
+
return (_jsx(Section, { title: "Last 30 days", children: _jsx(SectionFailure, { title: "Couldn't count the last 30 days", error: stats.error, onRetry: () => void stats.refetch(), skeleton: skeleton }) }));
|
|
49
|
+
}
|
|
50
|
+
const overview = buildSpamOverview(stats.data, overviewDays(now));
|
|
51
|
+
if (!overview.checkedAny) {
|
|
52
|
+
return (_jsx(Section, { title: "Last 30 days", children: _jsxs("div", { className: "rounded-md border border-line px-4 py-6 text-center", children: [_jsx("p", { className: "font-medium text-fg", children: "Remit has not checked any mail yet" }), _jsx("p", { className: "mt-1 text-sm text-fg-muted", children: "Counts appear here once new mail arrives." })] }) }));
|
|
53
|
+
}
|
|
54
|
+
return (_jsxs(Section, { title: "Last 30 days", children: [_jsx("p", { className: "text-sm text-fg tabular-nums", children: `Reached Spam ${overview.moved} · Warned ${overview.warned}` }), _jsxs("div", { className: "grid gap-6 sm:grid-cols-2", children: [_jsx(SpamDailyChart, { title: "Spam", tone: "warning", days: overview.spam }), _jsx(SpamDailyChart, { title: "Phishing", tone: "danger", days: overview.phishing })] }), _jsxs("ul", { className: "flex list-none flex-wrap gap-x-4 gap-y-1 text-2xs text-fg-muted", children: [_jsxs("li", { className: "flex items-center gap-1.5", children: [_jsx("span", { className: "size-2 rounded-sm bg-fg-muted", "aria-hidden": "true" }), "Reached the Move to Spam threshold"] }), _jsxs("li", { className: "flex items-center gap-1.5", children: [_jsx("span", { className: "size-2 rounded-sm bg-fg-muted/35", "aria-hidden": "true" }), "Warned"] })] })] }));
|
|
55
|
+
}
|
|
56
|
+
const latestOf = async (labelId) => {
|
|
57
|
+
const { data } = await unifiedThreadOperationsListAllThreads({
|
|
58
|
+
query: { labelId, order: "desc", limit: LATEST_COUNT },
|
|
59
|
+
throwOnError: true,
|
|
60
|
+
});
|
|
61
|
+
return data.items ?? [];
|
|
62
|
+
};
|
|
63
|
+
function LatestSection() {
|
|
64
|
+
const junkMailboxIds = useJunkMailboxIds();
|
|
65
|
+
const config = useQuery({
|
|
66
|
+
...configOperationsGetConfigOptions(),
|
|
67
|
+
staleTime: Infinity,
|
|
68
|
+
});
|
|
69
|
+
const labelList = useLabelList(config.data?.accounts[0]?.accountId);
|
|
70
|
+
const spamLabel = labelList.labels.find((label) => label.name === "Spam");
|
|
71
|
+
const phishingLabel = labelList.labels.find((label) => label.name === "Phishing");
|
|
72
|
+
const labelIds = [spamLabel, phishingLabel].flatMap((label) => label ? [label.labelId] : []);
|
|
73
|
+
const latest = useQuery({
|
|
74
|
+
queryKey: ["spam-settings", "latest-flagged", ...labelIds],
|
|
75
|
+
queryFn: async () => (await Promise.all(labelIds.map(latestOf)))
|
|
76
|
+
.flat()
|
|
77
|
+
.filter((row) => !row.spamCleared && remitSpamLabel(row.labels) !== undefined)
|
|
78
|
+
.sort((a, b) => b.sentDate - a.sentDate)
|
|
79
|
+
.slice(0, LATEST_COUNT),
|
|
80
|
+
enabled: labelList.isSuccess,
|
|
81
|
+
meta: sectionMeta,
|
|
82
|
+
});
|
|
83
|
+
const skeleton = (_jsx("div", { className: "space-y-2", children: ["a", "b", "c", "d"].map((key) => (_jsx(Skeleton, { className: "h-10" }, key))) }));
|
|
84
|
+
const failure = config.isError
|
|
85
|
+
? { error: config.error, retry: () => void config.refetch() }
|
|
86
|
+
: labelList.isError
|
|
87
|
+
? { error: labelList.error, retry: () => void labelList.refetch() }
|
|
88
|
+
: latest.isError
|
|
89
|
+
? { error: latest.error, retry: () => void latest.refetch() }
|
|
90
|
+
: undefined;
|
|
91
|
+
if (failure) {
|
|
92
|
+
return (_jsx(Section, { title: "Latest flagged", children: _jsx(SectionFailure, { title: "Couldn't load the latest flagged mail", error: failure.error, onRetry: failure.retry, skeleton: skeleton }) }));
|
|
93
|
+
}
|
|
94
|
+
if (!latest.isSuccess) {
|
|
95
|
+
return _jsx(Section, { title: "Latest flagged", children: skeleton });
|
|
96
|
+
}
|
|
97
|
+
if (latest.data.length === 0) {
|
|
98
|
+
return (_jsx(Section, { title: "Latest flagged", children: _jsx("p", { className: "text-sm text-fg-muted", children: "Nothing flagged yet." }) }));
|
|
99
|
+
}
|
|
100
|
+
return (_jsx(Section, { title: "Latest flagged", aside: _jsxs("span", { className: "flex gap-4 text-sm", children: [spamLabel && (_jsx(NavLink, { to: "/mail/label/$labelId", params: { labelId: spamLabel.labelId }, variant: "inline", children: "Review all in Spam" })), phishingLabel && (_jsx(NavLink, { to: "/mail/label/$labelId", params: { labelId: phishingLabel.labelId }, variant: "inline", children: "Open Phishing" }))] }), children: _jsx("div", { className: "overflow-x-auto rounded-md border border-line", children: _jsxs("table", { className: "w-full text-left text-sm", children: [_jsx("thead", { className: "border-b border-line text-2xs uppercase tracking-wide text-fg-subtle", children: _jsxs("tr", { children: [_jsx("th", { className: "px-3 py-2 font-medium", children: "Sender" }), _jsx("th", { className: "px-3 py-2 font-medium", children: "Subject and top reason" }), _jsx("th", { className: "px-3 py-2 font-medium", children: "Date" }), _jsx("th", { className: "px-3 py-2 font-medium", children: "Label" }), _jsx("th", { className: "px-3 py-2 font-medium", children: "Action" })] }) }), _jsx("tbody", { className: "divide-y divide-line", children: latest.data.map((row) => {
|
|
101
|
+
const label = remitSpamLabel(row.labels);
|
|
102
|
+
if (!label)
|
|
103
|
+
return null;
|
|
104
|
+
const verdict = flaggedVerdict(row.spamVerdict);
|
|
105
|
+
return (_jsxs("tr", { className: "hover:bg-surface-sunken", children: [_jsx("td", { className: "px-3 py-2 align-top text-fg", children: row.fromName ?? row.fromEmail ?? "Unknown" }), _jsxs("td", { className: "px-3 py-2 align-top", children: [_jsx(NavLink, { to: "/mail/label/$labelId/$threadId/$messageId", params: {
|
|
106
|
+
labelId: label.labelId,
|
|
107
|
+
threadId: row.threadId,
|
|
108
|
+
messageId: row.messageId,
|
|
109
|
+
}, variant: "inline", className: "text-fg", children: row.subject ?? "(No subject)" }), verdict && (_jsx("p", { className: "text-xs text-fg-muted", children: topSpamReasonSentence(verdict.reasons) }))] }), _jsx("td", { className: "whitespace-nowrap px-3 py-2 align-top text-fg-muted tabular-nums", children: formatEmailDate(row.sentDate) }), _jsx("td", { className: "px-3 py-2 align-top", children: _jsx(LabelChip, { label: label }) }), _jsx("td", { className: "px-3 py-2 align-top text-fg-muted", children: junkMailboxIds.has(row.mailboxId) ? "Moved" : "Warned" })] }, row.messageId));
|
|
110
|
+
}) })] }) }) }));
|
|
111
|
+
}
|
|
112
|
+
function ThresholdsSection({ spam }) {
|
|
113
|
+
const { thresholds } = spam;
|
|
114
|
+
return (_jsxs(Section, { title: "Thresholds", children: [thresholds.state === "Set" ? (_jsxs("dl", { className: "flex flex-wrap gap-x-8 gap-y-2 text-sm", children: [_jsxs("div", { children: [_jsx("dt", { className: "text-fg-muted", children: "Warn from" }), _jsx("dd", { className: "font-medium text-fg tabular-nums", children: formatSpamScore(thresholds.cleanBelow) })] }), _jsxs("div", { children: [_jsx("dt", { className: "text-fg-muted", children: "Move to Spam from" }), _jsx("dd", { className: "font-medium text-fg tabular-nums", children: formatSpamScore(thresholds.spamAt) })] })] })) : (_jsx("p", { className: "text-sm text-fg", children: "The spam service applies its own thresholds." })), _jsx("p", { className: "text-xs text-fg-muted", children: "Scores run from 0 to 1. The deployment sets these values, and they apply to mail arriving from now on. Check again in any list updates older mail." })] }));
|
|
115
|
+
}
|
|
116
|
+
const PLACEMENT_OPTIONS = [
|
|
117
|
+
{ value: "WarnOnly", label: "Warn only" },
|
|
118
|
+
{ value: "MoveToSpam", label: "Move to Spam" },
|
|
119
|
+
];
|
|
120
|
+
function PlacementSection({ spam }) {
|
|
121
|
+
const save = useSaveClassification();
|
|
122
|
+
const [announcement, setAnnouncement] = useState("");
|
|
123
|
+
const ids = useId();
|
|
124
|
+
const rows = [
|
|
125
|
+
{
|
|
126
|
+
field: "spamPlacementSpam",
|
|
127
|
+
label: "Spam",
|
|
128
|
+
value: spam.spamPlacement,
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
field: "spamPlacementPhishing",
|
|
132
|
+
label: "Phishing",
|
|
133
|
+
value: spam.phishingPlacement,
|
|
134
|
+
},
|
|
135
|
+
];
|
|
136
|
+
return (_jsxs(Section, { title: "Per label", children: [_jsx("div", { className: "space-y-2", children: rows.map((row) => (_jsxs("div", { className: "flex items-center gap-4", children: [_jsx("span", { className: "w-20 text-sm text-fg", children: row.label }), _jsx(SegmentedControl, { name: `${ids}-${row.field}`, "aria-label": `${row.label} label`, size: "sm", options: PLACEMENT_OPTIONS, value: row.value, onChange: (placement) => {
|
|
137
|
+
setAnnouncement("");
|
|
138
|
+
save.mutate({ body: { [row.field]: placement } }, { onSuccess: () => setAnnouncement("Saved") });
|
|
139
|
+
} })] }, row.field))) }), _jsx("p", { className: "text-xs text-fg-muted", children: "Warn only keeps the message where it arrived, under the warning banner." }), save.isError && (_jsx(FailureBanner, { title: "The label setting was not saved", message: formatErrorMessage(save.error), reportHref: spamReportHref("The label setting was not saved", formatErrorMessage(save.error)), onRetry: () => save.variables && save.mutate(save.variables) })), _jsx("p", { "aria-live": "polite", className: "text-xs text-positive", children: announcement })] }));
|
|
140
|
+
}
|
|
141
|
+
function SettingsSections() {
|
|
142
|
+
const settings = useQuery({
|
|
143
|
+
...userSettingsOperationsGetUserSettingsOptions(),
|
|
144
|
+
meta: sectionMeta,
|
|
145
|
+
});
|
|
146
|
+
const skeleton = (_jsxs(_Fragment, { children: [_jsx(Section, { title: "Thresholds", children: _jsx(Skeleton, { className: "h-11 w-64" }) }), _jsxs(Section, { title: "Per label", children: [_jsx(Skeleton, { className: "h-9 w-48" }), _jsx(Skeleton, { className: "h-9 w-48" })] })] }));
|
|
147
|
+
if (settings.isPending)
|
|
148
|
+
return skeleton;
|
|
149
|
+
if (settings.isError) {
|
|
150
|
+
return (_jsx(Section, { title: "Thresholds", children: _jsx(SectionFailure, { title: "Couldn't load the spam settings", error: settings.error, onRetry: () => void settings.refetch(), skeleton: skeleton }) }));
|
|
151
|
+
}
|
|
152
|
+
return (_jsxs(_Fragment, { children: [_jsx(ThresholdsSection, { spam: settings.data.spam }), _jsx(PlacementSection, { spam: settings.data.spam })] }));
|
|
153
|
+
}
|
|
154
|
+
function SendersSection() {
|
|
155
|
+
const groups = [
|
|
156
|
+
{
|
|
157
|
+
title: "Never in Spam",
|
|
158
|
+
hint: "Their mail skips the spam check.",
|
|
159
|
+
group: "neverSpam",
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
title: "Reported",
|
|
163
|
+
hint: "Their mail goes straight to Spam.",
|
|
164
|
+
group: "blocked",
|
|
165
|
+
},
|
|
166
|
+
];
|
|
167
|
+
return (_jsx(Section, { title: "Senders", children: _jsx("ul", { className: "list-none divide-y divide-line rounded-md border border-line", children: groups.map((group) => (_jsxs("li", { className: "flex items-center justify-between gap-3 px-3 py-2", children: [_jsxs("div", { children: [_jsx("p", { className: "text-sm font-medium text-fg", children: group.title }), _jsx("p", { className: "text-xs text-fg-muted", children: group.hint })] }), _jsx(NavLink, { to: "/settings/senders", search: { group: group.group }, variant: "inline", className: cn(buttonClassName({ variant: "secondary" }), "min-h-11 hover:no-underline"), "aria-label": `Manage ${group.title}`, children: "Manage" })] }, group.title))) }) }));
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* The Spam & phishing settings at `/settings/spam`: what Remit flagged in the
|
|
171
|
+
* last 30 days, the thresholds in effect, the per-label action and the sender
|
|
172
|
+
* groups. Every section loads and fails on its own.
|
|
173
|
+
*/
|
|
174
|
+
export function SpamSettingsPanel() {
|
|
175
|
+
return (_jsxs("div", { className: "max-w-3xl space-y-8", children: [_jsx(OverviewSection, {}), _jsx(LatestSection, {}), _jsx(SettingsSections, {}), _jsx(SendersSection, {})] }));
|
|
176
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RemitImapAddressResponse, RemitImapThreadMessageResponse } from "@remit/api-http-client/types.gen.ts";
|
|
2
|
-
import type {
|
|
2
|
+
import type { IntelligenceData, PlacementIntel, SenderIntel } from "@remit/ui";
|
|
3
3
|
/**
|
|
4
4
|
* A sender address we cannot read: empty, missing the `@`, or whose domain
|
|
5
5
|
* part carries no dot (catches placeholders like `missing_domain` and other
|
|
@@ -25,8 +25,6 @@ export declare function buildCategoryIntel(thread: RemitImapThreadMessageRespons
|
|
|
25
25
|
* than rendering a misleading "0 received" next to an earned trust badge.
|
|
26
26
|
*/
|
|
27
27
|
export declare function buildSenderIntel(thread: RemitImapThreadMessageResponse, address: RemitImapAddressResponse | undefined): SenderIntel;
|
|
28
|
-
/** Build authenticity intel from the thread message's authenticity field. */
|
|
29
|
-
export declare function buildAuthenticityIntel(thread: RemitImapThreadMessageResponse): AuthenticityIntel;
|
|
30
28
|
export declare function buildPlacementIntel(thread: RemitImapThreadMessageResponse): PlacementIntel | undefined;
|
|
31
29
|
export interface UseIntelligenceDataResult {
|
|
32
30
|
data: Omit<IntelligenceData, "spamAction"> | null;
|
|
@@ -52,7 +50,7 @@ export interface UseIntelligenceDataResult {
|
|
|
52
50
|
* Maps a `RemitImapThreadMessageResponse` into `IntelligenceData` for the
|
|
53
51
|
* `IntelligencePanel` component. Two data sources:
|
|
54
52
|
*
|
|
55
|
-
* 1. The thread row itself (already loaded) → sender basics, trust,
|
|
53
|
+
* 1. The thread row itself (already loaded) → sender basics, trust, category.
|
|
56
54
|
* 2. `GET /addresses/search?q=<email>` → address flags (VIP/muted/blocked/etc.)
|
|
57
55
|
* and first-seen timestamp. One round-trip per unique sender.
|
|
58
56
|
*/
|
|
@@ -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
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { provenanceFolderLabel } from "@remit/ui";
|
|
2
2
|
import { buildMailboxRoleMap } from "./folder-roles.js";
|
|
3
3
|
export const EMPTY_RESULT_FOLDER_INDEX = new Map();
|
|
4
|
+
function isLabelFolderPath({ fullPath, hierarchyDelimiter, }) {
|
|
5
|
+
return fullPath
|
|
6
|
+
.split(hierarchyDelimiter)
|
|
7
|
+
.some((segment) => segment.endsWith("_remit"));
|
|
8
|
+
}
|
|
4
9
|
/**
|
|
5
10
|
* The appointments and the mailbox list arrive from two different queries, so
|
|
6
11
|
* the roles are seeded first and the provider paths laid over them. A role on
|
|
@@ -14,6 +19,8 @@ export function buildResultFolderIndex(accounts) {
|
|
|
14
19
|
for (const [mailboxId, role] of roles)
|
|
15
20
|
index.set(mailboxId, { role });
|
|
16
21
|
for (const mailbox of account.mailboxes) {
|
|
22
|
+
if (isLabelFolderPath(mailbox))
|
|
23
|
+
continue;
|
|
17
24
|
const role = roles.get(mailbox.mailboxId);
|
|
18
25
|
const path = {
|
|
19
26
|
providerPath: mailbox.fullPath,
|
|
@@ -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
|
+
};
|