@remit/mailbox-service 0.0.112 → 0.0.113
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/account-credentials.d.ts +83 -0
- package/dist/account-credentials.js +104 -0
- package/dist/attribute-mapper.d.ts +36 -0
- package/dist/attribute-mapper.js +119 -0
- package/dist/body-parse.d.ts +28 -0
- package/{src/body-parse.ts → dist/body-parse.js} +18 -26
- package/dist/body-part-mapper.d.ts +92 -0
- package/dist/body-part-mapper.js +301 -0
- package/dist/body-sync-queue.d.ts +59 -0
- package/dist/body-sync-queue.js +56 -0
- package/dist/body-sync-terminal.d.ts +58 -0
- package/dist/body-sync-terminal.js +95 -0
- package/dist/body-sync.d.ts +351 -0
- package/dist/body-sync.js +1204 -0
- package/dist/calendar-parts.d.ts +23 -0
- package/dist/calendar-parts.js +18 -0
- package/dist/classification-backfill.d.ts +91 -0
- package/dist/classification-backfill.js +180 -0
- package/dist/classify-message.d.ts +31 -0
- package/dist/classify-message.js +89 -0
- package/dist/connection-factory.d.ts +54 -0
- package/dist/connection-factory.js +54 -0
- package/dist/connection-test.d.ts +41 -0
- package/dist/connection-test.js +152 -0
- package/dist/external-move.d.ts +94 -0
- package/dist/external-move.js +173 -0
- package/dist/filter-operations.d.ts +42 -0
- package/dist/filter-operations.js +211 -0
- package/dist/filters/filter-config.d.ts +14 -0
- package/dist/filters/filter-config.js +10 -0
- package/{src/filters/list-id.ts → dist/filters/list-id.d.ts} +2 -16
- package/dist/filters/list-id.js +26 -0
- package/dist/filters/match.d.ts +69 -0
- package/dist/filters/match.js +165 -0
- package/dist/filters/pipeline.d.ts +64 -0
- package/dist/filters/pipeline.js +100 -0
- package/{src/flag-push-terminal.ts → dist/flag-push-terminal.d.ts} +16 -72
- package/dist/flag-push-terminal.js +63 -0
- package/dist/flag-push.d.ts +69 -0
- package/dist/flag-push.js +111 -0
- package/dist/flag-queue.d.ts +175 -0
- package/dist/flag-queue.js +291 -0
- package/dist/folder-operations.d.ts +39 -0
- package/dist/folder-operations.js +112 -0
- package/dist/folder-placement.d.ts +13 -0
- package/dist/folder-placement.js +23 -0
- package/dist/heuristics/authenticationResults.d.ts +10 -0
- package/dist/heuristics/authenticationResults.js +187 -0
- package/dist/heuristics/classifyByHeaders.d.ts +82 -0
- package/dist/heuristics/classifyByHeaders.js +365 -0
- package/dist/heuristics/classifyPlacement.d.ts +67 -0
- package/dist/heuristics/classifyPlacement.js +153 -0
- package/dist/heuristics/machineSenders.d.ts +21 -0
- package/{src/heuristics/machineSenders.ts → dist/heuristics/machineSenders.js} +34 -40
- package/dist/heuristics/senderMismatch.d.ts +81 -0
- package/dist/heuristics/senderMismatch.js +192 -0
- package/dist/heuristics/socialDomains.d.ts +14 -0
- package/{src/heuristics/socialDomains.ts → dist/heuristics/socialDomains.js} +9 -9
- package/dist/heuristics/transactionalDomains.d.ts +18 -0
- package/{src/heuristics/transactionalDomains.ts → dist/heuristics/transactionalDomains.js} +8 -8
- package/dist/imapflow-connection.d.ts +377 -0
- package/dist/imapflow-connection.js +1147 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +65 -0
- package/dist/list-id-backfill.d.ts +83 -0
- package/dist/list-id-backfill.js +132 -0
- package/dist/mailbox-cursor-rebuild.d.ts +74 -0
- package/dist/mailbox-cursor-rebuild.js +71 -0
- package/{src/mailbox-cursor.ts → dist/mailbox-cursor.d.ts} +20 -98
- package/dist/mailbox-cursor.js +102 -0
- package/dist/mailbox-intent.d.ts +41 -0
- package/{src/mailbox-intent.ts → dist/mailbox-intent.js} +38 -64
- package/dist/mailbox-management.d.ts +240 -0
- package/dist/mailbox-management.js +576 -0
- package/dist/mailbox-presence.d.ts +52 -0
- package/{src/mailbox-presence.ts → dist/mailbox-presence.js} +19 -30
- package/dist/mailbox-queue.d.ts +126 -0
- package/dist/mailbox-queue.js +214 -0
- package/dist/mailbox-sync.d.ts +93 -0
- package/dist/mailbox-sync.js +490 -0
- package/dist/mailbox-upstream.d.ts +38 -0
- package/{src/mailbox-upstream.ts → dist/mailbox-upstream.js} +37 -47
- package/dist/message-category.d.ts +51 -0
- package/{src/message-category.ts → dist/message-category.js} +28 -71
- package/dist/message-move.d.ts +285 -0
- package/dist/message-move.js +858 -0
- package/dist/message-parser.d.ts +14 -0
- package/dist/message-parser.js +17 -0
- package/{src/message-presence.ts → dist/message-presence.d.ts} +1 -13
- package/dist/message-presence.js +29 -0
- package/dist/message-read.d.ts +51 -0
- package/dist/message-read.js +31 -0
- package/dist/message-sync.d.ts +345 -0
- package/dist/message-sync.js +1358 -0
- package/dist/mime-walker.d.ts +102 -0
- package/dist/mime-walker.js +198 -0
- package/dist/organize-job.d.ts +20 -0
- package/dist/organize-job.js +37 -0
- package/dist/outbox-attachment-content.d.ts +37 -0
- package/dist/outbox-attachment-content.js +50 -0
- package/dist/outbox-attachment-filename.d.ts +19 -0
- package/dist/outbox-attachment-filename.js +64 -0
- package/dist/outbox-attachment.d.ts +148 -0
- package/dist/outbox-attachment.js +273 -0
- package/dist/outbox-queue.d.ts +73 -0
- package/dist/outbox-queue.js +284 -0
- package/{src/outbox-status.ts → dist/outbox-status.d.ts} +1 -6
- package/dist/outbox-status.js +18 -0
- package/dist/ownership.d.ts +24 -0
- package/dist/ownership.js +83 -0
- package/dist/placement-move-terminal.d.ts +67 -0
- package/dist/placement-move-terminal.js +88 -0
- package/dist/placement-move.d.ts +83 -0
- package/dist/placement-move.js +216 -0
- package/{src/placement-settled.ts → dist/placement-settled.d.ts} +13 -68
- package/dist/placement-settled.js +75 -0
- package/dist/quarantine.d.ts +95 -0
- package/dist/quarantine.js +131 -0
- package/dist/refusal.d.ts +31 -0
- package/dist/refusal.js +3 -0
- package/{src/restore-source-placement.ts → dist/restore-source-placement.d.ts} +29 -97
- package/dist/restore-source-placement.js +79 -0
- package/dist/search-text-backfill.d.ts +15 -0
- package/dist/search-text-backfill.js +33 -0
- package/dist/snippet.d.ts +61 -0
- package/dist/snippet.js +129 -0
- package/dist/spam-report.d.ts +86 -0
- package/dist/spam-report.js +241 -0
- package/dist/sync-warning.d.ts +21 -0
- package/dist/sync-warning.js +26 -0
- package/dist/sync-watermarks.d.ts +138 -0
- package/dist/sync-watermarks.js +205 -0
- package/dist/test-helpers/fake-imap.d.ts +151 -0
- package/dist/test-helpers/fake-imap.js +508 -0
- package/dist/test-helpers/folder-roles.d.ts +34 -0
- package/dist/test-helpers/folder-roles.js +47 -0
- package/dist/test-helpers/mime-tree-generator.d.ts +82 -0
- package/dist/test-helpers/mime-tree-generator.js +329 -0
- package/dist/test-helpers/test-store.d.ts +69 -0
- package/dist/test-helpers/test-store.js +193 -0
- package/dist/text/normalizer.d.ts +20 -0
- package/dist/text/normalizer.js +102 -0
- package/dist/thread-message-rows.d.ts +69 -0
- package/dist/thread-message-rows.js +40 -0
- package/dist/thread-root.d.ts +7 -0
- package/dist/thread-root.js +25 -0
- package/dist/types.d.ts +343 -0
- package/dist/types.js +19 -0
- package/package.json +86 -88
- package/src/account-credentials.ts +0 -210
- package/src/attribute-mapper.test.ts +0 -104
- package/src/attribute-mapper.ts +0 -148
- package/src/body-parse.test.ts +0 -55
- package/src/body-part-mapper.property.test.ts +0 -354
- package/src/body-part-mapper.ts +0 -410
- package/src/body-sync-queue.test.ts +0 -64
- package/src/body-sync-queue.ts +0 -131
- package/src/body-sync-terminal.test.ts +0 -148
- package/src/body-sync-terminal.ts +0 -174
- package/src/body-sync.test.ts +0 -925
- package/src/body-sync.ts +0 -1891
- package/src/calendar-parts.ts +0 -41
- package/src/classification-backfill.test.ts +0 -285
- package/src/classification-backfill.ts +0 -363
- package/src/classify-message.test.ts +0 -142
- package/src/classify-message.ts +0 -116
- package/src/connection-factory.ts +0 -102
- package/src/connection-test.ts +0 -208
- package/src/credentials.test.ts +0 -181
- package/src/external-move.test.ts +0 -262
- package/src/external-move.ts +0 -285
- package/src/filter-operations.test.ts +0 -319
- package/src/filter-operations.ts +0 -377
- package/src/filter-update.test.ts +0 -313
- package/src/filters/filter-config.test.ts +0 -87
- package/src/filters/filter-config.ts +0 -34
- package/src/filters/list-id.test.ts +0 -50
- package/src/filters/match.test.ts +0 -392
- package/src/filters/match.ts +0 -225
- package/src/filters/pipeline.test.ts +0 -199
- package/src/filters/pipeline.ts +0 -170
- package/src/flag-push.test.ts +0 -112
- package/src/flag-push.ts +0 -198
- package/src/flag-queue.test.ts +0 -197
- package/src/flag-queue.ts +0 -509
- package/src/folder-operations.test.ts +0 -273
- package/src/folder-operations.ts +0 -217
- package/src/folder-placement.ts +0 -56
- package/src/forwarded-message.test.ts +0 -122
- package/src/heuristics/authenticationResults.test.ts +0 -189
- package/src/heuristics/authenticationResults.ts +0 -212
- package/src/heuristics/classifyByHeaders.test.ts +0 -889
- package/src/heuristics/classifyByHeaders.ts +0 -467
- package/src/heuristics/classifyPlacement.test.ts +0 -366
- package/src/heuristics/classifyPlacement.ts +0 -211
- package/src/heuristics/classifyRealMail.test.ts +0 -242
- package/src/heuristics/machineSenders.test.ts +0 -101
- package/src/heuristics/senderMismatch.test.ts +0 -346
- package/src/heuristics/senderMismatch.ts +0 -259
- package/src/imapflow-connect-retry.test.ts +0 -97
- package/src/imapflow-connection.test.ts +0 -503
- package/src/imapflow-connection.ts +0 -1476
- package/src/index.ts +0 -397
- package/src/list-id-backfill.test.ts +0 -207
- package/src/list-id-backfill.ts +0 -274
- package/src/mailbox-cursor-rebuild.test.ts +0 -171
- package/src/mailbox-cursor-rebuild.ts +0 -146
- package/src/mailbox-cursor.test.ts +0 -141
- package/src/mailbox-delete-intent.test.ts +0 -119
- package/src/mailbox-management.test.ts +0 -243
- package/src/mailbox-management.ts +0 -838
- package/src/mailbox-presence.test.ts +0 -74
- package/src/mailbox-queue.ts +0 -397
- package/src/mailbox-rename-intent.test.ts +0 -220
- package/src/mailbox-rename-subtree.test.ts +0 -287
- package/src/mailbox-sync.test.ts +0 -286
- package/src/mailbox-sync.ts +0 -724
- package/src/message-move.test.ts +0 -726
- package/src/message-move.ts +0 -1518
- package/src/message-parser.ts +0 -26
- package/src/message-presence.test.ts +0 -50
- package/src/message-read.ts +0 -87
- package/src/message-save-retry.test.ts +0 -90
- package/src/message-sync-flags.test.ts +0 -167
- package/src/message-sync.test.ts +0 -762
- package/src/message-sync.ts +0 -2133
- package/src/mime-walker.test.ts +0 -311
- package/src/mime-walker.ts +0 -306
- package/src/organize-job.ts +0 -93
- package/src/outbox-attachment-content.test.ts +0 -153
- package/src/outbox-attachment-content.ts +0 -104
- package/src/outbox-attachment-filename.test.ts +0 -132
- package/src/outbox-attachment-filename.ts +0 -76
- package/src/outbox-attachment.test.ts +0 -626
- package/src/outbox-attachment.ts +0 -536
- package/src/outbox-failed-recovery.test.ts +0 -299
- package/src/outbox-queue.test.ts +0 -315
- package/src/outbox-queue.ts +0 -525
- package/src/ownership.ts +0 -140
- package/src/placement-move-terminal.ts +0 -145
- package/src/placement-move.ts +0 -363
- package/src/placement-settled.test.ts +0 -147
- package/src/placement.test.ts +0 -404
- package/src/quarantine.test.ts +0 -133
- package/src/quarantine.ts +0 -229
- package/src/refusal.ts +0 -29
- package/src/snippet.test.ts +0 -213
- package/src/snippet.ts +0 -152
- package/src/spam-report.test.ts +0 -329
- package/src/spam-report.ts +0 -357
- package/src/sync-warning.test.ts +0 -213
- package/src/sync-warning.ts +0 -56
- package/src/sync-watermarks.test.ts +0 -409
- package/src/sync-watermarks.ts +0 -319
- package/src/system-flag-wire-format.test.ts +0 -77
- package/src/test-helpers/fake-imap.ts +0 -690
- package/src/test-helpers/folder-roles.ts +0 -66
- package/src/test-helpers/mime-tree-generator.ts +0 -461
- package/src/test-helpers/test-queue.ts +0 -56
- package/src/test-helpers/test-store.ts +0 -299
- package/src/text/normalizer.test.ts +0 -223
- package/src/text/normalizer.ts +0 -140
- package/src/thread-message-rows.ts +0 -77
- package/src/thread-root.test.ts +0 -29
- package/src/thread-root.ts +0 -51
- package/src/types/mailparser-augment.d.ts +0 -23
- package/src/types/natural-porter-stemmer.d.ts +0 -50
- package/src/types/stopword.d.ts +0 -69
- package/src/types.ts +0 -371
- package/tsconfig.json +0 -8
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
* signature, so before issue #45 it reached the `personal` fallback and sat
|
|
8
8
|
* alongside actual human correspondence.
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
/**
|
|
12
11
|
* From local-parts that mean "this mailbox is not read by a person". Matched
|
|
13
12
|
* case-insensitively against whole separator-delimited words, so `no-reply`,
|
|
@@ -18,36 +17,34 @@
|
|
|
18
17
|
* wrong entry here silently buries real mail in `automated`.
|
|
19
18
|
*/
|
|
20
19
|
const MACHINE_LOCAL_PARTS = new Set([
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
20
|
+
"noreply",
|
|
21
|
+
"donotreply",
|
|
22
|
+
"notification",
|
|
23
|
+
"notifications",
|
|
24
|
+
"notify",
|
|
25
|
+
"automailer",
|
|
26
|
+
"automated",
|
|
27
|
+
"autoreply",
|
|
28
|
+
"mailerdaemon",
|
|
29
|
+
"postmaster",
|
|
30
|
+
"bounce",
|
|
31
|
+
"bounces",
|
|
32
|
+
"alert",
|
|
33
|
+
"alerts",
|
|
35
34
|
]);
|
|
36
|
-
|
|
37
35
|
/**
|
|
38
36
|
* Machine mailbox names that senders spell across separators. Joined into one
|
|
39
37
|
* word before the local-part is split, so `no-reply` and `mailer.daemon` reduce
|
|
40
38
|
* to a single token that {@link MACHINE_LOCAL_PARTS} can match.
|
|
41
39
|
*/
|
|
42
|
-
const SPELLED_OUT_MACHINE_NAMES
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
const SPELLED_OUT_MACHINE_NAMES = [
|
|
41
|
+
[/do-not-reply/g, "donotreply"],
|
|
42
|
+
[/donot-reply/g, "donotreply"],
|
|
43
|
+
[/no-reply/g, "noreply"],
|
|
44
|
+
[/mailer-daemon/g, "mailerdaemon"],
|
|
45
|
+
[/auto-reply/g, "autoreply"],
|
|
46
|
+
[/auto-mailer/g, "automailer"],
|
|
49
47
|
];
|
|
50
|
-
|
|
51
48
|
/**
|
|
52
49
|
* Headers only bulk/notification infrastructure sets. `Feedback-ID` is the
|
|
53
50
|
* per-campaign identifier SES, Google and other ESPs attach to programmatic
|
|
@@ -55,20 +52,18 @@ const SPELLED_OUT_MACHINE_NAMES: ReadonlyArray<[RegExp, string]> = [
|
|
|
55
52
|
* vacation replies back, which only a machine sender asks for.
|
|
56
53
|
*/
|
|
57
54
|
const MACHINE_HEADERS = ["feedback-id", "x-auto-response-suppress"];
|
|
58
|
-
|
|
59
55
|
/**
|
|
60
56
|
* Split a local-part into its separator-delimited words, with the spelled-out
|
|
61
57
|
* machine names joined back up first. The `+tag` suffix is dropped: it labels a
|
|
62
58
|
* subaddress, never the mailbox.
|
|
63
59
|
*/
|
|
64
|
-
const toWords = (localPart
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
60
|
+
const toWords = (localPart) => {
|
|
61
|
+
let canonical = localPart.toLowerCase().split("+")[0].replace(/[._]/g, "-");
|
|
62
|
+
for (const [pattern, replacement] of SPELLED_OUT_MACHINE_NAMES) {
|
|
63
|
+
canonical = canonical.replace(pattern, replacement);
|
|
64
|
+
}
|
|
65
|
+
return canonical.split("-").filter(Boolean);
|
|
70
66
|
};
|
|
71
|
-
|
|
72
67
|
/**
|
|
73
68
|
* True when any whole word of the From local-part is a known machine mailbox.
|
|
74
69
|
*
|
|
@@ -79,12 +74,11 @@ const toWords = (localPart: string): string[] => {
|
|
|
79
74
|
* separators the sender wrote catches the qualified forms without inventing a
|
|
80
75
|
* match that spans two words.
|
|
81
76
|
*/
|
|
82
|
-
export const isMachineLocalPart = (localPart
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return false;
|
|
77
|
+
export const isMachineLocalPart = (localPart) => toWords(localPart).some((word) => MACHINE_LOCAL_PARTS.has(word));
|
|
78
|
+
export const hasMachineHeader = (headerKeys) => {
|
|
79
|
+
for (const key of headerKeys) {
|
|
80
|
+
if (MACHINE_HEADERS.includes(key.toLowerCase()))
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
return false;
|
|
90
84
|
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { DisplayNameCorrespondence } from "@remit/domain-enums";
|
|
2
|
+
import type { ParsedMail } from "mailparser";
|
|
3
|
+
import type { FolderPlacement } from "./classifyPlacement.js";
|
|
4
|
+
type CorrespondenceValue = (typeof DisplayNameCorrespondence)[keyof typeof DisplayNameCorrespondence];
|
|
5
|
+
/**
|
|
6
|
+
* The two signals that survive a passing SPF/DKIM/DMARC check: a display name
|
|
7
|
+
* that belongs to nobody at the sending domain, and body links that leave it.
|
|
8
|
+
*
|
|
9
|
+
* Both are deliberately aggressive, and both are computed only for mail the
|
|
10
|
+
* provider's own filter already called spam or that sits in the Junk folder
|
|
11
|
+
* (see {@link extractSenderMismatch}).
|
|
12
|
+
* On a shared-tenant host — a free Atlassian, Salesforce or Zendesk instance —
|
|
13
|
+
* the verified subdomain is chosen by whoever signed up, so a passing signature
|
|
14
|
+
* proves the domain and nothing about the identity the message claims.
|
|
15
|
+
*/
|
|
16
|
+
export interface SenderMismatchSignals {
|
|
17
|
+
displayNameCorrespondence?: CorrespondenceValue;
|
|
18
|
+
offDomainLinkDomains?: string[];
|
|
19
|
+
}
|
|
20
|
+
export interface SenderMismatchContext {
|
|
21
|
+
fromDomain: string;
|
|
22
|
+
providerSpamClassified: boolean;
|
|
23
|
+
placement: FolderPlacement;
|
|
24
|
+
/**
|
|
25
|
+
* List-Unsubscribe present. Bulk mail routinely shows a brand name over an
|
|
26
|
+
* ESP's sending domain, so the display-name comparison says nothing there and
|
|
27
|
+
* is not made.
|
|
28
|
+
*/
|
|
29
|
+
bulkSender: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Whether the From display name corresponds to the From domain.
|
|
33
|
+
*
|
|
34
|
+
* Containment decides: the normalised name, or any word of it, containing an
|
|
35
|
+
* entire domain candidate. `GitHub` contains the label `github` from
|
|
36
|
+
* `notifications.github.com`; `InfoMedics` contains no label of
|
|
37
|
+
* `serviceupdatebank.atlassian.net`.
|
|
38
|
+
*
|
|
39
|
+
* Only that direction counts — a domain candidate containing the (shorter)
|
|
40
|
+
* name does not. `ING Fraudedesk` is not a match for `secure-ing-verify.tk`
|
|
41
|
+
* just because the three-letter word "ing" sits inside "secureingverify":
|
|
42
|
+
* that is a coincidental substring of a longer label the domain owner chose,
|
|
43
|
+
* not a domain that names the brand. The direction this drops is exactly the
|
|
44
|
+
* one a short, valuable brand name is deliberately embedded into a longer,
|
|
45
|
+
* unrelated-looking domain to exploit — the live Dutch-bank shape this was
|
|
46
|
+
* fixed against (`ING`). A real short brand over its own domain (`ING` /
|
|
47
|
+
* `ing.nl`) still matches: name and label are then equal, and equality
|
|
48
|
+
* satisfies containment in either direction.
|
|
49
|
+
*
|
|
50
|
+
* A bounded edit distance is the secondary test, and only reaches names that
|
|
51
|
+
* nearly match a label — `InfoMedics` against `1nfomedics.nl`. It cannot promote
|
|
52
|
+
* an unrelated name on its own.
|
|
53
|
+
*
|
|
54
|
+
* A name that spells out an address is decided before any of that. Over the
|
|
55
|
+
* sending domain it claims nothing — `billing@` shown over
|
|
56
|
+
* `serviceupdatebank.atlassian.net` names the same party the envelope does.
|
|
57
|
+
* Over any other registrable domain it is the strongest non-correspondence
|
|
58
|
+
* signal there is: the message asserts, in the one field the recipient reads,
|
|
59
|
+
* that it comes from an address that cannot have sent it.
|
|
60
|
+
*/
|
|
61
|
+
export declare const classifyDisplayNameCorrespondence: (displayName: string | undefined, fromDomain: string) => CorrespondenceValue;
|
|
62
|
+
/**
|
|
63
|
+
* Registrable domains the body's links point at, minus the sender's own.
|
|
64
|
+
*
|
|
65
|
+
* `mailto:`, `tel:`, in-page anchors and relative hrefs carry no destination
|
|
66
|
+
* domain and are skipped; anything else is resolved public-suffix-aware through
|
|
67
|
+
* tldts, so `co.uk` and `atlassian.net` both survive the comparison a naive dot
|
|
68
|
+
* split gets wrong.
|
|
69
|
+
*/
|
|
70
|
+
export declare const extractOffDomainLinkDomains: (parsed: ParsedMail, fromDomain: string) => string[];
|
|
71
|
+
/**
|
|
72
|
+
* Both signals, gated on a spam verdict: the provider's own, or the message
|
|
73
|
+
* sitting in the Junk folder.
|
|
74
|
+
*
|
|
75
|
+
* The gate is what lets the checks be this aggressive: ordinary mail never
|
|
76
|
+
* reaches them, so a brand name over an ESP domain or a newsletter full of
|
|
77
|
+
* tracking links can never be flagged. Returns an empty object when the gate
|
|
78
|
+
* does not open — the fields stay absent, meaning "not compared".
|
|
79
|
+
*/
|
|
80
|
+
export declare const extractSenderMismatch: (parsed: ParsedMail, context: SenderMismatchContext) => SenderMismatchSignals;
|
|
81
|
+
export {};
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { DisplayNameCorrespondence } from "@remit/domain-enums";
|
|
2
|
+
import { getDomain, parse as parseHost } from "tldts";
|
|
3
|
+
const MAX_LINK_DOMAINS = 10;
|
|
4
|
+
const normalize = (value) => value.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
5
|
+
/**
|
|
6
|
+
* The parts of a host a display name could honestly correspond to: the
|
|
7
|
+
* registrable name without its public suffix, every subdomain label, and the
|
|
8
|
+
* registrable domain run together. The suffix itself is dropped — `net` and
|
|
9
|
+
* `com` sit inside half the brand names in existence.
|
|
10
|
+
*/
|
|
11
|
+
const correspondenceCandidates = (host) => {
|
|
12
|
+
const parsed = parseHost(host);
|
|
13
|
+
const labels = (parsed.subdomain ?? "").split(".");
|
|
14
|
+
if (parsed.domainWithoutSuffix !== null) {
|
|
15
|
+
labels.push(parsed.domainWithoutSuffix);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
labels.push(...host.split(".").slice(0, -1));
|
|
19
|
+
}
|
|
20
|
+
if (parsed.domain !== null)
|
|
21
|
+
labels.push(parsed.domain);
|
|
22
|
+
return labels.map(normalize).filter((label) => label.length >= 3);
|
|
23
|
+
};
|
|
24
|
+
const words = (displayName) => displayName
|
|
25
|
+
.toLowerCase()
|
|
26
|
+
.split(/[^a-z0-9]+/)
|
|
27
|
+
.filter((word) => word.length >= 3);
|
|
28
|
+
const editDistance = (a, b) => {
|
|
29
|
+
let previous = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
30
|
+
for (let i = 1; i <= a.length; i++) {
|
|
31
|
+
const current = [i];
|
|
32
|
+
for (let j = 1; j <= b.length; j++) {
|
|
33
|
+
current[j] = Math.min(previous[j] + 1, current[j - 1] + 1, previous[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
34
|
+
}
|
|
35
|
+
previous = current;
|
|
36
|
+
}
|
|
37
|
+
return previous[b.length];
|
|
38
|
+
};
|
|
39
|
+
const ADDRESS_SHAPE = /[^\s<>@,;:"]+@([a-z0-9-]+(?:\.[a-z0-9-]+)+)/i;
|
|
40
|
+
const registrableDomain = (host) => getDomain(host) ?? host.toLowerCase();
|
|
41
|
+
/**
|
|
42
|
+
* The registrable domain of the address a display name spells out, or
|
|
43
|
+
* `undefined` when it holds an `@` without an address behind it — `Bob @ Acme`
|
|
44
|
+
* asserts no address and is left to the ordinary comparison.
|
|
45
|
+
*/
|
|
46
|
+
const claimedAddressDomain = (displayName) => {
|
|
47
|
+
const host = ADDRESS_SHAPE.exec(displayName)?.[1];
|
|
48
|
+
if (host === undefined)
|
|
49
|
+
return undefined;
|
|
50
|
+
return registrableDomain(host);
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* The distance a name of this length may be from a domain label and still be
|
|
54
|
+
* read as an imitation of it. Tight on purpose: an unrelated brand name and an
|
|
55
|
+
* ESP's domain are always far apart, so distance alone must never decide.
|
|
56
|
+
*/
|
|
57
|
+
const lookalikeThreshold = (length) => {
|
|
58
|
+
if (length < 5)
|
|
59
|
+
return 0;
|
|
60
|
+
if (length < 9)
|
|
61
|
+
return 1;
|
|
62
|
+
return 2;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Whether the From display name corresponds to the From domain.
|
|
66
|
+
*
|
|
67
|
+
* Containment decides: the normalised name, or any word of it, containing an
|
|
68
|
+
* entire domain candidate. `GitHub` contains the label `github` from
|
|
69
|
+
* `notifications.github.com`; `InfoMedics` contains no label of
|
|
70
|
+
* `serviceupdatebank.atlassian.net`.
|
|
71
|
+
*
|
|
72
|
+
* Only that direction counts — a domain candidate containing the (shorter)
|
|
73
|
+
* name does not. `ING Fraudedesk` is not a match for `secure-ing-verify.tk`
|
|
74
|
+
* just because the three-letter word "ing" sits inside "secureingverify":
|
|
75
|
+
* that is a coincidental substring of a longer label the domain owner chose,
|
|
76
|
+
* not a domain that names the brand. The direction this drops is exactly the
|
|
77
|
+
* one a short, valuable brand name is deliberately embedded into a longer,
|
|
78
|
+
* unrelated-looking domain to exploit — the live Dutch-bank shape this was
|
|
79
|
+
* fixed against (`ING`). A real short brand over its own domain (`ING` /
|
|
80
|
+
* `ing.nl`) still matches: name and label are then equal, and equality
|
|
81
|
+
* satisfies containment in either direction.
|
|
82
|
+
*
|
|
83
|
+
* A bounded edit distance is the secondary test, and only reaches names that
|
|
84
|
+
* nearly match a label — `InfoMedics` against `1nfomedics.nl`. It cannot promote
|
|
85
|
+
* an unrelated name on its own.
|
|
86
|
+
*
|
|
87
|
+
* A name that spells out an address is decided before any of that. Over the
|
|
88
|
+
* sending domain it claims nothing — `billing@` shown over
|
|
89
|
+
* `serviceupdatebank.atlassian.net` names the same party the envelope does.
|
|
90
|
+
* Over any other registrable domain it is the strongest non-correspondence
|
|
91
|
+
* signal there is: the message asserts, in the one field the recipient reads,
|
|
92
|
+
* that it comes from an address that cannot have sent it.
|
|
93
|
+
*/
|
|
94
|
+
export const classifyDisplayNameCorrespondence = (displayName, fromDomain) => {
|
|
95
|
+
const raw = (displayName ?? "").trim();
|
|
96
|
+
if (raw === "")
|
|
97
|
+
return DisplayNameCorrespondence.NoClaim;
|
|
98
|
+
const claimed = claimedAddressDomain(raw);
|
|
99
|
+
if (claimed !== undefined) {
|
|
100
|
+
if (claimed === registrableDomain(fromDomain)) {
|
|
101
|
+
return DisplayNameCorrespondence.NoClaim;
|
|
102
|
+
}
|
|
103
|
+
return DisplayNameCorrespondence.ForeignAddress;
|
|
104
|
+
}
|
|
105
|
+
const name = normalize(raw);
|
|
106
|
+
if (name.length < 3)
|
|
107
|
+
return DisplayNameCorrespondence.NoClaim;
|
|
108
|
+
const candidates = correspondenceCandidates(fromDomain);
|
|
109
|
+
if (candidates.length === 0)
|
|
110
|
+
return DisplayNameCorrespondence.NoClaim;
|
|
111
|
+
const terms = [name, ...words(raw)];
|
|
112
|
+
for (const term of terms) {
|
|
113
|
+
for (const candidate of candidates) {
|
|
114
|
+
if (term.includes(candidate)) {
|
|
115
|
+
return DisplayNameCorrespondence.Corresponds;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
for (const candidate of candidates) {
|
|
120
|
+
const threshold = lookalikeThreshold(Math.min(name.length, candidate.length));
|
|
121
|
+
if (threshold === 0)
|
|
122
|
+
continue;
|
|
123
|
+
if (Math.abs(name.length - candidate.length) > threshold)
|
|
124
|
+
continue;
|
|
125
|
+
if (editDistance(name, candidate) <= threshold) {
|
|
126
|
+
return DisplayNameCorrespondence.Lookalike;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return DisplayNameCorrespondence.Unrelated;
|
|
130
|
+
};
|
|
131
|
+
const hrefsFromHtml = (html) => {
|
|
132
|
+
const out = [];
|
|
133
|
+
const pattern = /href\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/gi;
|
|
134
|
+
let match = pattern.exec(html);
|
|
135
|
+
while (match !== null) {
|
|
136
|
+
out.push(match[1] ?? match[2] ?? match[3] ?? "");
|
|
137
|
+
match = pattern.exec(html);
|
|
138
|
+
}
|
|
139
|
+
return out;
|
|
140
|
+
};
|
|
141
|
+
const urlsFromText = (text) => text.match(/https?:\/\/[^\s<>"')\]]+/gi) ?? [];
|
|
142
|
+
/**
|
|
143
|
+
* Registrable domains the body's links point at, minus the sender's own.
|
|
144
|
+
*
|
|
145
|
+
* `mailto:`, `tel:`, in-page anchors and relative hrefs carry no destination
|
|
146
|
+
* domain and are skipped; anything else is resolved public-suffix-aware through
|
|
147
|
+
* tldts, so `co.uk` and `atlassian.net` both survive the comparison a naive dot
|
|
148
|
+
* split gets wrong.
|
|
149
|
+
*/
|
|
150
|
+
export const extractOffDomainLinkDomains = (parsed, fromDomain) => {
|
|
151
|
+
const senderDomain = getDomain(fromDomain);
|
|
152
|
+
const html = typeof parsed.html === "string" ? parsed.html : "";
|
|
153
|
+
const text = typeof parsed.text === "string" ? parsed.text : "";
|
|
154
|
+
const seen = new Set();
|
|
155
|
+
const out = [];
|
|
156
|
+
for (const href of [...hrefsFromHtml(html), ...urlsFromText(text)]) {
|
|
157
|
+
const value = href.trim();
|
|
158
|
+
if (value === "" || !/^https?:\/\//i.test(value))
|
|
159
|
+
continue;
|
|
160
|
+
const domain = getDomain(value);
|
|
161
|
+
if (domain === null || domain === senderDomain)
|
|
162
|
+
continue;
|
|
163
|
+
if (seen.has(domain))
|
|
164
|
+
continue;
|
|
165
|
+
seen.add(domain);
|
|
166
|
+
out.push(domain);
|
|
167
|
+
if (out.length === MAX_LINK_DOMAINS)
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
return out;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* Both signals, gated on a spam verdict: the provider's own, or the message
|
|
174
|
+
* sitting in the Junk folder.
|
|
175
|
+
*
|
|
176
|
+
* The gate is what lets the checks be this aggressive: ordinary mail never
|
|
177
|
+
* reaches them, so a brand name over an ESP domain or a newsletter full of
|
|
178
|
+
* tracking links can never be flagged. Returns an empty object when the gate
|
|
179
|
+
* does not open — the fields stay absent, meaning "not compared".
|
|
180
|
+
*/
|
|
181
|
+
export const extractSenderMismatch = (parsed, context) => {
|
|
182
|
+
if (!context.providerSpamClassified && context.placement !== "junk") {
|
|
183
|
+
return {};
|
|
184
|
+
}
|
|
185
|
+
const offDomainLinkDomains = extractOffDomainLinkDomains(parsed, context.fromDomain);
|
|
186
|
+
if (context.bulkSender)
|
|
187
|
+
return { offDomainLinkDomains };
|
|
188
|
+
return {
|
|
189
|
+
displayNameCorrespondence: classifyDisplayNameCorrespondence(parsed.from?.value?.[0]?.name, context.fromDomain),
|
|
190
|
+
offDomainLinkDomains,
|
|
191
|
+
};
|
|
192
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hand-curated allow-list of domains whose mail is treated as `social`.
|
|
3
|
+
*
|
|
4
|
+
* Sources are notifications from social/communication platforms. Match is
|
|
5
|
+
* suffix-based on the From-domain (lowercase). `news.linkedin.com` matches
|
|
6
|
+
* an entry of `linkedin.com`. Add new entries lowercase, no leading dot.
|
|
7
|
+
*
|
|
8
|
+
* Note: GitHub deliberately does NOT appear here. It is in
|
|
9
|
+
* `transactionalDomains.ts` because the EDD prioritises receipts and
|
|
10
|
+
* security alerts. The transactional rule fires before the social rule, so
|
|
11
|
+
* placing GitHub in the transactional list ensures all GitHub mail surfaces
|
|
12
|
+
* as `transactional`.
|
|
13
|
+
*/
|
|
14
|
+
export declare const SOCIAL_DOMAINS: readonly ["linkedin.com", "x.com", "twitter.com", "facebook.com", "instagram.com", "meetup.com", "discord.com", "slack.com"];
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
* as `transactional`.
|
|
13
13
|
*/
|
|
14
14
|
export const SOCIAL_DOMAINS = [
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
]
|
|
15
|
+
"linkedin.com",
|
|
16
|
+
"x.com",
|
|
17
|
+
"twitter.com",
|
|
18
|
+
"facebook.com",
|
|
19
|
+
"instagram.com",
|
|
20
|
+
"meetup.com",
|
|
21
|
+
"discord.com",
|
|
22
|
+
"slack.com",
|
|
23
|
+
];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hand-curated allow-list of domains whose mail is treated as `transactional`.
|
|
3
|
+
*
|
|
4
|
+
* Sources are receipts, billing, security alerts, and similar
|
|
5
|
+
* person-actionable but not promotional mail. GitHub appears here (security
|
|
6
|
+
* alerts, billing receipts) and is intentionally NOT in the social allow-list
|
|
7
|
+
* — we want a GitHub security alert to surface as `transactional`, not
|
|
8
|
+
* `social`.
|
|
9
|
+
*
|
|
10
|
+
* Match is suffix-based on the From-domain (lowercase). `news.example.com`
|
|
11
|
+
* matches an entry of `example.com`. Add new entries lowercase, no leading
|
|
12
|
+
* dot.
|
|
13
|
+
*
|
|
14
|
+
* TODO: We deliberately do NOT seed banks here — the bank landscape is too
|
|
15
|
+
* geographic, and a wrong allow-list entry causes silent mis-classification.
|
|
16
|
+
* Banks should be added per-deployment by the operator.
|
|
17
|
+
*/
|
|
18
|
+
export declare const TRANSACTIONAL_DOMAINS: readonly ["github.com", "stripe.com", "paypal.com", "square.com", "itunes.com", "apple.com", "google.com"];
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
* Banks should be added per-deployment by the operator.
|
|
17
17
|
*/
|
|
18
18
|
export const TRANSACTIONAL_DOMAINS = [
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
]
|
|
19
|
+
"github.com",
|
|
20
|
+
"stripe.com",
|
|
21
|
+
"paypal.com",
|
|
22
|
+
"square.com",
|
|
23
|
+
"itunes.com",
|
|
24
|
+
"apple.com",
|
|
25
|
+
"google.com",
|
|
26
|
+
];
|