@remit/mailbox-service 0.0.112 → 0.0.114
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 +129 -0
- package/dist/mailbox-queue.js +216 -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 +280 -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
package/src/body-parse.test.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The boundary the whole quarantine feature rests on: a message defect is a
|
|
3
|
-
* `BodyParseError`, everything else is not. If this type ever wraps something
|
|
4
|
-
* that is not the parser's refusal, an outage becomes a pile of records saying
|
|
5
|
-
* the user's mail is unreadable — and the cursor moves past it.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import assert from "node:assert/strict";
|
|
9
|
-
import { describe, it } from "node:test";
|
|
10
|
-
import { BodyParseError, parseMessageBody } from "./body-parse.js";
|
|
11
|
-
|
|
12
|
-
const WELL_FORMED = Buffer.from(
|
|
13
|
-
[
|
|
14
|
-
"From: someone@example.com",
|
|
15
|
-
"Subject: hello",
|
|
16
|
-
"Content-Type: text/plain",
|
|
17
|
-
"",
|
|
18
|
-
"body",
|
|
19
|
-
].join("\r\n"),
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
describe("parseMessageBody", () => {
|
|
23
|
-
it("returns the parsed message when the body is readable", async () => {
|
|
24
|
-
const parsed = await parseMessageBody(WELL_FORMED);
|
|
25
|
-
assert.equal(parsed.subject, "hello");
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("wraps a parser refusal so the catch site can attribute it", async () => {
|
|
29
|
-
const error = await parseMessageBody(
|
|
30
|
-
// A source the parser has to reject rather than tolerate.
|
|
31
|
-
null as unknown as Buffer,
|
|
32
|
-
).then(
|
|
33
|
-
() => null,
|
|
34
|
-
(err: unknown) => err,
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
assert.ok(error instanceof BodyParseError);
|
|
38
|
-
assert.equal(error.name, "BodyParseError");
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("names an unknown charset, because that defect is identifiable", () => {
|
|
42
|
-
const error = new BodyParseError(new Error("Unknown charset: x-nonesuch"));
|
|
43
|
-
assert.equal(error.failureCode, "UnknownCharset");
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("refuses to guess a code from parser prose it cannot read", () => {
|
|
47
|
-
const error = new BodyParseError(new Error("something went sideways"));
|
|
48
|
-
assert.equal(error.failureCode, "UnreadableBody");
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it("keeps the parser's own words, which stay on screen and off a report", () => {
|
|
52
|
-
const error = new BodyParseError(new Error("boundary never closed"));
|
|
53
|
-
assert.equal(error.message, "boundary never closed");
|
|
54
|
-
});
|
|
55
|
-
});
|
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Property test for the total body-part mapper (issue #395 PR C).
|
|
3
|
-
*
|
|
4
|
-
* Generates 10,000 random MIME trees (depth ≤ 4, mixed/alternative/related
|
|
5
|
-
* multiparts, five leaf content types, optional filenames/contentIds,
|
|
6
|
-
* occasional empty leaves), renders each to an `.eml`, parses it via
|
|
7
|
-
* `simpleParser`, walks the synthetic tree into `MapperInput[]`, and runs
|
|
8
|
-
* `mapBodyPartsToContent`.
|
|
9
|
-
*
|
|
10
|
-
* Per-iteration assertions:
|
|
11
|
-
* 1. Totality — `pairs.length === leafCount`.
|
|
12
|
-
* 2. Buffer-ness — every `pair.content` is a Buffer (never undefined/null).
|
|
13
|
-
* 3. No-throw — wrapping the call site never escapes.
|
|
14
|
-
* 4. PartPath cover — every leaf's `partPath` appears exactly once in `pairs`.
|
|
15
|
-
*
|
|
16
|
-
* Reproducibility: seed via `MAPPER_PROPERTY_SEED` env var. Defaults to
|
|
17
|
-
* `0xC0DEC0DE` so CI runs are deterministic. The generator's per-iteration
|
|
18
|
-
* RNG is derived from `(baseSeed ^ iterationIndex)` so a failure on
|
|
19
|
-
* iteration `N` can be reproduced as a single-iteration run with the same
|
|
20
|
-
* combined seed.
|
|
21
|
-
*
|
|
22
|
-
* Targeted property blocks below cover PR B reviewer's three gaps:
|
|
23
|
-
* - Case-insensitive `dispositionFilename` matching.
|
|
24
|
-
* - Negative routing: `application/octet-stream` without a filename
|
|
25
|
-
* doesn't swallow a text/html attachment.
|
|
26
|
-
* - Inline `cid:` casing + angle-bracket insensitivity.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
import assert from "node:assert/strict";
|
|
30
|
-
import { Buffer } from "node:buffer";
|
|
31
|
-
import { describe, it } from "node:test";
|
|
32
|
-
import { simpleParser } from "mailparser";
|
|
33
|
-
import { type MapperInput, mapBodyPartsToContent } from "./body-part-mapper.js";
|
|
34
|
-
import {
|
|
35
|
-
createRng,
|
|
36
|
-
generateMimeTree,
|
|
37
|
-
type MultipartNode,
|
|
38
|
-
renderEml,
|
|
39
|
-
treeToBodyParts,
|
|
40
|
-
} from "./test-helpers/mime-tree-generator.js";
|
|
41
|
-
|
|
42
|
-
const DEFAULT_SEED = 0xc0dec0de;
|
|
43
|
-
const ITERATIONS = 10_000;
|
|
44
|
-
|
|
45
|
-
const parseSeed = (): number => {
|
|
46
|
-
const raw = process.env.MAPPER_PROPERTY_SEED;
|
|
47
|
-
if (!raw) return DEFAULT_SEED;
|
|
48
|
-
const n = Number.parseInt(raw, 10);
|
|
49
|
-
if (Number.isNaN(n)) {
|
|
50
|
-
throw new Error(
|
|
51
|
-
`MAPPER_PROPERTY_SEED is not a valid integer: ${JSON.stringify(raw)}`,
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
return n | 0;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const collectLeafPaths = (parts: readonly MapperInput[]): string[] =>
|
|
58
|
-
parts.filter((p) => !p.isMultipart).map((p) => p.partPath);
|
|
59
|
-
|
|
60
|
-
describe("body-part-mapper property: random MIME trees", () => {
|
|
61
|
-
it(`pairs every leaf for ${ITERATIONS} random trees (seed-reproducible)`, async () => {
|
|
62
|
-
const baseSeed = parseSeed();
|
|
63
|
-
|
|
64
|
-
for (let i = 0; i < ITERATIONS; i++) {
|
|
65
|
-
const iterSeed = (baseSeed ^ i) | 0;
|
|
66
|
-
const rng = createRng(iterSeed);
|
|
67
|
-
const tree = generateMimeTree(rng);
|
|
68
|
-
const eml = renderEml(tree, { seed: iterSeed });
|
|
69
|
-
const bodyParts = treeToBodyParts(tree);
|
|
70
|
-
const leafPaths = collectLeafPaths(bodyParts);
|
|
71
|
-
|
|
72
|
-
let parsed: Awaited<ReturnType<typeof simpleParser>>;
|
|
73
|
-
try {
|
|
74
|
-
parsed = await simpleParser(eml);
|
|
75
|
-
} catch (err) {
|
|
76
|
-
// If mailparser can't parse, the generated EML is bad — surface
|
|
77
|
-
// it loudly with the seed so we can reproduce.
|
|
78
|
-
assert.fail(
|
|
79
|
-
`simpleParser threw for seed=${iterSeed} (iteration ${i}): ${(err as Error).message}`,
|
|
80
|
-
);
|
|
81
|
-
throw err; // unreachable; satisfies the control-flow analysis below.
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Assertion 3: mapper never throws.
|
|
85
|
-
let pairs: ReturnType<typeof mapBodyPartsToContent>;
|
|
86
|
-
try {
|
|
87
|
-
pairs = mapBodyPartsToContent(bodyParts, parsed);
|
|
88
|
-
} catch (err) {
|
|
89
|
-
assert.fail(
|
|
90
|
-
`mapBodyPartsToContent threw for seed=${iterSeed} (iteration ${i}): ${(err as Error).message}`,
|
|
91
|
-
);
|
|
92
|
-
throw err; // unreachable
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Assertion 1: totality.
|
|
96
|
-
assert.equal(
|
|
97
|
-
pairs.length,
|
|
98
|
-
leafPaths.length,
|
|
99
|
-
`totality violated for seed=${iterSeed} (iteration ${i}): pairs=${pairs.length} leaves=${leafPaths.length}`,
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
// Assertion 2: every content is a Buffer.
|
|
103
|
-
for (const p of pairs) {
|
|
104
|
-
assert.ok(
|
|
105
|
-
Buffer.isBuffer(p.content),
|
|
106
|
-
`pair.content is not a Buffer for seed=${iterSeed} (iteration ${i}), partPath=${p.partPath}`,
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Assertion 4: every leaf partPath appears exactly once.
|
|
111
|
-
const seen = new Map<string, number>();
|
|
112
|
-
for (const p of pairs)
|
|
113
|
-
seen.set(p.partPath, (seen.get(p.partPath) ?? 0) + 1);
|
|
114
|
-
for (const path of leafPaths) {
|
|
115
|
-
assert.equal(
|
|
116
|
-
seen.get(path),
|
|
117
|
-
1,
|
|
118
|
-
`leaf partPath="${path}" not paired exactly once for seed=${iterSeed} (iteration ${i})`,
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
/* -------------------------------------------------------------------- */
|
|
126
|
-
/* Targeted properties: PR B reviewer's three gaps */
|
|
127
|
-
/* -------------------------------------------------------------------- */
|
|
128
|
-
|
|
129
|
-
const TARGETED_ITERATIONS = 100;
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Random-case filename matching. Generates a tree with one html leaf and
|
|
133
|
-
* one PDF attachment whose filename has a random mix of upper/lower-case
|
|
134
|
-
* letters. The BODYSTRUCTURE row records the filename verbatim; mailparser
|
|
135
|
-
* preserves the same string on the attachment. The dispositionFilename
|
|
136
|
-
* fallback must match case-insensitively (PR B's `findByFilename` lowercases
|
|
137
|
-
* both sides). With `partId === partPath` doing structural pairing first
|
|
138
|
-
* this looks easy — but if mailparser ever drifts on partId we want the
|
|
139
|
-
* filename fallback to keep working.
|
|
140
|
-
*/
|
|
141
|
-
describe("body-part-mapper property: case-insensitive filename match", () => {
|
|
142
|
-
it("pairs a PDF leaf when the filename has random-case extension", async () => {
|
|
143
|
-
const baseSeed = parseSeed() ^ 0xa1a1a1a1;
|
|
144
|
-
|
|
145
|
-
for (let i = 0; i < TARGETED_ITERATIONS; i++) {
|
|
146
|
-
const rng = createRng((baseSeed ^ i) | 0);
|
|
147
|
-
const randomCase = (s: string): string =>
|
|
148
|
-
[...s]
|
|
149
|
-
.map((c) => (rng.bool(0.5) ? c.toUpperCase() : c.toLowerCase()))
|
|
150
|
-
.join("");
|
|
151
|
-
const filename = randomCase("invoice.pdf");
|
|
152
|
-
|
|
153
|
-
const tree: MultipartNode = {
|
|
154
|
-
kind: "multipart",
|
|
155
|
-
subtype: "mixed",
|
|
156
|
-
children: [
|
|
157
|
-
{
|
|
158
|
-
kind: "leaf",
|
|
159
|
-
contentType: "text/html",
|
|
160
|
-
bytes: Buffer.from("<p>see attached</p>", "utf8"),
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
kind: "leaf",
|
|
164
|
-
// BODYSTRUCTURE will declare octet-stream; mailparser sniffs PDF
|
|
165
|
-
// from the filename. Filename-case insensitivity is the
|
|
166
|
-
// load-bearing step.
|
|
167
|
-
contentType: "application/octet-stream",
|
|
168
|
-
bytes: Buffer.from("%PDF-fake-bytes", "utf8"),
|
|
169
|
-
filename,
|
|
170
|
-
disposition: "attachment",
|
|
171
|
-
},
|
|
172
|
-
],
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
const seed = (baseSeed ^ i) | 0;
|
|
176
|
-
const eml = renderEml(tree, { seed });
|
|
177
|
-
const bodyParts = treeToBodyParts(tree);
|
|
178
|
-
const parsed = await simpleParser(eml);
|
|
179
|
-
const pairs = mapBodyPartsToContent(bodyParts, parsed);
|
|
180
|
-
|
|
181
|
-
assert.equal(pairs.length, 2, `seed=${seed}: expected 2 pairs`);
|
|
182
|
-
const pdfPair = pairs.find((p) => p.partPath === "2");
|
|
183
|
-
assert.ok(pdfPair, `seed=${seed}: missing partPath=2 pair`);
|
|
184
|
-
// PDF bytes (from mailparser's attachment) — must equal the rendered
|
|
185
|
-
// leaf body, not an empty buffer and not the html bytes.
|
|
186
|
-
assert.equal(
|
|
187
|
-
pdfPair.content.toString("utf8"),
|
|
188
|
-
"%PDF-fake-bytes",
|
|
189
|
-
`seed=${seed}: PDF pair bytes mismatch (filename=${filename})`,
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Negative routing: an `application/octet-stream` leaf with no filename
|
|
197
|
-
* must not consume a `text/html` attachment from mailparser. With PR B's
|
|
198
|
-
* mapper, the html leaf is routed via `parsed.html` (text-routing slot)
|
|
199
|
-
* before the octet-stream leaf reaches the non-text pairing pipeline,
|
|
200
|
-
* so the html bytes stay with their proper leaf.
|
|
201
|
-
*
|
|
202
|
-
* Shape: multipart/mixed with [html-leaf, octet-stream-leaf]. The
|
|
203
|
-
* octet-stream has no filename, no contentId — only the positional
|
|
204
|
-
* fallback can pair it. We assert that the octet-stream pair does NOT
|
|
205
|
-
* receive the html body's bytes.
|
|
206
|
-
*/
|
|
207
|
-
describe("body-part-mapper property: negative routing for octet-stream", () => {
|
|
208
|
-
it("does not pair an unnamed octet-stream leaf with html bytes", async () => {
|
|
209
|
-
const baseSeed = parseSeed() ^ 0xb2b2b2b2;
|
|
210
|
-
|
|
211
|
-
for (let i = 0; i < TARGETED_ITERATIONS; i++) {
|
|
212
|
-
const seed = (baseSeed ^ i) | 0;
|
|
213
|
-
const rng = createRng(seed);
|
|
214
|
-
|
|
215
|
-
const htmlBody = `<html><body><p>seed-${seed}-${randomTag(rng)}</p></body></html>`;
|
|
216
|
-
const octetBody = `octet-${seed}-${randomTag(rng)}`;
|
|
217
|
-
|
|
218
|
-
const tree: MultipartNode = {
|
|
219
|
-
kind: "multipart",
|
|
220
|
-
subtype: "mixed",
|
|
221
|
-
children: [
|
|
222
|
-
{
|
|
223
|
-
kind: "leaf",
|
|
224
|
-
contentType: "text/html",
|
|
225
|
-
bytes: Buffer.from(htmlBody, "utf8"),
|
|
226
|
-
},
|
|
227
|
-
{
|
|
228
|
-
kind: "leaf",
|
|
229
|
-
contentType: "application/octet-stream",
|
|
230
|
-
bytes: Buffer.from(octetBody, "utf8"),
|
|
231
|
-
// no filename, no contentId, no disposition
|
|
232
|
-
},
|
|
233
|
-
],
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
const eml = renderEml(tree, { seed });
|
|
237
|
-
const bodyParts = treeToBodyParts(tree);
|
|
238
|
-
const parsed = await simpleParser(eml);
|
|
239
|
-
const pairs = mapBodyPartsToContent(bodyParts, parsed);
|
|
240
|
-
|
|
241
|
-
assert.equal(pairs.length, 2, `seed=${seed}: expected 2 pairs`);
|
|
242
|
-
|
|
243
|
-
const htmlPair = pairs.find((p) => p.partPath === "1");
|
|
244
|
-
const octetPair = pairs.find((p) => p.partPath === "2");
|
|
245
|
-
assert.ok(htmlPair, `seed=${seed}: missing html pair`);
|
|
246
|
-
assert.ok(octetPair, `seed=${seed}: missing octet pair`);
|
|
247
|
-
|
|
248
|
-
// html leaf gets the html body (text-routing slot).
|
|
249
|
-
const htmlStr = htmlPair.content.toString("utf8");
|
|
250
|
-
assert.ok(
|
|
251
|
-
htmlStr.includes(`seed-${seed}-`),
|
|
252
|
-
`seed=${seed}: html pair lost its body (got "${htmlStr.slice(0, 80)}")`,
|
|
253
|
-
);
|
|
254
|
-
|
|
255
|
-
// octet leaf must NOT contain the html body's marker.
|
|
256
|
-
const octetStr = octetPair.content.toString("utf8");
|
|
257
|
-
assert.ok(
|
|
258
|
-
!octetStr.includes("<html>"),
|
|
259
|
-
`seed=${seed}: octet pair swallowed html bytes (got "${octetStr.slice(0, 80)}")`,
|
|
260
|
-
);
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Inline `cid:` casing + angle-bracket insensitivity. PR B's
|
|
267
|
-
* `findByContentId` strips angle brackets and lowercases both sides, so a
|
|
268
|
-
* BODYSTRUCTURE row with `contentId: "Logo@Example.ORG"` should still pair
|
|
269
|
-
* with a mailparser attachment whose `cid` is `<logo@example.org>` (or any
|
|
270
|
-
* mixed-case variant with/without brackets). We assert the image leaf
|
|
271
|
-
* receives the image bytes — not the html ones — across random
|
|
272
|
-
* permutations.
|
|
273
|
-
*/
|
|
274
|
-
describe("body-part-mapper property: cid casing + angle-bracket insensitivity", () => {
|
|
275
|
-
it("pairs inline image with mixed-case bracketed contentId", async () => {
|
|
276
|
-
const baseSeed = parseSeed() ^ 0xc3c3c3c3;
|
|
277
|
-
|
|
278
|
-
for (let i = 0; i < TARGETED_ITERATIONS; i++) {
|
|
279
|
-
const seed = (baseSeed ^ i) | 0;
|
|
280
|
-
const rng = createRng(seed);
|
|
281
|
-
|
|
282
|
-
const localPart = `hero-${randomTag(rng)}`;
|
|
283
|
-
const domain = "example.org";
|
|
284
|
-
const baseCid = `${localPart}@${domain}`;
|
|
285
|
-
|
|
286
|
-
// Random-case for the BodyPart row's contentId. Sometimes wrapped in
|
|
287
|
-
// `< >`, sometimes not. The leaf's actual Content-ID header (rendered
|
|
288
|
-
// into the EML) is always lower-case with angles — that's what
|
|
289
|
-
// mailparser sees.
|
|
290
|
-
const rowCid = (() => {
|
|
291
|
-
const cased = [...baseCid]
|
|
292
|
-
.map((c) => (rng.bool(0.4) ? c.toUpperCase() : c.toLowerCase()))
|
|
293
|
-
.join("");
|
|
294
|
-
return rng.bool(0.5) ? `<${cased}>` : cased;
|
|
295
|
-
})();
|
|
296
|
-
|
|
297
|
-
const imageBytes = Buffer.from(`png-${seed}-${randomTag(rng)}`, "utf8");
|
|
298
|
-
|
|
299
|
-
const tree: MultipartNode = {
|
|
300
|
-
kind: "multipart",
|
|
301
|
-
subtype: "related",
|
|
302
|
-
children: [
|
|
303
|
-
{
|
|
304
|
-
kind: "leaf",
|
|
305
|
-
contentType: "text/html",
|
|
306
|
-
bytes: Buffer.from(`<img src="cid:${baseCid}">`, "utf8"),
|
|
307
|
-
},
|
|
308
|
-
{
|
|
309
|
-
kind: "leaf",
|
|
310
|
-
contentType: "image/png",
|
|
311
|
-
bytes: imageBytes,
|
|
312
|
-
contentId: baseCid, // leaf header always normalised; mailparser sees this
|
|
313
|
-
disposition: "inline",
|
|
314
|
-
},
|
|
315
|
-
],
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
const eml = renderEml(tree, { seed });
|
|
319
|
-
// Swap the row's contentId for the random-cased / bracketed variant —
|
|
320
|
-
// simulating what BODYSTRUCTURE might persist after a sloppy sender.
|
|
321
|
-
// MapperInput rows are typed as readonly via `Pick<BodyPartItem,...>`
|
|
322
|
-
// so we rebuild the row rather than mutating in place.
|
|
323
|
-
const bodyParts = treeToBodyParts(tree).map((row) =>
|
|
324
|
-
row.mediaType === "IMAGE" ? { ...row, contentId: rowCid } : row,
|
|
325
|
-
);
|
|
326
|
-
const imageRow = bodyParts.find((p) => p.mediaType === "IMAGE");
|
|
327
|
-
assert.ok(imageRow, `seed=${seed}: missing image row in body parts`);
|
|
328
|
-
|
|
329
|
-
const parsed = await simpleParser(eml);
|
|
330
|
-
const pairs = mapBodyPartsToContent(bodyParts, parsed);
|
|
331
|
-
|
|
332
|
-
assert.equal(pairs.length, 2, `seed=${seed}: expected 2 pairs`);
|
|
333
|
-
|
|
334
|
-
const imagePair = pairs.find((p) => p.partPath === "2");
|
|
335
|
-
assert.ok(imagePair, `seed=${seed}: missing image pair`);
|
|
336
|
-
assert.equal(
|
|
337
|
-
imagePair.content.toString("utf8"),
|
|
338
|
-
imageBytes.toString("utf8"),
|
|
339
|
-
`seed=${seed}: image pair did not receive image bytes (rowCid=${rowCid})`,
|
|
340
|
-
);
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
/* -------------------------------------------------------------------- */
|
|
346
|
-
/* Helpers */
|
|
347
|
-
/* -------------------------------------------------------------------- */
|
|
348
|
-
|
|
349
|
-
const randomTag = (rng: { int: (n: number) => number }): string => {
|
|
350
|
-
const letters = "abcdefghijklmnopqrstuvwxyz";
|
|
351
|
-
let s = "";
|
|
352
|
-
for (let i = 0; i < 6; i++) s += letters[rng.int(letters.length)];
|
|
353
|
-
return s;
|
|
354
|
-
};
|