@remit/mailbox-service 0.0.94 → 0.0.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/body-sync.ts
CHANGED
|
@@ -59,7 +59,7 @@ import {
|
|
|
59
59
|
classifyPlacement,
|
|
60
60
|
type FolderPlacement,
|
|
61
61
|
type PlacementVerdict,
|
|
62
|
-
|
|
62
|
+
resolveSenderPlacement,
|
|
63
63
|
} from "./heuristics/classifyPlacement.js";
|
|
64
64
|
import { extractSenderMismatch } from "./heuristics/senderMismatch.js";
|
|
65
65
|
import { denormalizeMessageCategory } from "./message-category.js";
|
|
@@ -1176,7 +1176,7 @@ export class BodySyncService {
|
|
|
1176
1176
|
* `deriveSenderTrust` always did — `vip → wellknown → unknown`, untouched by
|
|
1177
1177
|
* `blocked` — plus `blocked`/`autoArchive` off the same row. `trustSetAt` is
|
|
1178
1178
|
* the `setAt` of whichever flag produced the trust value, needed by
|
|
1179
|
-
* {@link
|
|
1179
|
+
* {@link resolveSenderPlacement}'s tie-break; it stays local to placement and
|
|
1180
1180
|
* never reaches `deriveSenderTrust`'s own contract (the trust badge).
|
|
1181
1181
|
*/
|
|
1182
1182
|
private async deriveSenderPlacementSignals(
|
|
@@ -1187,11 +1187,13 @@ export class BodySyncService {
|
|
|
1187
1187
|
trustSetAt?: number;
|
|
1188
1188
|
blocked: boolean;
|
|
1189
1189
|
blockedSetAt?: number;
|
|
1190
|
+
neverSpam: boolean;
|
|
1190
1191
|
autoArchive: boolean;
|
|
1191
1192
|
}> {
|
|
1192
1193
|
const unknown = {
|
|
1193
1194
|
trust: SenderTrust.Unknown,
|
|
1194
1195
|
blocked: false,
|
|
1196
|
+
neverSpam: false,
|
|
1195
1197
|
autoArchive: false,
|
|
1196
1198
|
} as const;
|
|
1197
1199
|
try {
|
|
@@ -1207,6 +1209,7 @@ export class BodySyncService {
|
|
|
1207
1209
|
trustSetAt: flags.vip.setAt,
|
|
1208
1210
|
blocked: flags.blocked?.value === true,
|
|
1209
1211
|
blockedSetAt: flags.blocked?.setAt,
|
|
1212
|
+
neverSpam: flags.neverSpam?.value === true,
|
|
1210
1213
|
autoArchive: flags.autoArchive?.value === true,
|
|
1211
1214
|
};
|
|
1212
1215
|
}
|
|
@@ -1216,6 +1219,7 @@ export class BodySyncService {
|
|
|
1216
1219
|
trustSetAt: flags.wellknown.setAt,
|
|
1217
1220
|
blocked: flags.blocked?.value === true,
|
|
1218
1221
|
blockedSetAt: flags.blocked?.setAt,
|
|
1222
|
+
neverSpam: flags.neverSpam?.value === true,
|
|
1219
1223
|
autoArchive: flags.autoArchive?.value === true,
|
|
1220
1224
|
};
|
|
1221
1225
|
}
|
|
@@ -1223,6 +1227,7 @@ export class BodySyncService {
|
|
|
1223
1227
|
...unknown,
|
|
1224
1228
|
blocked: flags?.blocked?.value === true,
|
|
1225
1229
|
blockedSetAt: flags?.blocked?.setAt,
|
|
1230
|
+
neverSpam: flags?.neverSpam?.value === true,
|
|
1226
1231
|
autoArchive: flags?.autoArchive?.value === true,
|
|
1227
1232
|
};
|
|
1228
1233
|
} catch (err) {
|
|
@@ -1514,12 +1519,14 @@ export class BodySyncService {
|
|
|
1514
1519
|
: {
|
|
1515
1520
|
trust: SenderTrust.Unknown,
|
|
1516
1521
|
blocked: false,
|
|
1522
|
+
neverSpam: false,
|
|
1517
1523
|
autoArchive: false,
|
|
1518
1524
|
};
|
|
1519
1525
|
|
|
1520
|
-
const { senderTrust,
|
|
1526
|
+
const { senderTrust, senderOverride } = resolveSenderPlacement(
|
|
1521
1527
|
{ trust: signals.trust, setAt: signals.trustSetAt },
|
|
1522
1528
|
{ blocked: signals.blocked, setAt: signals.blockedSetAt },
|
|
1529
|
+
signals.neverSpam,
|
|
1523
1530
|
);
|
|
1524
1531
|
|
|
1525
1532
|
// The verdict needs the classification signals (providerSpam,
|
|
@@ -1530,7 +1537,7 @@ export class BodySyncService {
|
|
|
1530
1537
|
candidate,
|
|
1531
1538
|
placement,
|
|
1532
1539
|
senderTrust,
|
|
1533
|
-
|
|
1540
|
+
senderOverride,
|
|
1534
1541
|
);
|
|
1535
1542
|
|
|
1536
1543
|
// A `leave` verdict — including "nothing confident to say" — carries no
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `classifyPlacement` had no dedicated unit test — only the DKIM/DMARC paths
|
|
3
3
|
* were exercised indirectly through realistic-mail fixtures elsewhere. Issue
|
|
4
|
-
* #300 (RFC 039 Decision 3/3a)
|
|
5
|
-
* independent of every DKIM/DMARC/provider signal, plus a
|
|
6
|
-
* against `vip`/`wellknown` (Decision 3a
|
|
7
|
-
*
|
|
8
|
-
* regression in
|
|
4
|
+
* #300 (RFC 039 Decision 3/3a) added the user's placement instruction as a
|
|
5
|
+
* confident move independent of every DKIM/DMARC/provider signal, plus a
|
|
6
|
+
* `setAt` tie-break against `vip`/`wellknown` (Decision 3a). Issue #605 adds
|
|
7
|
+
* the other direction, `neverSpam`. These tests cover both instruction
|
|
8
|
+
* branches and the pre-existing DKIM/DMARC branches, so a regression in any of
|
|
9
|
+
* them shows up here.
|
|
9
10
|
*/
|
|
10
11
|
|
|
11
12
|
import assert from "node:assert/strict";
|
|
12
13
|
import { describe, it } from "node:test";
|
|
13
14
|
import type { MessageItem } from "@remit/data-ports";
|
|
14
|
-
import { SenderTrust } from "@remit/domain-enums";
|
|
15
|
+
import { SenderOverride, SenderTrust } from "@remit/domain-enums";
|
|
15
16
|
import {
|
|
16
17
|
classifyPlacement,
|
|
17
|
-
|
|
18
|
+
resolveSenderPlacement,
|
|
18
19
|
} from "./classifyPlacement.js";
|
|
19
20
|
|
|
20
21
|
const baseMessage = (overrides: Partial<MessageItem> = {}): MessageItem =>
|
|
@@ -28,7 +29,7 @@ const baseMessage = (overrides: Partial<MessageItem> = {}): MessageItem =>
|
|
|
28
29
|
}) as unknown as MessageItem;
|
|
29
30
|
|
|
30
31
|
describe("classifyPlacement", () => {
|
|
31
|
-
describe("
|
|
32
|
+
describe("SenderOverride.Blocked (RFC 039 Decision 3)", () => {
|
|
32
33
|
it("demotes an inbox message from a blocked sender, independent of DKIM/DMARC", () => {
|
|
33
34
|
const message = baseMessage({
|
|
34
35
|
providerSpam: undefined,
|
|
@@ -38,7 +39,7 @@ describe("classifyPlacement", () => {
|
|
|
38
39
|
message,
|
|
39
40
|
"inbox",
|
|
40
41
|
SenderTrust.Unknown,
|
|
41
|
-
|
|
42
|
+
SenderOverride.Blocked,
|
|
42
43
|
);
|
|
43
44
|
assert.deepEqual(verdict, {
|
|
44
45
|
action: "move-to-junk",
|
|
@@ -52,7 +53,7 @@ describe("classifyPlacement", () => {
|
|
|
52
53
|
baseMessage(),
|
|
53
54
|
"other",
|
|
54
55
|
SenderTrust.Unknown,
|
|
55
|
-
|
|
56
|
+
SenderOverride.Blocked,
|
|
56
57
|
);
|
|
57
58
|
assert.equal(verdict.action, "move-to-junk");
|
|
58
59
|
assert.equal(verdict.confidence, "confident");
|
|
@@ -63,17 +64,17 @@ describe("classifyPlacement", () => {
|
|
|
63
64
|
baseMessage(),
|
|
64
65
|
"junk",
|
|
65
66
|
SenderTrust.Unknown,
|
|
66
|
-
|
|
67
|
+
SenderOverride.Blocked,
|
|
67
68
|
);
|
|
68
69
|
assert.notEqual(verdict.action, "move-to-junk");
|
|
69
70
|
});
|
|
70
71
|
|
|
71
|
-
it("does not demote when the sender
|
|
72
|
+
it("does not demote when the sender carries no instruction, all else equal", () => {
|
|
72
73
|
const verdict = classifyPlacement(
|
|
73
74
|
baseMessage({ providerSpam: undefined, authResult: undefined }),
|
|
74
75
|
"inbox",
|
|
75
76
|
SenderTrust.Unknown,
|
|
76
|
-
|
|
77
|
+
SenderOverride.None,
|
|
77
78
|
);
|
|
78
79
|
assert.deepEqual(verdict, {
|
|
79
80
|
action: "leave",
|
|
@@ -87,7 +88,7 @@ describe("classifyPlacement", () => {
|
|
|
87
88
|
baseMessage({ movedByRemit: true }),
|
|
88
89
|
"inbox",
|
|
89
90
|
SenderTrust.Unknown,
|
|
90
|
-
|
|
91
|
+
SenderOverride.Blocked,
|
|
91
92
|
);
|
|
92
93
|
assert.deepEqual(verdict, {
|
|
93
94
|
action: "leave",
|
|
@@ -97,70 +98,221 @@ describe("classifyPlacement", () => {
|
|
|
97
98
|
});
|
|
98
99
|
});
|
|
99
100
|
|
|
100
|
-
describe("
|
|
101
|
+
describe("SenderOverride.NeverSpam (issue #605)", () => {
|
|
102
|
+
it("rescues mail the provider rated clean from a domain that publishes no DMARC", () => {
|
|
103
|
+
const verdict = classifyPlacement(
|
|
104
|
+
baseMessage({
|
|
105
|
+
providerSpam: { classified: false },
|
|
106
|
+
authResult: { dmarc: "None" },
|
|
107
|
+
}),
|
|
108
|
+
"junk",
|
|
109
|
+
SenderTrust.Unknown,
|
|
110
|
+
SenderOverride.NeverSpam,
|
|
111
|
+
);
|
|
112
|
+
assert.deepEqual(verdict, {
|
|
113
|
+
action: "move-to-inbox",
|
|
114
|
+
confidence: "confident",
|
|
115
|
+
reasons: ["sender=never-spam"],
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("rescues before the missing-signals return, so a message with no parsed signals still comes out of junk", () => {
|
|
120
|
+
const verdict = classifyPlacement(
|
|
121
|
+
baseMessage({ providerSpam: undefined, authResult: undefined }),
|
|
122
|
+
"junk",
|
|
123
|
+
SenderTrust.Unknown,
|
|
124
|
+
SenderOverride.NeverSpam,
|
|
125
|
+
);
|
|
126
|
+
assert.equal(verdict.action, "move-to-inbox");
|
|
127
|
+
assert.equal(verdict.confidence, "confident");
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("leaves a never-spam sender's mail filed in a user folder where it is", () => {
|
|
131
|
+
const verdict = classifyPlacement(
|
|
132
|
+
baseMessage(),
|
|
133
|
+
"other",
|
|
134
|
+
SenderTrust.Unknown,
|
|
135
|
+
SenderOverride.NeverSpam,
|
|
136
|
+
);
|
|
137
|
+
assert.equal(verdict.action, "leave");
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// The demote branch is reached only from `inbox`, so a spoof already in
|
|
141
|
+
// Junk never meets it. Without the guard on the rescue, the grant would
|
|
142
|
+
// carry mail impersonating the granted address out of Junk.
|
|
143
|
+
it("refuses to rescue a dkim-mismatch + dmarc-fail spoof sitting in junk", () => {
|
|
144
|
+
const verdict = classifyPlacement(
|
|
145
|
+
baseMessage({
|
|
146
|
+
providerSpam: { classified: true },
|
|
147
|
+
authResult: { dmarc: "Fail" },
|
|
148
|
+
authenticity: { fromDomain: "example.com", dkimMismatch: true },
|
|
149
|
+
}),
|
|
150
|
+
"junk",
|
|
151
|
+
SenderTrust.Unknown,
|
|
152
|
+
SenderOverride.NeverSpam,
|
|
153
|
+
);
|
|
154
|
+
assert.notEqual(verdict.action, "move-to-inbox");
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("refuses to rescue on a hard DMARC failure even with DKIM aligned", () => {
|
|
158
|
+
const verdict = classifyPlacement(
|
|
159
|
+
baseMessage({
|
|
160
|
+
providerSpam: { classified: true },
|
|
161
|
+
authResult: { dmarc: "Fail" },
|
|
162
|
+
}),
|
|
163
|
+
"junk",
|
|
164
|
+
SenderTrust.Unknown,
|
|
165
|
+
SenderOverride.NeverSpam,
|
|
166
|
+
);
|
|
167
|
+
assert.notEqual(verdict.action, "move-to-inbox");
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("refuses to rescue on a DKIM mismatch even where DMARC did not fail", () => {
|
|
171
|
+
const verdict = classifyPlacement(
|
|
172
|
+
baseMessage({
|
|
173
|
+
providerSpam: { classified: true },
|
|
174
|
+
authResult: { dmarc: "None" },
|
|
175
|
+
authenticity: { fromDomain: "example.com", dkimMismatch: true },
|
|
176
|
+
}),
|
|
177
|
+
"junk",
|
|
178
|
+
SenderTrust.Unknown,
|
|
179
|
+
SenderOverride.NeverSpam,
|
|
180
|
+
);
|
|
181
|
+
assert.notEqual(verdict.action, "move-to-inbox");
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("still demotes a never-spam sender's inbox mail on dkim-mismatch + dmarc-fail", () => {
|
|
185
|
+
const verdict = classifyPlacement(
|
|
186
|
+
baseMessage({
|
|
187
|
+
authResult: { dmarc: "Fail" },
|
|
188
|
+
authenticity: { fromDomain: "example.com", dkimMismatch: true },
|
|
189
|
+
}),
|
|
190
|
+
"inbox",
|
|
191
|
+
SenderTrust.Unknown,
|
|
192
|
+
SenderOverride.NeverSpam,
|
|
193
|
+
);
|
|
194
|
+
assert.deepEqual(verdict, {
|
|
195
|
+
action: "move-to-junk",
|
|
196
|
+
confidence: "confident",
|
|
197
|
+
reasons: ["dkim-mismatch", "dmarc=fail", "sender=untrusted"],
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("still leaves an already-Remit-moved message alone", () => {
|
|
202
|
+
const verdict = classifyPlacement(
|
|
203
|
+
baseMessage({ movedByRemit: true }),
|
|
204
|
+
"junk",
|
|
205
|
+
SenderTrust.Unknown,
|
|
206
|
+
SenderOverride.NeverSpam,
|
|
207
|
+
);
|
|
208
|
+
assert.deepEqual(verdict, {
|
|
209
|
+
action: "leave",
|
|
210
|
+
confidence: "confident",
|
|
211
|
+
reasons: ["already-moved-by-remit"],
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
describe("resolveSenderPlacement (Decision 3a tie-break)", () => {
|
|
101
217
|
it("blocked wins when set after vip", () => {
|
|
102
|
-
const result =
|
|
218
|
+
const result = resolveSenderPlacement(
|
|
103
219
|
{ trust: SenderTrust.Vip, setAt: 1_000 },
|
|
104
220
|
{ blocked: true, setAt: 5_000 },
|
|
221
|
+
false,
|
|
105
222
|
);
|
|
106
223
|
assert.deepEqual(result, {
|
|
107
224
|
senderTrust: SenderTrust.Unknown,
|
|
108
|
-
|
|
225
|
+
senderOverride: SenderOverride.Blocked,
|
|
109
226
|
});
|
|
110
227
|
});
|
|
111
228
|
|
|
112
229
|
it("vip wins when set after blocked", () => {
|
|
113
|
-
const result =
|
|
230
|
+
const result = resolveSenderPlacement(
|
|
114
231
|
{ trust: SenderTrust.Vip, setAt: 5_000 },
|
|
115
232
|
{ blocked: true, setAt: 1_000 },
|
|
233
|
+
false,
|
|
116
234
|
);
|
|
117
235
|
assert.deepEqual(result, {
|
|
118
236
|
senderTrust: SenderTrust.Vip,
|
|
119
|
-
|
|
237
|
+
senderOverride: SenderOverride.None,
|
|
120
238
|
});
|
|
121
239
|
});
|
|
122
240
|
|
|
123
241
|
it("breaks a same-second tie in favor of blocked", () => {
|
|
124
|
-
const result =
|
|
242
|
+
const result = resolveSenderPlacement(
|
|
125
243
|
{ trust: SenderTrust.Wellknown, setAt: 1_000 },
|
|
126
244
|
{ blocked: true, setAt: 1_400 },
|
|
245
|
+
false,
|
|
127
246
|
);
|
|
128
247
|
assert.deepEqual(result, {
|
|
129
248
|
senderTrust: SenderTrust.Unknown,
|
|
130
|
-
|
|
249
|
+
senderOverride: SenderOverride.Blocked,
|
|
131
250
|
});
|
|
132
251
|
});
|
|
133
252
|
|
|
134
253
|
it("blocked applies outright when there is no competing trust flag", () => {
|
|
135
|
-
const result =
|
|
254
|
+
const result = resolveSenderPlacement(
|
|
136
255
|
{ trust: SenderTrust.Unknown },
|
|
137
256
|
{ blocked: true, setAt: 1_000 },
|
|
257
|
+
false,
|
|
138
258
|
);
|
|
139
259
|
assert.deepEqual(result, {
|
|
140
260
|
senderTrust: SenderTrust.Unknown,
|
|
141
|
-
|
|
261
|
+
senderOverride: SenderOverride.Blocked,
|
|
142
262
|
});
|
|
143
263
|
});
|
|
144
264
|
|
|
145
|
-
it("passes trust through unchanged when the sender
|
|
146
|
-
const result =
|
|
265
|
+
it("passes trust through unchanged when the sender carries no instruction", () => {
|
|
266
|
+
const result = resolveSenderPlacement(
|
|
147
267
|
{ trust: SenderTrust.Wellknown, setAt: 1_000 },
|
|
148
268
|
{ blocked: false },
|
|
269
|
+
false,
|
|
149
270
|
);
|
|
150
271
|
assert.deepEqual(result, {
|
|
151
272
|
senderTrust: SenderTrust.Wellknown,
|
|
152
|
-
|
|
273
|
+
senderOverride: SenderOverride.None,
|
|
153
274
|
});
|
|
154
275
|
});
|
|
276
|
+
|
|
277
|
+
it("reads never-spam as the instruction, leaving trust untouched", () => {
|
|
278
|
+
const result = resolveSenderPlacement(
|
|
279
|
+
{ trust: SenderTrust.Unknown },
|
|
280
|
+
{ blocked: false },
|
|
281
|
+
true,
|
|
282
|
+
);
|
|
283
|
+
assert.deepEqual(result, {
|
|
284
|
+
senderTrust: SenderTrust.Unknown,
|
|
285
|
+
senderOverride: SenderOverride.NeverSpam,
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it("does not promote a never-spam sender's trust to vip or wellknown", () => {
|
|
290
|
+
const result = resolveSenderPlacement(
|
|
291
|
+
{ trust: SenderTrust.Vip, setAt: 1_000 },
|
|
292
|
+
{ blocked: false },
|
|
293
|
+
true,
|
|
294
|
+
);
|
|
295
|
+
assert.equal(result.senderTrust, SenderTrust.Vip);
|
|
296
|
+
assert.equal(result.senderOverride, SenderOverride.NeverSpam);
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it("resolves a row that somehow carries both instructions to blocked", () => {
|
|
300
|
+
const result = resolveSenderPlacement(
|
|
301
|
+
{ trust: SenderTrust.Unknown },
|
|
302
|
+
{ blocked: true, setAt: 1_000 },
|
|
303
|
+
true,
|
|
304
|
+
);
|
|
305
|
+
assert.equal(result.senderOverride, SenderOverride.Blocked);
|
|
306
|
+
});
|
|
155
307
|
});
|
|
156
308
|
|
|
157
|
-
describe("existing DKIM/DMARC paths (unaffected by
|
|
309
|
+
describe("existing DKIM/DMARC paths (unaffected by SenderOverride.None)", () => {
|
|
158
310
|
it("rescues a trusted sender's mail from junk on provider-spam + dmarc-pass", () => {
|
|
159
311
|
const verdict = classifyPlacement(
|
|
160
312
|
baseMessage({ providerSpam: { classified: true } }),
|
|
161
313
|
"junk",
|
|
162
314
|
SenderTrust.Vip,
|
|
163
|
-
|
|
315
|
+
SenderOverride.None,
|
|
164
316
|
);
|
|
165
317
|
assert.equal(verdict.action, "move-to-inbox");
|
|
166
318
|
assert.equal(verdict.confidence, "confident");
|
|
@@ -171,7 +323,7 @@ describe("classifyPlacement", () => {
|
|
|
171
323
|
baseMessage({ providerSpam: { classified: true } }),
|
|
172
324
|
"junk",
|
|
173
325
|
SenderTrust.Unknown,
|
|
174
|
-
|
|
326
|
+
SenderOverride.None,
|
|
175
327
|
);
|
|
176
328
|
assert.equal(verdict.action, "leave");
|
|
177
329
|
assert.equal(verdict.confidence, "unsure");
|
|
@@ -185,7 +337,7 @@ describe("classifyPlacement", () => {
|
|
|
185
337
|
}),
|
|
186
338
|
"inbox",
|
|
187
339
|
SenderTrust.Unknown,
|
|
188
|
-
|
|
340
|
+
SenderOverride.None,
|
|
189
341
|
);
|
|
190
342
|
assert.deepEqual(verdict, {
|
|
191
343
|
action: "move-to-junk",
|
|
@@ -202,7 +354,7 @@ describe("classifyPlacement", () => {
|
|
|
202
354
|
}),
|
|
203
355
|
"inbox",
|
|
204
356
|
SenderTrust.Unknown,
|
|
205
|
-
|
|
357
|
+
SenderOverride.None,
|
|
206
358
|
);
|
|
207
359
|
assert.deepEqual(verdict, {
|
|
208
360
|
action: "leave",
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { MessageItem } from "@remit/data-ports";
|
|
2
|
-
import { SenderTrust } from "@remit/domain-enums";
|
|
2
|
+
import { SenderOverride, SenderTrust } from "@remit/domain-enums";
|
|
3
3
|
|
|
4
4
|
type SenderTrustValue = (typeof SenderTrust)[keyof typeof SenderTrust];
|
|
5
5
|
|
|
6
|
+
type SenderOverrideValue = (typeof SenderOverride)[keyof typeof SenderOverride];
|
|
7
|
+
|
|
6
8
|
export type FolderPlacement = "inbox" | "junk" | "other";
|
|
7
9
|
|
|
8
10
|
export type PlacementAction = "move-to-inbox" | "move-to-junk" | "leave";
|
|
@@ -39,7 +41,7 @@ export interface SenderBlockedSignal {
|
|
|
39
41
|
* fixed, arbitrary order: `blocked` before `vip` before `wellknown` — a
|
|
40
42
|
* determinism backstop, not a meaningful signal.
|
|
41
43
|
*/
|
|
42
|
-
|
|
44
|
+
const resolveBlockedVsTrust = (
|
|
43
45
|
trust: SenderTrustSignal,
|
|
44
46
|
blocked: SenderBlockedSignal,
|
|
45
47
|
): { senderTrust: SenderTrustValue; senderBlocked: boolean } => {
|
|
@@ -60,6 +62,32 @@ export const resolveBlockedVsTrust = (
|
|
|
60
62
|
return { senderTrust: trust.trust, senderBlocked: false };
|
|
61
63
|
};
|
|
62
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Resolve the two axes {@link classifyPlacement} takes: the trust signal, and
|
|
67
|
+
* the user's standing instruction about placement.
|
|
68
|
+
*
|
|
69
|
+
* `blocked` and `neverSpam` are two directly contradictory instructions and
|
|
70
|
+
* cannot both stand — `AddressRepository.mergeFlags` drops the loser at write
|
|
71
|
+
* time. Reading a row that carries both anyway (written before that invariant)
|
|
72
|
+
* resolves to `Blocked`, the same direction the `blocked`/`vip` same-second tie
|
|
73
|
+
* already breaks in: the demote is the recoverable mistake.
|
|
74
|
+
*/
|
|
75
|
+
export const resolveSenderPlacement = (
|
|
76
|
+
trust: SenderTrustSignal,
|
|
77
|
+
blocked: SenderBlockedSignal,
|
|
78
|
+
neverSpam: boolean,
|
|
79
|
+
): {
|
|
80
|
+
senderTrust: SenderTrustValue;
|
|
81
|
+
senderOverride: SenderOverrideValue;
|
|
82
|
+
} => {
|
|
83
|
+
const { senderTrust, senderBlocked } = resolveBlockedVsTrust(trust, blocked);
|
|
84
|
+
if (senderBlocked)
|
|
85
|
+
return { senderTrust, senderOverride: SenderOverride.Blocked };
|
|
86
|
+
if (neverSpam)
|
|
87
|
+
return { senderTrust, senderOverride: SenderOverride.NeverSpam };
|
|
88
|
+
return { senderTrust, senderOverride: SenderOverride.None };
|
|
89
|
+
};
|
|
90
|
+
|
|
63
91
|
/**
|
|
64
92
|
* Tier 0 deterministic placement verdict (RFC 031, "Confident moves").
|
|
65
93
|
*
|
|
@@ -69,17 +97,32 @@ export const resolveBlockedVsTrust = (
|
|
|
69
97
|
* recall-biased — a confident move only fires when cheap, deterministic signals
|
|
70
98
|
* agree; everything else is left in place for a later LLM tier.
|
|
71
99
|
*
|
|
72
|
-
* `
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
100
|
+
* `senderOverride` (RFC 039 Decision 3, issue #605) is the user's standing
|
|
101
|
+
* instruction about this sender's placement, and it outranks every
|
|
102
|
+
* DKIM/DMARC/provider signal below — an explicit block or never-spam grant is
|
|
103
|
+
* not a heuristic. Already-tie-broken against `vip`/`wellknown` by
|
|
104
|
+
* {@link resolveSenderPlacement} in the caller; this function itself does not
|
|
76
105
|
* compare `setAt`.
|
|
106
|
+
*
|
|
107
|
+
* `NeverSpam` is checked above the `missing-signals` return and above the
|
|
108
|
+
* `providerSpam.classified` gate on purpose: the senders who need the grant are
|
|
109
|
+
* the ones the provider rated clean and whose domain publishes no DMARC record,
|
|
110
|
+
* so a check inside the rescue branch below would never fire for them. It
|
|
111
|
+
* rescues only from `junk` — a message a standing filter put in a user folder
|
|
112
|
+
* is not a spam question.
|
|
113
|
+
*
|
|
114
|
+
* It refuses outright on a `dmarc === "Fail"` or a DKIM mismatch. The demote
|
|
115
|
+
* branch below is reached only from `inbox`, so a spoof already sitting in Junk
|
|
116
|
+
* would never meet it: without this guard the grant would launder mail out of
|
|
117
|
+
* Junk on exactly the two signals that identify someone impersonating the
|
|
118
|
+
* address the user granted. A domain that publishes no DMARC record never
|
|
119
|
+
* scores `Fail`, so the case the grant exists for is untouched.
|
|
77
120
|
*/
|
|
78
121
|
export const classifyPlacement = (
|
|
79
122
|
message: MessageItem,
|
|
80
123
|
placement: FolderPlacement,
|
|
81
124
|
senderTrust: SenderTrustValue,
|
|
82
|
-
|
|
125
|
+
senderOverride: SenderOverrideValue,
|
|
83
126
|
): PlacementVerdict => {
|
|
84
127
|
if (message.movedByRemit === true) {
|
|
85
128
|
return {
|
|
@@ -89,7 +132,7 @@ export const classifyPlacement = (
|
|
|
89
132
|
};
|
|
90
133
|
}
|
|
91
134
|
|
|
92
|
-
if (
|
|
135
|
+
if (senderOverride === SenderOverride.Blocked && placement !== "junk") {
|
|
93
136
|
return {
|
|
94
137
|
action: "move-to-junk",
|
|
95
138
|
confidence: "confident",
|
|
@@ -97,6 +140,19 @@ export const classifyPlacement = (
|
|
|
97
140
|
};
|
|
98
141
|
}
|
|
99
142
|
|
|
143
|
+
if (
|
|
144
|
+
senderOverride === SenderOverride.NeverSpam &&
|
|
145
|
+
placement === "junk" &&
|
|
146
|
+
message.authResult?.dmarc !== "Fail" &&
|
|
147
|
+
message.authenticity?.dkimMismatch !== true
|
|
148
|
+
) {
|
|
149
|
+
return {
|
|
150
|
+
action: "move-to-inbox",
|
|
151
|
+
confidence: "confident",
|
|
152
|
+
reasons: ["sender=never-spam"],
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
100
156
|
if (!message.providerSpam || !message.authResult) {
|
|
101
157
|
return {
|
|
102
158
|
action: "leave",
|