@chainlesschain/personal-data-hub 0.4.29 → 0.4.30
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/lib/prompt-builder.js +15 -1
- package/package.json +4 -1
- package/__tests__/adapter-guide.test.js +0 -47
- package/__tests__/adapter-spec.test.js +0 -78
- package/__tests__/adapters/ai-chat-cookie-capture-spec.test.js +0 -211
- package/__tests__/adapters/ai-chat-health-checker.test.js +0 -262
- package/__tests__/adapters/ai-chat-history.test.js +0 -396
- package/__tests__/adapters/ai-chat-http-client.test.js +0 -242
- package/__tests__/adapters/ai-chat-vendors.test.js +0 -874
- package/__tests__/adapters/alipay-bill-adapter.test.js +0 -538
- package/__tests__/adapters/apple-health.test.js +0 -95
- package/__tests__/adapters/bank-family.test.js +0 -125
- package/__tests__/adapters/biz-tianyancha.test.js +0 -159
- package/__tests__/adapters/browser-history-chrome.test.js +0 -377
- package/__tests__/adapters/browser-history-edge.test.js +0 -159
- package/__tests__/adapters/car-mercedesme.test.js +0 -74
- package/__tests__/adapters/doc-baidu-netdisk.test.js +0 -102
- package/__tests__/adapters/doc-camscanner.test.js +0 -147
- package/__tests__/adapters/doc-platforms.test.js +0 -177
- package/__tests__/adapters/edu-huawei-learning-live.test.js +0 -198
- package/__tests__/adapters/edu-zuoyebang-live.test.js +0 -226
- package/__tests__/adapters/email-adapter-snapshot.test.js +0 -237
- package/__tests__/adapters/email-adapter.test.js +0 -742
- package/__tests__/adapters/email-classifier.test.js +0 -347
- package/__tests__/adapters/email-imap-session.test.js +0 -334
- package/__tests__/adapters/email-parser.test.js +0 -244
- package/__tests__/adapters/email-pdf-extractor.test.js +0 -529
- package/__tests__/adapters/email-providers.test.js +0 -84
- package/__tests__/adapters/email-retry-progress.test.js +0 -294
- package/__tests__/adapters/email-templates.test.js +0 -822
- package/__tests__/adapters/family-23-collectors-scaffold.test.js +0 -182
- package/__tests__/adapters/finance-alipay-live.test.js +0 -258
- package/__tests__/adapters/finance-dcep.test.js +0 -74
- package/__tests__/adapters/fitness-joyrun.test.js +0 -82
- package/__tests__/adapters/game-genshin-live.test.js +0 -238
- package/__tests__/adapters/game-genshin-scaffold.test.js +0 -108
- package/__tests__/adapters/game-honor-of-kings-live.test.js +0 -230
- package/__tests__/adapters/git-activity.test.js +0 -222
- package/__tests__/adapters/gov-12123.test.js +0 -103
- package/__tests__/adapters/gov-ixiamen.test.js +0 -150
- package/__tests__/adapters/gov-tax.test.js +0 -135
- package/__tests__/adapters/health-meiyou.test.js +0 -125
- package/__tests__/adapters/local-files.test.js +0 -264
- package/__tests__/adapters/local-im-pc.test.js +0 -154
- package/__tests__/adapters/messaging-whatsapp.test.js +0 -289
- package/__tests__/adapters/music-kugou.test.js +0 -187
- package/__tests__/adapters/music-qq.test.js +0 -112
- package/__tests__/adapters/netease-music-live.test.js +0 -244
- package/__tests__/adapters/netease-music.test.js +0 -74
- package/__tests__/adapters/pc-local-discovery.test.js +0 -141
- package/__tests__/adapters/qq-pc-direct-read.test.js +0 -227
- package/__tests__/adapters/reading-family.test.js +0 -108
- package/__tests__/adapters/recruit-boss.test.js +0 -180
- package/__tests__/adapters/shell-history.test.js +0 -180
- package/__tests__/adapters/shopping-base.test.js +0 -179
- package/__tests__/adapters/shopping-dianping.test.js +0 -239
- package/__tests__/adapters/social-bilibili-adb-api-client.test.js +0 -721
- package/__tests__/adapters/social-bilibili-adb-chromium-cookies-reader.test.js +0 -346
- package/__tests__/adapters/social-bilibili-adb-collector.test.js +0 -284
- package/__tests__/adapters/social-bilibili-adb-cookies-extension.test.js +0 -343
- package/__tests__/adapters/social-bilibili-adb-snapshot-builder.test.js +0 -296
- package/__tests__/adapters/social-csdn.test.js +0 -175
- package/__tests__/adapters/social-dongchedi.test.js +0 -165
- package/__tests__/adapters/social-douyin-adb-aweme-detail.test.js +0 -165
- package/__tests__/adapters/social-douyin-adb-collector.test.js +0 -254
- package/__tests__/adapters/social-douyin-adb-db-extension.test.js +0 -114
- package/__tests__/adapters/social-douyin-adb-im-db-parser.test.js +0 -304
- package/__tests__/adapters/social-douyin-adb-snapshot-builder.test.js +0 -216
- package/__tests__/adapters/social-douyin-adb-usage-profile.test.js +0 -229
- package/__tests__/adapters/social-douyin-adb-watch-history.test.js +0 -269
- package/__tests__/adapters/social-kuaishou-adb-api-client.test.js +0 -496
- package/__tests__/adapters/social-kuaishou-adb-collector.test.js +0 -276
- package/__tests__/adapters/social-kuaishou-adb-cookies-extension.test.js +0 -152
- package/__tests__/adapters/social-kuaishou-adb-snapshot-builder.test.js +0 -178
- package/__tests__/adapters/social-toutiao-adb-account-reader.test.js +0 -135
- package/__tests__/adapters/social-toutiao-adb-api-client.test.js +0 -626
- package/__tests__/adapters/social-toutiao-adb-article.test.js +0 -155
- package/__tests__/adapters/social-toutiao-adb-collector.test.js +0 -378
- package/__tests__/adapters/social-toutiao-adb-cookies-extension.test.js +0 -193
- package/__tests__/adapters/social-toutiao-adb-snapshot-builder.test.js +0 -196
- package/__tests__/adapters/social-toutiao-kuaishou-scaffold.test.js +0 -311
- package/__tests__/adapters/social-weibo-adb-api-client.test.js +0 -362
- package/__tests__/adapters/social-weibo-adb-collector.test.js +0 -201
- package/__tests__/adapters/social-weibo-adb-cookies-extension.test.js +0 -167
- package/__tests__/adapters/social-weibo-adb-snapshot-builder.test.js +0 -189
- package/__tests__/adapters/social-xiaohongshu-adb-api-client.test.js +0 -431
- package/__tests__/adapters/social-xiaohongshu-adb-collector.test.js +0 -207
- package/__tests__/adapters/social-xiaohongshu-adb-cookies-extension.test.js +0 -0
- package/__tests__/adapters/social-xiaohongshu-adb-sign-provider-injection.test.js +0 -351
- package/__tests__/adapters/social-xiaohongshu-adb-sign.test.js +0 -130
- package/__tests__/adapters/social-xiaohongshu-adb-snapshot-builder.test.js +0 -200
- package/__tests__/adapters/social-zhihu.test.js +0 -246
- package/__tests__/adapters/system-data-adapter.test.js +0 -443
- package/__tests__/adapters/system-data-android-ingest.test.js +0 -144
- package/__tests__/adapters/system-data-android.test.js +0 -519
- package/__tests__/adapters/system-data-disclosure.test.js +0 -153
- package/__tests__/adapters/travel-12306.test.js +0 -512
- package/__tests__/adapters/travel-amap.test.js +0 -219
- package/__tests__/adapters/travel-baidu-map.test.js +0 -305
- package/__tests__/adapters/travel-base.test.js +0 -205
- package/__tests__/adapters/travel-ctrip.test.js +0 -377
- package/__tests__/adapters/travel-didi-consumer.test.js +0 -66
- package/__tests__/adapters/travel-didi.test.js +0 -204
- package/__tests__/adapters/travel-tencent-map.test.js +0 -207
- package/__tests__/adapters/travel-tongcheng.test.js +0 -289
- package/__tests__/adapters/video-platforms.test.js +0 -152
- package/__tests__/adapters/video-xigua.test.js +0 -106
- package/__tests__/adapters/vscode.test.js +0 -299
- package/__tests__/adapters/wechat-bootstrap.test.js +0 -240
- package/__tests__/adapters/wechat-env-probe.test.js +0 -162
- package/__tests__/adapters/wechat-frida-agent.test.js +0 -322
- package/__tests__/adapters/wechat-frida-integration.test.js +0 -149
- package/__tests__/adapters/wechat-frida-key-provider.test.js +0 -188
- package/__tests__/adapters/wechat-md5-key-provider.test.js +0 -101
- package/__tests__/adapters/wechat-pc-direct-read.test.js +0 -365
- package/__tests__/adapters/wechat-pc-group-topic.test.js +0 -63
- package/__tests__/adapters/wechat-pc-v4-sidecar.test.js +0 -72
- package/__tests__/adapters/weread.test.js +0 -123
- package/__tests__/adapters/wework-pc.test.js +0 -124
- package/__tests__/adapters/win-recent.test.js +0 -192
- package/__tests__/analysis-skills.test.js +0 -754
- package/__tests__/analysis.test.js +0 -1845
- package/__tests__/audio-ximalaya-snapshot.test.js +0 -279
- package/__tests__/batch.test.js +0 -133
- package/__tests__/bridges-cc-kg.test.js +0 -231
- package/__tests__/bridges-cc-llm.test.js +0 -191
- package/__tests__/bridges-cc-rag.test.js +0 -162
- package/__tests__/categories.test.js +0 -92
- package/__tests__/e2e/ai-chat-cross-source-journey.test.js +0 -213
- package/__tests__/e2e/full-user-journey.test.js +0 -188
- package/__tests__/e2e/local-data-adapters-cli.e2e.test.js +0 -146
- package/__tests__/entity-resolver-ingest-hook.test.js +0 -177
- package/__tests__/entity-resolver-stages.test.js +0 -411
- package/__tests__/entity-resolver-vault.test.js +0 -249
- package/__tests__/entity-resolver.test.js +0 -526
- package/__tests__/fitness-keep-snapshot.test.js +0 -224
- package/__tests__/fixtures/entity-resolver-200-mock.json +0 -96
- package/__tests__/ids.test.js +0 -45
- package/__tests__/integration/ai-chat-history-registry.test.js +0 -228
- package/__tests__/integration/aichat-wizard-end-to-end.test.js +0 -282
- package/__tests__/integration/cross-adapter-pipelines.test.js +0 -396
- package/__tests__/integration/local-data-adapters-pipeline.test.js +0 -373
- package/__tests__/integration/social-bilibili-pipeline.test.js +0 -261
- package/__tests__/integration/wechat-bootstrap-end-to-end.test.js +0 -390
- package/__tests__/key-providers.test.js +0 -126
- package/__tests__/kg-derive.test.js +0 -219
- package/__tests__/llm-client.test.js +0 -122
- package/__tests__/longtail-adapters.test.js +0 -281
- package/__tests__/messaging-qq-snapshot.test.js +0 -294
- package/__tests__/mobile-extractor-encrypted.test.js +0 -460
- package/__tests__/mobile-extractor.test.js +0 -288
- package/__tests__/mock-adapter.test.js +0 -93
- package/__tests__/prompt-builder.test.js +0 -249
- package/__tests__/query-parser.test.js +0 -365
- package/__tests__/rag-derive.test.js +0 -169
- package/__tests__/registry-readiness.test.js +0 -292
- package/__tests__/registry.test.js +0 -420
- package/__tests__/salvage-ingest.test.js +0 -97
- package/__tests__/schemas.test.js +0 -331
- package/__tests__/shopping-adapters.test.js +0 -392
- package/__tests__/shopping-eleme-snapshot.test.js +0 -454
- package/__tests__/shopping-pinduoduo-snapshot.test.js +0 -484
- package/__tests__/shopping-snapshot.test.js +0 -438
- package/__tests__/shopping-vipshop-snapshot.test.js +0 -425
- package/__tests__/shopping-xianyu-snapshot.test.js +0 -451
- package/__tests__/sidecar-contacts-cross-validate.test.js +0 -186
- package/__tests__/sidecar-supervisor.test.js +0 -128
- package/__tests__/sign-providers.test.js +0 -62
- package/__tests__/social-adapters.test.js +0 -280
- package/__tests__/social-bilibili-snapshot.test.js +0 -278
- package/__tests__/social-douban-snapshot.test.js +0 -351
- package/__tests__/social-douyin-im-direct-read.test.js +0 -377
- package/__tests__/social-douyin-salvage-collector.test.js +0 -98
- package/__tests__/social-douyin-salvage-mapper.test.js +0 -90
- package/__tests__/social-douyin-snapshot.test.js +0 -256
- package/__tests__/social-kuaishou-snapshot.test.js +0 -362
- package/__tests__/social-toutiao-snapshot.test.js +0 -366
- package/__tests__/social-weibo-snapshot.test.js +0 -234
- package/__tests__/social-weibo-sqlite-device.test.js +0 -174
- package/__tests__/social-xiaohongshu-snapshot.test.js +0 -232
- package/__tests__/sqlite-leaf-salvage.test.js +0 -97
- package/__tests__/travel-adapters.test.js +0 -483
- package/__tests__/travel-maps-snapshot.test.js +0 -426
- package/__tests__/vault-driver-error.test.js +0 -74
- package/__tests__/vault-search-helpers.test.js +0 -104
- package/__tests__/vault-search.test.js +0 -423
- package/__tests__/vault.test.js +0 -767
- package/__tests__/wechat-adapter.test.js +0 -594
- package/__tests__/whatsapp-adapter.test.js +0 -138
- package/scripts/_make-fixture-all.js +0 -126
- package/scripts/_make-fixture-contacts.js +0 -84
- package/scripts/evaluate-entity-resolver.js +0 -213
- package/scripts/run-native-tests-sandbox.sh +0 -55
- package/scripts/smoke-phase-5-5.js +0 -196
- package/scripts/smoke-phase-5-7.js +0 -181
- package/scripts/smoke-system-data-contacts.js +0 -309
- package/scripts/smoke-system-data.js +0 -312
- package/vitest.config.js +0 -88
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { describe, it, expect } from "vitest";
|
|
4
|
-
|
|
5
|
-
const { parseRawEmail } = require("../../lib/adapters/email-imap/email-parser");
|
|
6
|
-
|
|
7
|
-
// ─── Fixture builders ───────────────────────────────────────────────────
|
|
8
|
-
|
|
9
|
-
function plaintextEmail({
|
|
10
|
-
from = "alice@example.com",
|
|
11
|
-
to = "bob@example.com",
|
|
12
|
-
subject = "Hello",
|
|
13
|
-
body = "Hello, world!",
|
|
14
|
-
date = "Fri, 19 May 2026 10:00:00 +0800",
|
|
15
|
-
messageId = "<m-1@example.com>",
|
|
16
|
-
} = {}) {
|
|
17
|
-
return [
|
|
18
|
-
`From: ${from}`,
|
|
19
|
-
`To: ${to}`,
|
|
20
|
-
`Subject: ${subject}`,
|
|
21
|
-
`Date: ${date}`,
|
|
22
|
-
`Message-ID: ${messageId}`,
|
|
23
|
-
`Content-Type: text/plain; charset=utf-8`,
|
|
24
|
-
`Content-Transfer-Encoding: 7bit`,
|
|
25
|
-
``,
|
|
26
|
-
body,
|
|
27
|
-
].join("\r\n");
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function multipartAlternative({ text = "plain version", html = "<p>html <b>version</b></p>" } = {}) {
|
|
31
|
-
const boundary = "BOUNDARY_42";
|
|
32
|
-
return [
|
|
33
|
-
`From: sender@example.com`,
|
|
34
|
-
`To: me@example.com`,
|
|
35
|
-
`Subject: Multipart`,
|
|
36
|
-
`MIME-Version: 1.0`,
|
|
37
|
-
`Content-Type: multipart/alternative; boundary="${boundary}"`,
|
|
38
|
-
``,
|
|
39
|
-
`--${boundary}`,
|
|
40
|
-
`Content-Type: text/plain; charset=utf-8`,
|
|
41
|
-
``,
|
|
42
|
-
text,
|
|
43
|
-
`--${boundary}`,
|
|
44
|
-
`Content-Type: text/html; charset=utf-8`,
|
|
45
|
-
``,
|
|
46
|
-
html,
|
|
47
|
-
`--${boundary}--`,
|
|
48
|
-
].join("\r\n");
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function multipartWithAttachment({ filename = "report.pdf", contentType = "application/pdf", body = "%PDF-1.4\n/Encrypt placeholder\n" } = {}) {
|
|
52
|
-
const boundary = "MIXED_99";
|
|
53
|
-
const b64 = Buffer.from(body).toString("base64");
|
|
54
|
-
return [
|
|
55
|
-
`From: bank@example.com`,
|
|
56
|
-
`To: me@example.com`,
|
|
57
|
-
`Subject: Your statement`,
|
|
58
|
-
`MIME-Version: 1.0`,
|
|
59
|
-
`Content-Type: multipart/mixed; boundary="${boundary}"`,
|
|
60
|
-
``,
|
|
61
|
-
`--${boundary}`,
|
|
62
|
-
`Content-Type: text/plain`,
|
|
63
|
-
``,
|
|
64
|
-
`See attached statement.`,
|
|
65
|
-
`--${boundary}`,
|
|
66
|
-
`Content-Type: ${contentType}; name="${filename}"`,
|
|
67
|
-
`Content-Disposition: attachment; filename="${filename}"`,
|
|
68
|
-
`Content-Transfer-Encoding: base64`,
|
|
69
|
-
``,
|
|
70
|
-
b64,
|
|
71
|
-
`--${boundary}--`,
|
|
72
|
-
].join("\r\n");
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// ─── parseRawEmail ──────────────────────────────────────────────────────
|
|
76
|
-
|
|
77
|
-
describe("parseRawEmail — basic shape", () => {
|
|
78
|
-
it("rejects null/missing input", async () => {
|
|
79
|
-
await expect(parseRawEmail(null)).rejects.toThrow(/required/);
|
|
80
|
-
await expect(parseRawEmail()).rejects.toThrow(/required/);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("accepts a Buffer", async () => {
|
|
84
|
-
const buf = Buffer.from(plaintextEmail(), "utf8");
|
|
85
|
-
const r = await parseRawEmail(buf);
|
|
86
|
-
expect(r.subject).toBe("Hello");
|
|
87
|
-
expect(r.textBody).toContain("Hello, world!");
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it("accepts a string", async () => {
|
|
91
|
-
const r = await parseRawEmail(plaintextEmail());
|
|
92
|
-
expect(r.subject).toBe("Hello");
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it("returns sourceBytes + contentSha256", async () => {
|
|
96
|
-
const raw = plaintextEmail();
|
|
97
|
-
const r = await parseRawEmail(raw);
|
|
98
|
-
expect(r.sourceBytes).toBe(Buffer.byteLength(raw));
|
|
99
|
-
expect(r.contentSha256).toMatch(/^[0-9a-f]{64}$/);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it("flattens headers to lowercased-keyed object", async () => {
|
|
103
|
-
const r = await parseRawEmail(plaintextEmail());
|
|
104
|
-
expect(r.headers["subject"]).toBe("Hello");
|
|
105
|
-
expect(r.headers["from"]).toBeDefined();
|
|
106
|
-
expect(r.headers["message-id"]).toBe("<m-1@example.com>");
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it("parses Date header", async () => {
|
|
110
|
-
const r = await parseRawEmail(plaintextEmail());
|
|
111
|
-
expect(r.date).toBeInstanceOf(Date);
|
|
112
|
-
expect(r.date.getUTCFullYear()).toBe(2026);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
describe("parseRawEmail — multipart", () => {
|
|
117
|
-
it("multipart/alternative yields both text + html bodies", async () => {
|
|
118
|
-
const r = await parseRawEmail(multipartAlternative());
|
|
119
|
-
expect(r.textBody).toContain("plain version");
|
|
120
|
-
expect(r.htmlBody).toContain("html");
|
|
121
|
-
expect(r.htmlBody).toContain("version");
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it("multipart/mixed with attachment yields attachment metadata", async () => {
|
|
125
|
-
const r = await parseRawEmail(multipartWithAttachment());
|
|
126
|
-
expect(r.attachments).toHaveLength(1);
|
|
127
|
-
const a = r.attachments[0];
|
|
128
|
-
expect(a.filename).toBe("report.pdf");
|
|
129
|
-
expect(a.contentType).toContain("pdf");
|
|
130
|
-
expect(a.size).toBeGreaterThan(0);
|
|
131
|
-
expect(a.sha256).toMatch(/^[0-9a-f]{64}$/);
|
|
132
|
-
expect(a.contentDisposition).toBe("attachment");
|
|
133
|
-
expect(a.isInline).toBe(false);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it("flags encrypted PDFs heuristically (/Encrypt header in body)", async () => {
|
|
137
|
-
const r = await parseRawEmail(multipartWithAttachment({
|
|
138
|
-
filename: "encrypted.pdf",
|
|
139
|
-
body: "%PDF-1.4\n%fake header\n/Encrypt <<\n/V 4\n>>\n",
|
|
140
|
-
}));
|
|
141
|
-
expect(r.attachments[0].isEncrypted).toBe(true);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it("doesn't flag plaintext PDFs as encrypted", async () => {
|
|
145
|
-
const r = await parseRawEmail(multipartWithAttachment({
|
|
146
|
-
body: "%PDF-1.4\nplain content no encrypt token\n",
|
|
147
|
-
}));
|
|
148
|
-
expect(r.attachments[0].isEncrypted).toBe(false);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it("attachment buffer is omitted by default", async () => {
|
|
152
|
-
const r = await parseRawEmail(multipartWithAttachment());
|
|
153
|
-
expect(r.attachments[0].buffer).toBeUndefined();
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it("keepAttachmentBuffers:true attaches the decoded buffer", async () => {
|
|
157
|
-
const r = await parseRawEmail(multipartWithAttachment(), { keepAttachmentBuffers: true });
|
|
158
|
-
expect(Buffer.isBuffer(r.attachments[0].buffer)).toBe(true);
|
|
159
|
-
expect(r.attachments[0].buffer.toString()).toContain("%PDF-1.4");
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
describe("parseRawEmail — encoding handling", () => {
|
|
164
|
-
it("decodes UTF-8 body correctly", async () => {
|
|
165
|
-
const utf8Body = "妈妈生日蛋白粉 ¥288.50";
|
|
166
|
-
const r = await parseRawEmail(plaintextEmail({ body: utf8Body }));
|
|
167
|
-
expect(r.textBody).toContain("妈妈生日蛋白粉");
|
|
168
|
-
expect(r.textBody).toContain("¥288.50");
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it("decodes GBK-encoded body (via Content-Type charset)", async () => {
|
|
172
|
-
// Build raw bytes: header in UTF-8, body in GBK.
|
|
173
|
-
const headerAscii =
|
|
174
|
-
`From: sender@example.com\r\n` +
|
|
175
|
-
`To: me@example.com\r\n` +
|
|
176
|
-
`Subject: 中文\r\n` +
|
|
177
|
-
`MIME-Version: 1.0\r\n` +
|
|
178
|
-
`Content-Type: text/plain; charset=GBK\r\n\r\n`;
|
|
179
|
-
// GBK bytes for "妈妈生日": dc e8 dc e8 c9 fa c8 d5
|
|
180
|
-
const gbkBody = Buffer.from([0xc2, 0xe8, 0xc2, 0xe8, 0xc9, 0xfa, 0xc8, 0xd5]);
|
|
181
|
-
const raw = Buffer.concat([Buffer.from(headerAscii, "ascii"), gbkBody]);
|
|
182
|
-
const r = await parseRawEmail(raw);
|
|
183
|
-
// mailparser+iconv-lite converts GBK to UTF-8. We can't assert exact
|
|
184
|
-
// unicode without locking in iconv tables, but we can verify the
|
|
185
|
-
// body is non-empty + got past the GBK byte sequence (which is
|
|
186
|
-
// invalid UTF-8 — would error if left as raw).
|
|
187
|
-
expect(r.textBody.length).toBeGreaterThan(0);
|
|
188
|
-
expect(r.headers["content-type"]).toBeDefined();
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it("RFC 2047 encoded subject is decoded", async () => {
|
|
192
|
-
const raw = [
|
|
193
|
-
`From: alice@example.com`,
|
|
194
|
-
`To: me@example.com`,
|
|
195
|
-
// =?UTF-8?B?5aaI5aaIc/eIuOWlh+aBpQ==?= (just a sample base64)
|
|
196
|
-
`Subject: =?UTF-8?B?5aaI5aaI?=`,
|
|
197
|
-
`Date: Fri, 19 May 2026 10:00:00 +0800`,
|
|
198
|
-
`Message-ID: <m@x>`,
|
|
199
|
-
`Content-Type: text/plain; charset=utf-8`,
|
|
200
|
-
``,
|
|
201
|
-
`body`,
|
|
202
|
-
].join("\r\n");
|
|
203
|
-
const r = await parseRawEmail(raw);
|
|
204
|
-
expect(r.subject).toBe("妈妈");
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
describe("parseRawEmail — truncation + edge cases", () => {
|
|
209
|
-
it("truncates bodies longer than maxBodyChars", async () => {
|
|
210
|
-
const longBody = "X".repeat(500_000);
|
|
211
|
-
const r = await parseRawEmail(plaintextEmail({ body: longBody }), { maxBodyChars: 1000 });
|
|
212
|
-
expect(r.textBody.length).toBeLessThan(longBody.length);
|
|
213
|
-
expect(r.textBody).toMatch(/truncated/);
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it("returns empty bodies for emails with no payload", async () => {
|
|
217
|
-
const raw = [
|
|
218
|
-
`From: x@x.com`,
|
|
219
|
-
`To: y@y.com`,
|
|
220
|
-
`Subject: empty`,
|
|
221
|
-
`Date: Fri, 19 May 2026 10:00:00 +0800`,
|
|
222
|
-
`Message-ID: <m@x>`,
|
|
223
|
-
``,
|
|
224
|
-
``,
|
|
225
|
-
].join("\r\n");
|
|
226
|
-
const r = await parseRawEmail(raw);
|
|
227
|
-
expect(r.textBody).toBe("");
|
|
228
|
-
expect(r.htmlBody).toBe("");
|
|
229
|
-
expect(r.attachments).toEqual([]);
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
it("contentSha256 is deterministic for identical input", async () => {
|
|
233
|
-
const raw = plaintextEmail();
|
|
234
|
-
const r1 = await parseRawEmail(raw);
|
|
235
|
-
const r2 = await parseRawEmail(raw);
|
|
236
|
-
expect(r1.contentSha256).toBe(r2.contentSha256);
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
it("contentSha256 differs across different inputs", async () => {
|
|
240
|
-
const r1 = await parseRawEmail(plaintextEmail({ body: "v1" }));
|
|
241
|
-
const r2 = await parseRawEmail(plaintextEmail({ body: "v2" }));
|
|
242
|
-
expect(r1.contentSha256).not.toBe(r2.contentSha256);
|
|
243
|
-
});
|
|
244
|
-
});
|