@file-viewer/renderer-email 3.1.2 → 3.2.0
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/README.en.md +3 -70
- package/README.md +3 -70
- package/dist/email.js +4 -6
- package/dist/emailHtml.d.ts +0 -4
- package/dist/emailHtml.js +2 -16
- package/dist/msg.d.ts +0 -5
- package/dist/msg.js +0 -13
- package/dist/msgCfb.d.ts +0 -3
- package/dist/msgCfb.js +0 -3
- package/dist/msgEncoding.d.ts +0 -1
- package/dist/msgEncoding.js +1 -2
- package/dist/msgRtf.d.ts +0 -4
- package/dist/msgRtf.js +0 -5
- package/package.json +29 -22
package/README.en.md
CHANGED
|
@@ -1,74 +1,7 @@
|
|
|
1
1
|
# @file-viewer/renderer-email
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Runtime package version 3.2.0.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Usage and API documentation: https://doc.file-viewer.app/guide/on-demand-renderers
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
import { FileViewer } from '@file-viewer/vue3'
|
|
9
|
-
import { emailRenderer } from '@file-viewer/renderer-email'
|
|
10
|
-
|
|
11
|
-
const options = {
|
|
12
|
-
builtinRenderers: 'none',
|
|
13
|
-
renderers: emailRenderer,
|
|
14
|
-
}
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
Pass a real `File` named `message.msg`, or a URL with the original filename. The existing email route selects the MSG parser lazily; EML/MBOX do not import the MSG decoder.
|
|
18
|
-
|
|
19
|
-
For attachment previews, compose the corresponding PDF, image, Word and other renderers. The host supplies the standard `renderNestedBuffer` callback. Embedded Outlook messages are extracted as `.msg`, not renamed to text; original attachment bytes are retained for download.
|
|
20
|
-
|
|
21
|
-
### Rich-text Outlook messages
|
|
22
|
-
|
|
23
|
-
The full preset already includes the Word renderer and RTF capability:
|
|
24
|
-
|
|
25
|
-
```ts
|
|
26
|
-
import allRenderers from '@file-viewer/preset-all'
|
|
27
|
-
const options = { preset: allRenderers }
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
For a selective integration, install `@file-viewer/renderer-word` and `@file-viewer/capability-rtf` alongside the email renderer:
|
|
31
|
-
|
|
32
|
-
```ts
|
|
33
|
-
import { emailRenderer } from '@file-viewer/renderer-email'
|
|
34
|
-
import { wordRenderer } from '@file-viewer/renderer-word'
|
|
35
|
-
import '@file-viewer/capability-rtf'
|
|
36
|
-
|
|
37
|
-
const options = {
|
|
38
|
-
builtinRenderers: 'none',
|
|
39
|
-
renderers: [emailRenderer, wordRenderer],
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
Compressed RTF is decompressed locally. HTML-encapsulated RTF can supply an HTML body; ordinary rich RTF uses the existing RTF.js capability through the nested renderer contract. An email-only installation retains readable plain text with a notice when rich rendering is unavailable. Email RTF always blocks external resources and links, even when the host opts into them for other document types.
|
|
44
|
-
|
|
45
|
-
## Outlook MSG coverage
|
|
46
|
-
|
|
47
|
-
- Unicode and ANSI properties; Outlook codepages, Unicode `bodyHtml` and binary `html`, BOM and HTML charset handling.
|
|
48
|
-
- Subject, From, on-behalf-of Sender, separate To/Cc/Bcc, submission/delivery time, original transport headers and a clearly labeled metadata fallback for drafts.
|
|
49
|
-
- HTML, plain text and RTF body switching; tables, authored styles and local CID/Content-Location raster images.
|
|
50
|
-
- MIME-aware attachment names, lazy binary extraction, downloads and nested MSG preview. Unknown sizes are shown as unknown until extraction, not as zero bytes.
|
|
51
|
-
- Body uses the available height until an attachment opens. Closing an attachment restores body space and keyboard focus. Pending views and owned object URLs are cleaned up on replacement, cancellation and unmount.
|
|
52
|
-
- Simplified Chinese, English, Japanese and German notices follow the viewer locale. Narrow-host layout and light/dark presentation are supported.
|
|
53
|
-
|
|
54
|
-
EML/MBOX remain on `postal-mime`; MBOX still previews its first message and reports the count rather than implementing a mailbox browser.
|
|
55
|
-
|
|
56
|
-
## Privacy, limits and compatibility
|
|
57
|
-
|
|
58
|
-
Email HTML is read-only in an empty-sandbox iframe. Sanitization and a restrictive CSP block scripts, forms, embedded documents, local paths, external stylesheets, fonts, tracking images and remote resource requests. Only owned local image resources and raster image data URLs are allowed. External hyperlinks are not activated. This applies to EML/MBOX as well as MSG: emails that relied on remote images will no longer fetch them automatically. Normal origins use blob URLs; opaque-origin WebViews use bounded local data URLs for inline images.
|
|
59
|
-
|
|
60
|
-
Limits: 128 MiB MSG source/individual attachment, 32 MiB HTML or decompressed RTF, 32 MiB eagerly extracted inline images, 1,024 attachments and 4,096 recipients per message, 32,768 CFB directory entries and 24 storage levels. HTML additionally bounds node count and serialized/inline expansion. Malformed, cyclic, truncated or excessive input fails explicitly. These are defensive bounds, not a claim of a complete adversarial parser audit.
|
|
61
|
-
|
|
62
|
-
S/MIME/IRM decryption and signature verification are **not** implemented. Protected/signed message classes are identified with a notice; only available content is displayed. MSG contacts, tasks, appointments, OLE activation and every Outlook-specific MAPI property are not complete Outlook replacements. RTF fidelity is limited by the installed RTF capability. No claim of pixel-identical Outlook rendering is made without a matching real-file comparison.
|
|
63
|
-
|
|
64
|
-
## Verification
|
|
65
|
-
|
|
66
|
-
```sh
|
|
67
|
-
pnpm --filter @file-viewer/renderer-email verify:email
|
|
68
|
-
pnpm exec playwright install chromium
|
|
69
|
-
pnpm --filter @file-viewer/renderer-email verify:msg:browser
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
The existing root email regression gate invokes `verify:email`, preserving the EML #232 checks and adding the MSG tests. `test/msg.test.mjs` includes actual installed-MsgReader tests over generated CFB v3/v4, ANSI, Unicode, RTF and nested-message fixtures. Those integration cases are required by default; `MSG_UNIT_ONLY=1` is only an explicitly reported offline subset.
|
|
73
|
-
|
|
74
|
-
The browser gate uses the emitted production renderer and real Chromium with explicit Reader/RTF host API fixtures. It covers layout, sanitization, downloads, races and disposal, **not** installed-parser integration or RTF.js visual parity. It writes screenshots and a JSON report to `output/msg-browser/`. See [fixture provenance](test/fixtures/README.md).
|
|
7
|
+
The package's own license is Apache-2.0. Included third-party notices apply to their respective components.
|
package/README.md
CHANGED
|
@@ -1,74 +1,7 @@
|
|
|
1
1
|
# @file-viewer/renderer-email
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Runtime package version 3.2.0.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Usage and API documentation: https://doc.file-viewer.app/guide/on-demand-renderers
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
import { FileViewer } from '@file-viewer/vue3'
|
|
9
|
-
import { emailRenderer } from '@file-viewer/renderer-email'
|
|
10
|
-
|
|
11
|
-
const options = {
|
|
12
|
-
builtinRenderers: 'none',
|
|
13
|
-
renderers: emailRenderer,
|
|
14
|
-
}
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
传入带真实 `.msg` 文件名的 `File`,或保留原文件名的 URL。沿用现有 email 路由,仅在命中 MSG 时加载其解析模块,EML/MBOX 不加载 MSG 解析器。
|
|
18
|
-
|
|
19
|
-
附件预览需要组合相应的 PDF、图片、Word 等 renderer,由宿主提供标准 `renderNestedBuffer`。内嵌 Outlook 邮件按真实 `.msg` 提取和预览,不伪装成文本;下载保留附件原始字节。
|
|
20
|
-
|
|
21
|
-
### Outlook 富文本正文
|
|
22
|
-
|
|
23
|
-
Full preset 已包含 Word renderer 和 RTF 能力:
|
|
24
|
-
|
|
25
|
-
```ts
|
|
26
|
-
import allRenderers from '@file-viewer/preset-all'
|
|
27
|
-
const options = { preset: allRenderers }
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
按需接入时,同时安装 `@file-viewer/renderer-word` 和 `@file-viewer/capability-rtf`:
|
|
31
|
-
|
|
32
|
-
```ts
|
|
33
|
-
import { emailRenderer } from '@file-viewer/renderer-email'
|
|
34
|
-
import { wordRenderer } from '@file-viewer/renderer-word'
|
|
35
|
-
import '@file-viewer/capability-rtf'
|
|
36
|
-
|
|
37
|
-
const options = {
|
|
38
|
-
builtinRenderers: 'none',
|
|
39
|
-
renderers: [emailRenderer, wordRenderer],
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
本地解压压缩 RTF;其中封装的 HTML 可用于正文预览,普通富文本通过嵌套 renderer 复用现有 RTF.js 能力。仅安装 email renderer 时仍可阅读提取的纯文本,并提示富文本能力未安装。邮件 RTF 始终禁止外部资源和链接,不继承宿主针对其他文档开启的外链权限。
|
|
44
|
-
|
|
45
|
-
## MSG 能力
|
|
46
|
-
|
|
47
|
-
- Unicode/ANSI 属性、Outlook 代码页、Unicode `bodyHtml` 与二进制 `html`、BOM 和 HTML charset 解码。
|
|
48
|
-
- 主题、发件人、代发 Sender、独立的 To/Cc/Bcc、提交/投递时间、原始邮件头;草稿缺少邮件头时显示明确标识的元数据摘要。
|
|
49
|
-
- HTML、纯文本、RTF 正文切换,保留表格、作者样式和本地 CID/Content-Location 栅格图片。
|
|
50
|
-
- MIME、附件安全文件名、惰性二进制提取、原字节下载和内嵌 MSG 预览;未知大小在提取前显示未知,不误报为零字节。
|
|
51
|
-
- 未打开附件时正文占满可用高度;关闭附件恢复正文空间和键盘焦点;切换、取消、卸载会清理过期预览和资源 URL。
|
|
52
|
-
- 提示支持简体中文、英语、日语、德语,跟随 viewer locale;适配窄容器和明暗主题。
|
|
53
|
-
|
|
54
|
-
EML/MBOX 继续使用 `postal-mime`。MBOX 仍预览第一封邮件并提示邮件数量,本次不新增邮箱列表浏览器。
|
|
55
|
-
|
|
56
|
-
## 隐私、限制与兼容性
|
|
57
|
-
|
|
58
|
-
HTML 正文位于空 sandbox iframe 内,通过净化和严格 CSP 禁止脚本、表单操作、嵌入文档、本地路径、外部样式、字体、追踪图片及远程资源请求。只允许本地持有的图片资源和栅格图片 data URL,外部超链接不激活。此规则同时作用于 EML/MBOX,因此历史上依赖远程图片的邮件不再自动联网加载。普通来源使用 Blob URL;不透明来源的 WebView 使用有界的本地 data URL 展示内嵌图片。
|
|
59
|
-
|
|
60
|
-
安全上限:MSG 原文件/单个附件 128 MiB,HTML 或解压后的 RTF 32 MiB,提前解码的内嵌图片合计 32 MiB,每封邮件最多 1,024 个附件、4,096 个收件人,CFB 最多 32,768 个目录项、24 层存储。HTML 另有节点数量和序列化/内嵌资源膨胀上限。损坏、循环、截断或超限输入明确失败;这些防御性限制不代表完成了全面对抗性解析器审计。
|
|
61
|
-
|
|
62
|
-
**不实现 S/MIME/IRM 解密或签名验证。** 对受保护/签名邮件类型显示提示,仅展示可获得的内容。联系人、任务、日程、OLE 激活和全部 Outlook 专有 MAPI 属性不属于完整 Outlook 替代范围。富文本还原度受已安装 RTF 能力限制,未经真实文件对照不承诺与 Outlook 像素一致。
|
|
63
|
-
|
|
64
|
-
## 验证
|
|
65
|
-
|
|
66
|
-
```sh
|
|
67
|
-
pnpm --filter @file-viewer/renderer-email verify:email
|
|
68
|
-
pnpm exec playwright install chromium
|
|
69
|
-
pnpm --filter @file-viewer/renderer-email verify:msg:browser
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
根目录原有邮件回归入口会调用 `verify:email`,保留 EML #232 检查并加入 MSG 测试。`test/msg.test.mjs` 默认使用真实安装的 MsgReader,覆盖生成的 CFB v3/v4、ANSI、Unicode、RTF 和嵌套邮件。`MSG_UNIT_ONLY=1` 仅用于明确标注的离线子集,不能替代集成验收。
|
|
73
|
-
|
|
74
|
-
浏览器测试使用生产 renderer 编译结果、真实 Chromium,以及明确声明的 Reader/RTF 宿主 API 测试替身,验证布局、安全隔离、下载、竞态和清理;不代表真实解析器集成或 RTF.js 视觉还原验收。截图和 JSON 结果输出到 `output/msg-browser/`。参见[样本来源说明](test/fixtures/README.md)。
|
|
7
|
+
The package's own license is Apache-2.0. Included third-party notices apply to their respective components.
|
package/dist/email.js
CHANGED
|
@@ -131,15 +131,14 @@ const createPostalAttachments = (email, objectUrls, cidUrls) => {
|
|
|
131
131
|
cidUrls.set(normalizeContentId(attachment.contentId), url);
|
|
132
132
|
})).then(() => attachments);
|
|
133
133
|
};
|
|
134
|
-
// Exported for the package-local #232 regression gate (verify-github-232.mjs); it
|
|
135
|
-
// stays out of the public exports map, so the shipped API surface is unchanged.
|
|
136
134
|
export const parseEml = async (buffer, filename, objectUrls, cidUrls) => {
|
|
137
135
|
var _a, _b;
|
|
138
|
-
const PostalMime =
|
|
136
|
+
const { default: PostalMime } = await import('postal-mime');
|
|
139
137
|
const email = await PostalMime.parse(buffer, {
|
|
140
138
|
attachmentEncoding: 'arraybuffer',
|
|
141
139
|
maxNestingDepth: 24,
|
|
142
140
|
maxHeadersSize: 2 * 1024 * 1024,
|
|
141
|
+
maxPartCount: 10000,
|
|
143
142
|
});
|
|
144
143
|
const attachments = await createPostalAttachments(email, objectUrls, cidUrls);
|
|
145
144
|
return {
|
|
@@ -164,11 +163,12 @@ const parseMbox = async (buffer, filename, objectUrls, cidUrls, t) => {
|
|
|
164
163
|
const secondStart = (_b = starts[1]) !== null && _b !== void 0 ? _b : source.length;
|
|
165
164
|
const firstMessage = source.slice(firstStart, secondStart).replace(/^From .*$\n/, '');
|
|
166
165
|
const encoded = new TextEncoder().encode(firstMessage).buffer;
|
|
167
|
-
const PostalMime =
|
|
166
|
+
const { default: PostalMime } = await import('postal-mime');
|
|
168
167
|
const email = await PostalMime.parse(encoded, {
|
|
169
168
|
attachmentEncoding: 'arraybuffer',
|
|
170
169
|
maxNestingDepth: 24,
|
|
171
170
|
maxHeadersSize: 2 * 1024 * 1024,
|
|
171
|
+
maxPartCount: 10000,
|
|
172
172
|
});
|
|
173
173
|
const attachments = await createPostalAttachments(email, objectUrls, cidUrls);
|
|
174
174
|
return {
|
|
@@ -412,8 +412,6 @@ export default async function renderEmail(buffer, target, type = 'eml', context)
|
|
|
412
412
|
else if (activeBody === 'rtf' && parsed.rtf && (context === null || context === void 0 ? void 0 : context.renderNestedBuffer)) {
|
|
413
413
|
const child = createElement('div', 'email-rtf');
|
|
414
414
|
messageContent.append(child);
|
|
415
|
-
// Reuse the host's opt-in RTF capability (RTF.js), like attachments.
|
|
416
|
-
// A mail body must not inherit the host's external-resource opt-in.
|
|
417
415
|
const rendered = await context.renderNestedBuffer(parsed.rtf, 'rtf', child, {
|
|
418
416
|
...context,
|
|
419
417
|
filename: `${filename}.rtf`,
|
package/dist/emailHtml.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
1
|
export declare const normalizeEmailResourceId: (value: string) => string;
|
|
2
|
-
/** Sandboxed srcdoc cannot read blob:null URLs from a different opaque
|
|
3
|
-
* origin (file:// WebViews, data: hosts). Keep ordinary hosts zero-copy and use
|
|
4
|
-
* a bounded data URL only for those hosts or browsers without object URLs.
|
|
5
|
-
*/
|
|
6
2
|
export declare function createEmailImageResource(buffer: ArrayBuffer, mimeType: string, objectUrls: string[]): string;
|
|
7
3
|
export declare function createEmailHtmlDocument(html: string, resources: Map<string, string>, darkMode?: boolean, documentRef?: Document): string;
|
package/dist/emailHtml.js
CHANGED
|
@@ -5,14 +5,10 @@ export const normalizeEmailResourceId = (value) => {
|
|
|
5
5
|
try {
|
|
6
6
|
result = decodeURIComponent(result);
|
|
7
7
|
}
|
|
8
|
-
catch {
|
|
8
|
+
catch { }
|
|
9
9
|
}
|
|
10
10
|
return result;
|
|
11
11
|
};
|
|
12
|
-
/** Sandboxed srcdoc cannot read blob:null URLs from a different opaque
|
|
13
|
-
* origin (file:// WebViews, data: hosts). Keep ordinary hosts zero-copy and use
|
|
14
|
-
* a bounded data URL only for those hosts or browsers without object URLs.
|
|
15
|
-
*/
|
|
16
12
|
export function createEmailImageResource(buffer, mimeType, objectUrls) {
|
|
17
13
|
if (typeof URL.createObjectURL === 'function') {
|
|
18
14
|
const url = URL.createObjectURL(new Blob([buffer], { type: mimeType }));
|
|
@@ -24,7 +20,6 @@ export function createEmailImageResource(buffer, mimeType, objectUrls) {
|
|
|
24
20
|
}
|
|
25
21
|
const bytes = new Uint8Array(buffer);
|
|
26
22
|
const parts = [];
|
|
27
|
-
// Divisible by three: only the final base64 chunk can contain padding.
|
|
28
23
|
for (let offset = 0; offset < bytes.length; offset += 24576) {
|
|
29
24
|
parts.push(btoa(String.fromCharCode(...bytes.subarray(offset, offset + 24576))));
|
|
30
25
|
}
|
|
@@ -38,15 +33,12 @@ export function createEmailHtmlDocument(html, resources, darkMode = false, docum
|
|
|
38
33
|
var _a, _b;
|
|
39
34
|
if (html.length > 32 * 1024 * 1024)
|
|
40
35
|
throw new Error('Email HTML exceeds the safety limit.');
|
|
41
|
-
// Template contents are inert, unlike parsing a live document with loadable images.
|
|
42
36
|
const template = documentRef.createElement('template');
|
|
43
37
|
const inertDocument = template.content.ownerDocument;
|
|
44
38
|
if (inertDocument.defaultView)
|
|
45
39
|
throw new Error('Email parsing requires an inert template document.');
|
|
46
40
|
const parsed = inertDocument.createElement('html');
|
|
47
41
|
parsed.innerHTML = html;
|
|
48
|
-
// Fragment parsing drops the outer html token. Recover only its language and
|
|
49
|
-
// direction through a second inert element; never copy executable attributes.
|
|
50
42
|
const rootAttributes = (_a = /^\s*(?:<!doctype[^>]*>\s*)?<html\b((?:[^>"']|"[^"]*"|'[^']*')*)>/i.exec(html.slice(0, 16384))) === null || _a === void 0 ? void 0 : _a[1];
|
|
51
43
|
if (rootAttributes) {
|
|
52
44
|
const probe = inertDocument.createElement('div');
|
|
@@ -72,13 +64,11 @@ export function createEmailHtmlDocument(html, resources, darkMode = false, docum
|
|
|
72
64
|
try {
|
|
73
65
|
exact = resources.get(decodeURIComponent(key));
|
|
74
66
|
}
|
|
75
|
-
catch {
|
|
67
|
+
catch { }
|
|
76
68
|
}
|
|
77
69
|
if (exact && (/^blob:/.test(exact) || SAFE_IMAGE.test(exact)))
|
|
78
70
|
return exact;
|
|
79
71
|
if (/^cid:/i.test(trimmed)) {
|
|
80
|
-
// Legacy writers vary CID casing. Only use a case-insensitive fallback
|
|
81
|
-
// when it identifies exactly one attachment; never replace a prefix.
|
|
82
72
|
const matches = [...resources].filter(([id]) => id.toLowerCase() === key.toLowerCase());
|
|
83
73
|
if (matches.length === 1 && (/^blob:/.test(matches[0][1]) || SAFE_IMAGE.test(matches[0][1])))
|
|
84
74
|
return matches[0][1];
|
|
@@ -158,14 +148,12 @@ export function createEmailHtmlDocument(html, resources, darkMode = false, docum
|
|
|
158
148
|
clean(body);
|
|
159
149
|
attributes(parsed);
|
|
160
150
|
attributes(body);
|
|
161
|
-
// Preserve legacy Outlook body colors as well as modern inline styles.
|
|
162
151
|
if (body.getAttribute('bgcolor') && !body.style.backgroundColor)
|
|
163
152
|
body.style.backgroundColor = body.getAttribute('bgcolor');
|
|
164
153
|
if (body.getAttribute('text') && !body.style.color)
|
|
165
154
|
body.style.color = body.getAttribute('text');
|
|
166
155
|
if (body.getAttribute('background') && !body.style.backgroundImage)
|
|
167
156
|
body.style.backgroundImage = `url("${body.getAttribute('background').replace(/["\\\r\n]/g, '')}")`;
|
|
168
|
-
// Check escaped serialization growth before building a potentially huge srcdoc.
|
|
169
157
|
const escapedLength = (value, attribute = false) => {
|
|
170
158
|
let size = value.length;
|
|
171
159
|
for (let index = 0; index < value.length; index++) {
|
|
@@ -198,8 +186,6 @@ export function createEmailHtmlDocument(html, resources, darkMode = false, docum
|
|
|
198
186
|
const serializeAttributes = (element) => Array.from(element.attributes).map(attr => ` ${attr.name}="${escape(attr.value)}"`).join('');
|
|
199
187
|
const background = darkMode ? '#111827' : '#fff';
|
|
200
188
|
const foreground = darkMode ? '#e5e7eb' : '#172033';
|
|
201
|
-
// CSP is required in addition to sanitization: CSS escapes and future HTML
|
|
202
|
-
// features must not introduce external requests or executable content.
|
|
203
189
|
const csp = "default-src 'none'; script-src 'none'; connect-src 'none'; img-src blob: data:; style-src 'unsafe-inline'; font-src 'none'; media-src 'none'; object-src 'none'; frame-src 'none'; base-uri 'none'; form-action 'none'";
|
|
204
190
|
return `<!doctype html><html${serializeAttributes(parsed)}><head><meta charset="utf-8"><meta http-equiv="Content-Security-Policy" content="${csp}"><meta name="referrer" content="no-referrer"><style>:root{color-scheme:${darkMode ? 'dark' : 'light'}}body{margin:0;padding:18px;font-family:Aptos,"Segoe UI",sans-serif;line-height:1.6;overflow-wrap:anywhere;background:${background};color:${foreground}}img{max-width:100%;height:auto}table{max-width:100%}</style>${head.innerHTML}</head><body${serializeAttributes(body)}>${body.innerHTML}</body></html>`;
|
|
205
191
|
}
|
package/dist/msg.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import type { ParsedEmailView } from './email.js';
|
|
2
|
-
/** Structural view of @kenjiuno/msgreader 1.28's documented API. Keep it local:
|
|
3
|
-
* consumers continue to use the shared File Viewer contract, not MAPI types.
|
|
4
|
-
*/
|
|
5
2
|
export interface MsgFields {
|
|
6
3
|
dataType?: string;
|
|
7
4
|
error?: unknown;
|
|
@@ -58,8 +55,6 @@ export interface MsgReaderLike {
|
|
|
58
55
|
}
|
|
59
56
|
export type MsgReaderConstructor = new (buffer: ArrayBuffer) => MsgReaderLike;
|
|
60
57
|
export declare function safeMsgAttachmentName(value: unknown, fallback: string): string;
|
|
61
|
-
/** Exported only from the internal module for deterministic normalization tests. */
|
|
62
58
|
export declare function normalizeMsg(reader: MsgReaderLike, fields: MsgFields, filename: string, objectUrls: string[], cidUrls: Map<string, string>, signal?: AbortSignal): Promise<ParsedEmailView>;
|
|
63
|
-
/** Capture standard MAPI strings not named by the reader's default map. */
|
|
64
59
|
export declare function captureMsgProperty(fields: MsgFields, tag: number, raw: Uint8Array | null, codepage?: number): void;
|
|
65
60
|
export declare function parseMsg(buffer: ArrayBuffer, filename: string, objectUrls: string[], cidUrls: Map<string, string>, signal?: AbortSignal): Promise<ParsedEmailView>;
|
package/dist/msg.js
CHANGED
|
@@ -55,7 +55,6 @@ function assertFieldTree(root) {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
/** Exported only from the internal module for deterministic normalization tests. */
|
|
59
58
|
export async function normalizeMsg(reader, fields, filename, objectUrls, cidUrls, signal) {
|
|
60
59
|
var _a, _b;
|
|
61
60
|
signal === null || signal === void 0 ? void 0 : signal.throwIfAborted();
|
|
@@ -79,8 +78,6 @@ export async function normalizeMsg(reader, fields, filename, objectUrls, cidUrls
|
|
|
79
78
|
const kind = String((_a = item.recipType) !== null && _a !== void 0 ? _a : 'to').toLowerCase();
|
|
80
79
|
(kind === 'cc' || kind === '2' ? cc : kind === 'bcc' || kind === '3' ? bcc : to).push(address);
|
|
81
80
|
}
|
|
82
|
-
// Display lists are useful in drafts that omit recipient rows. They are
|
|
83
|
-
// display text, not an address parser: do not invent SMTP addresses.
|
|
84
81
|
if (!to.length && fields.displayTo)
|
|
85
82
|
to.push({ name: string(fields.displayTo, 32768) });
|
|
86
83
|
if (!cc.length && fields.displayCc)
|
|
@@ -129,7 +126,6 @@ export async function normalizeMsg(reader, fields, filename, objectUrls, cidUrls
|
|
|
129
126
|
inline: !!attachment.attachmentHidden || !!contentId,
|
|
130
127
|
async load() {
|
|
131
128
|
signal === null || signal === void 0 ? void 0 : signal.throwIfAborted();
|
|
132
|
-
// Do not cache every extracted buffer: the reader already owns the CFB.
|
|
133
129
|
const extracted = reader.getAttachment(attachment);
|
|
134
130
|
if (!extracted || !(extracted.content instanceof Uint8Array))
|
|
135
131
|
throw new Error(`Attachment data is not embedded: ${name}`);
|
|
@@ -141,7 +137,6 @@ export async function normalizeMsg(reader, fields, filename, objectUrls, cidUrls
|
|
|
141
137
|
};
|
|
142
138
|
return result;
|
|
143
139
|
});
|
|
144
|
-
// Only raster CID images are decoded eagerly. PDF/Office/nested MSG remain lazy.
|
|
145
140
|
for (const attachment of attachments) {
|
|
146
141
|
const referenced = !!(attachment.contentId || attachment.contentLocation || attachment.inline || html.includes(attachment.name));
|
|
147
142
|
if (!referenced || !RASTER_MIME.test(attachment.mimeType || ''))
|
|
@@ -157,7 +152,6 @@ export async function normalizeMsg(reader, fields, filename, objectUrls, cidUrls
|
|
|
157
152
|
signal === null || signal === void 0 ? void 0 : signal.throwIfAborted();
|
|
158
153
|
const cid = normalizeEmailResourceId(attachment.contentId || '');
|
|
159
154
|
const keys = [cid, attachment.contentLocation].filter((key) => !!key);
|
|
160
|
-
// A unique filename is also a valid local Content-Location fallback.
|
|
161
155
|
if (attachments.filter(item => item.name === attachment.name).length === 1)
|
|
162
156
|
keys.push(attachment.name);
|
|
163
157
|
const available = keys.map(normalizeEmailResourceId).filter(key => !cidUrls.has(key));
|
|
@@ -177,8 +171,6 @@ export async function normalizeMsg(reader, fields, filename, objectUrls, cidUrls
|
|
|
177
171
|
const date = string(fields.clientSubmitTime || fields.messageDeliveryTime || fields.creationTime, 4096);
|
|
178
172
|
const rawHeaders = string(fields.headers, 2 * 1024 * 1024);
|
|
179
173
|
const headerLine = (key, value) => value ? `${key}: ${value.replace(/[\r\n\0]/g, ' ')}` : '';
|
|
180
|
-
// Outlook drafts may have no transport headers. Label the generated metadata
|
|
181
|
-
// explicitly instead of misrepresenting it as the original transport envelope.
|
|
182
174
|
const headers = rawHeaders || [
|
|
183
175
|
'X-File-Viewer-Source: Outlook MAPI properties (not transport headers)',
|
|
184
176
|
headerLine('Subject', subject), headerLine('From', addressText(from)), headerLine('Sender', addressText(sender)),
|
|
@@ -193,7 +185,6 @@ export async function normalizeMsg(reader, fields, filename, objectUrls, cidUrls
|
|
|
193
185
|
warnings.push('email.msg.protected');
|
|
194
186
|
return { kind: 'msg', subject, from, sender, to, cc, bcc, date, text, html, rtf, headers, attachments, warnings };
|
|
195
187
|
}
|
|
196
|
-
/** Capture standard MAPI strings not named by the reader's default map. */
|
|
197
188
|
export function captureMsgProperty(fields, tag, raw, codepage) {
|
|
198
189
|
const name = { 0x0042: 'sentRepresentingName', 0x0065: 'sentRepresentingEmail',
|
|
199
190
|
0x0e04: 'displayTo', 0x0e03: 'displayCc', 0x0e02: 'displayBcc',
|
|
@@ -204,8 +195,6 @@ export function captureMsgProperty(fields, tag, raw, codepage) {
|
|
|
204
195
|
if (raw.length > 65536)
|
|
205
196
|
throw new Error('Outlook MSG metadata exceeds the safety limit.');
|
|
206
197
|
const value = decodeEmailHtmlBytes(raw, type === 0x001f ? 1200 : codepage || 1252);
|
|
207
|
-
// MsgReader also observes inline property-table references, whose 8-byte
|
|
208
|
-
// length/flags record is not the variable-length string stored in the CFB.
|
|
209
198
|
if (/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/.test(value))
|
|
210
199
|
return;
|
|
211
200
|
fields[name] = value;
|
|
@@ -215,7 +204,6 @@ export async function parseMsg(buffer, filename, objectUrls, cidUrls, signal) {
|
|
|
215
204
|
const { messageCodepage } = inspectMsgContainer(buffer);
|
|
216
205
|
const module = await import('@kenjiuno/msgreader');
|
|
217
206
|
signal === null || signal === void 0 ? void 0 : signal.throwIfAborted();
|
|
218
|
-
// CJS interop varies between native ESM, Vite and Webpack.
|
|
219
207
|
const exported = module.default;
|
|
220
208
|
const constructor = typeof exported === 'function' ? exported : exported === null || exported === void 0 ? void 0 : exported.default;
|
|
221
209
|
if (typeof constructor !== 'function')
|
|
@@ -224,7 +212,6 @@ export async function parseMsg(buffer, filename, objectUrls, cidUrls, signal) {
|
|
|
224
212
|
const reader = new constructor(localBuffer);
|
|
225
213
|
const label = msgCodepageLabel(messageCodepage);
|
|
226
214
|
reader.parserConfig = {
|
|
227
|
-
// iconv-lite's names differ from WHATWG for Korean/Chinese codepages.
|
|
228
215
|
...(messageCodepage ? { ansiEncoding: { 949: 'cp949', 936: 'cp936', 932: 'cp932', 950: 'cp950' }[messageCodepage] || label || `cp${messageCodepage}` } : {}),
|
|
229
216
|
propertyObserver: (fields, tag, raw) => captureMsgProperty(fields, tag, raw, messageCodepage),
|
|
230
217
|
};
|
package/dist/msgCfb.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/** Bounded structural validation before handing an untrusted CFB to MsgReader.
|
|
2
|
-
* MS-CFB: header, FAT/DIFAT, directory and MiniFAT. This is not a second MSG parser.
|
|
3
|
-
*/
|
|
4
1
|
export declare const MAX_MSG_BYTES: number;
|
|
5
2
|
export declare function inspectMsgContainer(buffer: ArrayBuffer): {
|
|
6
3
|
messageCodepage?: number;
|
package/dist/msgCfb.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/** Bounded structural validation before handing an untrusted CFB to MsgReader.
|
|
2
|
-
* MS-CFB: header, FAT/DIFAT, directory and MiniFAT. This is not a second MSG parser.
|
|
3
|
-
*/
|
|
4
1
|
export const MAX_MSG_BYTES = 128 * 1024 * 1024;
|
|
5
2
|
const END = 0xfffffffe;
|
|
6
3
|
const FREE = 0xffffffff;
|
package/dist/msgEncoding.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
export declare const msgCodepageLabel: (codepage?: number) => string | undefined;
|
|
2
|
-
/** PR_HTML is PtypBinary, whereas 1013001F (bodyHtml) is already Unicode. */
|
|
3
2
|
export declare function decodeEmailHtmlBytes(value: string | Uint8Array | ArrayBuffer, internetCodepage?: number, messageCodepage?: number): string;
|
package/dist/msgEncoding.js
CHANGED
|
@@ -13,7 +13,6 @@ export const msgCodepageLabel = (codepage) => {
|
|
|
13
13
|
51932: 'euc-jp', 51949: 'euc-kr',
|
|
14
14
|
}[codepage || 0];
|
|
15
15
|
};
|
|
16
|
-
/** PR_HTML is PtypBinary, whereas 1013001F (bodyHtml) is already Unicode. */
|
|
17
16
|
export function decodeEmailHtmlBytes(value, internetCodepage, messageCodepage) {
|
|
18
17
|
var _a;
|
|
19
18
|
if (typeof value === 'string') {
|
|
@@ -42,7 +41,7 @@ export function decodeEmailHtmlBytes(value, internetCodepage, messageCodepage) {
|
|
|
42
41
|
try {
|
|
43
42
|
return new TextDecoder(candidate).decode(bytes).replace(/\0+$/, '');
|
|
44
43
|
}
|
|
45
|
-
catch {
|
|
44
|
+
catch { }
|
|
46
45
|
}
|
|
47
46
|
try {
|
|
48
47
|
return new TextDecoder('utf-8', { fatal: true }).decode(bytes).replace(/\0+$/, '');
|
package/dist/msgRtf.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/** MS-OXRTFCP decompression and MS-OXRTFEX body extraction.
|
|
2
|
-
* Rich RTF layout is delegated to the installed RTF renderer; this tokenizer
|
|
3
|
-
* provides readable text and extracts HTML encapsulated by Outlook.
|
|
4
|
-
*/
|
|
5
1
|
export declare const MAX_MSG_RTF_BYTES: number;
|
|
6
2
|
export declare function rtfCrc32(bytes: Uint8Array): number;
|
|
7
3
|
export declare function decompressMsgRtf(input: Uint8Array): Uint8Array;
|
package/dist/msgRtf.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import { msgCodepageLabel } from './msgEncoding.js';
|
|
2
|
-
/** MS-OXRTFCP decompression and MS-OXRTFEX body extraction.
|
|
3
|
-
* Rich RTF layout is delegated to the installed RTF renderer; this tokenizer
|
|
4
|
-
* provides readable text and extracts HTML encapsulated by Outlook.
|
|
5
|
-
*/
|
|
6
2
|
export const MAX_MSG_RTF_BYTES = 32 * 1024 * 1024;
|
|
7
3
|
const SEED = '{\\rtf1\\ansi\\mac\\deff0\\deftab720{\\fonttbl;}{\\f0\\fnil \\froman \\fswiss \\fmodern \\fscript \\fdecor MS Sans SerifSymbolArialTimes New RomanCourier{\\colortbl\\red0\\green0\\blue0\r\n\\par \\pard\\plain\\f0\\fs20\\b\\i\\u\\tab\\tx';
|
|
8
4
|
export function rtfCrc32(bytes) {
|
|
@@ -92,7 +88,6 @@ const SKIPPED = new Set([
|
|
|
92
88
|
export function extractMsgRtf(bytes, codepage) {
|
|
93
89
|
if (bytes.length > MAX_MSG_RTF_BYTES)
|
|
94
90
|
throw new Error('Outlook RTF exceeds the body limit.');
|
|
95
|
-
// Latin-1 byte identity, NOT TextDecoder("latin1") (which maps to Windows-1252).
|
|
96
91
|
let source = '';
|
|
97
92
|
for (let offset = 0; offset < bytes.length; offset += 8192)
|
|
98
93
|
source += String.fromCharCode(...bytes.subarray(offset, offset + 8192));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@file-viewer/renderer-email",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Standalone email renderer plugin for File Viewer with EML, MSG, MBOX, attachments, and nested previews.",
|
|
@@ -26,8 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"repository": {
|
|
28
28
|
"type": "git",
|
|
29
|
-
"url": "git+https://github.com/flyfish-dev/file-viewer.git"
|
|
30
|
-
"directory": "packages/renderers/email"
|
|
29
|
+
"url": "git+https://github.com/flyfish-dev/file-viewer.git"
|
|
31
30
|
},
|
|
32
31
|
"homepage": "https://doc.file-viewer.app/guide/on-demand-renderers",
|
|
33
32
|
"bugs": {
|
|
@@ -49,31 +48,39 @@
|
|
|
49
48
|
"./package.json": "./package.json"
|
|
50
49
|
},
|
|
51
50
|
"files": [
|
|
52
|
-
"dist",
|
|
51
|
+
"dist/email.d.ts",
|
|
52
|
+
"dist/email.js",
|
|
53
|
+
"dist/emailHtml.d.ts",
|
|
54
|
+
"dist/emailHtml.js",
|
|
55
|
+
"dist/index.d.ts",
|
|
56
|
+
"dist/index.js",
|
|
57
|
+
"dist/msg.d.ts",
|
|
58
|
+
"dist/msg.js",
|
|
59
|
+
"dist/msgCfb.d.ts",
|
|
60
|
+
"dist/msgCfb.js",
|
|
61
|
+
"dist/msgEncoding.d.ts",
|
|
62
|
+
"dist/msgEncoding.js",
|
|
63
|
+
"dist/msgMessages.d.ts",
|
|
64
|
+
"dist/msgMessages.js",
|
|
65
|
+
"dist/msgRtf.d.ts",
|
|
66
|
+
"dist/msgRtf.js",
|
|
53
67
|
"file-viewer.capability.json",
|
|
54
|
-
"
|
|
68
|
+
"LICENSE",
|
|
55
69
|
"README.en.md",
|
|
56
|
-
"
|
|
70
|
+
"README.md"
|
|
57
71
|
],
|
|
58
72
|
"dependencies": {
|
|
59
|
-
"@file-viewer/core": "3.
|
|
73
|
+
"@file-viewer/core": "3.2.0",
|
|
60
74
|
"@kenjiuno/msgreader": "^1.28.0",
|
|
61
75
|
"buffer": "^6.0.3",
|
|
62
|
-
"postal-mime": "^
|
|
63
|
-
},
|
|
64
|
-
"devDependencies": {
|
|
65
|
-
"typescript": "^6.0.3"
|
|
76
|
+
"postal-mime": "^4.0.5"
|
|
66
77
|
},
|
|
67
78
|
"fileViewer": {
|
|
68
|
-
"capabilityManifest": "./file-viewer.capability.json"
|
|
79
|
+
"capabilityManifest": "./file-viewer.capability.json",
|
|
80
|
+
"distribution": {
|
|
81
|
+
"schemaVersion": 1,
|
|
82
|
+
"mode": "runtime-only"
|
|
83
|
+
}
|
|
69
84
|
},
|
|
70
|
-
"license": "Apache-2.0"
|
|
71
|
-
|
|
72
|
-
"build": "tsc -b tsconfig.json",
|
|
73
|
-
"type-check": "tsc -b tsconfig.json",
|
|
74
|
-
"verify:email": "pnpm --filter @file-viewer/core build && pnpm build && node scripts/verify-github-232.mjs && node --test test/msg.test.mjs",
|
|
75
|
-
"verify:github-232": "pnpm verify:email",
|
|
76
|
-
"verify:msg": "pnpm --filter @file-viewer/core build && pnpm build && node --test test/msg.test.mjs",
|
|
77
|
-
"verify:msg:browser": "pnpm --filter @file-viewer/core build && pnpm build && node scripts/verify-msg-browser.mjs"
|
|
78
|
-
}
|
|
79
|
-
}
|
|
85
|
+
"license": "Apache-2.0"
|
|
86
|
+
}
|