@file-viewer/renderer-email 3.3.0 → 3.3.3

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/email.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createFileViewerTranslator, disposeFileViewerRendered, resolveFileViewerColorScheme, } from '@file-viewer/core';
2
- import { createEmailHtmlDocument, createEmailImageResource } from './emailHtml.js';
2
+ import { createEmailHtmlDocument, createEmailImageResource, isEmailImageMimeType } from './emailHtml.js';
3
3
  import { getMsgLabels } from './msgMessages.js';
4
4
  const emailStyle = `
5
5
  .email-viewer{position:relative;height:100%;min-height:0;display:flex;flex-direction:column;background:#f3f6f8;color:#172033;box-sizing:border-box}
@@ -122,8 +122,7 @@ const createPostalAttachments = (email, objectUrls, cidUrls) => {
122
122
  };
123
123
  });
124
124
  return Promise.all(attachments.map(async (attachment) => {
125
- var _a;
126
- if (!attachment.contentId || !((_a = attachment.mimeType) === null || _a === void 0 ? void 0 : _a.startsWith('image/'))) {
125
+ if (!attachment.contentId || !isEmailImageMimeType(attachment.mimeType || '')) {
127
126
  return;
128
127
  }
129
128
  const buffer = await attachment.load();
@@ -1,3 +1,4 @@
1
1
  export declare const normalizeEmailResourceId: (value: string) => string;
2
+ export declare const isEmailImageMimeType: (value: string) => boolean;
2
3
  export declare function createEmailImageResource(buffer: ArrayBuffer, mimeType: string, objectUrls: string[]): string;
3
4
  export declare function createEmailHtmlDocument(html: string, resources: Map<string, string>, darkMode?: boolean, documentRef?: Document): string;
package/dist/emailHtml.js CHANGED
@@ -9,21 +9,25 @@ export const normalizeEmailResourceId = (value) => {
9
9
  }
10
10
  return result;
11
11
  };
12
+ const MAX_INLINE_RESOURCE_CHARACTERS = 48 * 1024 * 1024;
13
+ const inlineResourceCharacters = new WeakMap();
14
+ export const isEmailImageMimeType = (value) => /^image\/(?:png|jpeg|gif|webp|avif|bmp)$/i.test(value);
12
15
  export function createEmailImageResource(buffer, mimeType, objectUrls) {
13
- if (typeof URL.createObjectURL === 'function') {
14
- const url = URL.createObjectURL(new Blob([buffer], { type: mimeType }));
15
- if (!url.startsWith('blob:null/')) {
16
- objectUrls.push(url);
17
- return url;
18
- }
19
- URL.revokeObjectURL(url);
20
- }
16
+ if (!isEmailImageMimeType(mimeType))
17
+ throw new Error('Unsupported inline email image type.');
18
+ const prefix = `data:${mimeType};base64,`;
19
+ const size = prefix.length + 4 * Math.ceil(buffer.byteLength / 3);
20
+ const used = inlineResourceCharacters.get(objectUrls) || 0;
21
+ if (size > MAX_INLINE_RESOURCE_CHARACTERS - used)
22
+ throw new Error('Email inline resource expansion limit exceeded.');
21
23
  const bytes = new Uint8Array(buffer);
22
24
  const parts = [];
23
25
  for (let offset = 0; offset < bytes.length; offset += 24576) {
24
26
  parts.push(btoa(String.fromCharCode(...bytes.subarray(offset, offset + 24576))));
25
27
  }
26
- return `data:${mimeType};base64,${parts.join('')}`;
28
+ const url = prefix + parts.join('');
29
+ inlineResourceCharacters.set(objectUrls, used + size);
30
+ return url;
27
31
  }
28
32
  const ALLOWED_TAGS = new Set('a abbr address article aside b bdi bdo big blockquote br caption center cite code col colgroup dd del details div dl dt em figcaption figure font footer h1 h2 h3 h4 h5 h6 header hr i img ins kbd label li main mark ol p pre q rp rt ruby s samp section small span strike strong style sub summary sup table tbody td tfoot th thead time title tr tt u ul var wbr'.split(' '));
29
33
  const DROP_CONTENT = new Set('script iframe frame frameset object embed applet svg math template noscript audio video source track input link meta base'.split(' '));
@@ -80,7 +84,7 @@ export function createEmailHtmlDocument(html, resources, darkMode = false, docum
80
84
  const resolved = lookup(value);
81
85
  if (resolved) {
82
86
  expandedResourceCharacters += resolved.length;
83
- if (expandedResourceCharacters > 48 * 1024 * 1024)
87
+ if (expandedResourceCharacters > MAX_INLINE_RESOURCE_CHARACTERS)
84
88
  throw new Error('Email inline resource expansion limit exceeded.');
85
89
  }
86
90
  return resolved;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@file-viewer/renderer-email",
3
- "version": "3.3.0",
3
+ "version": "3.3.3",
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.",
@@ -71,10 +71,10 @@
71
71
  "README.zh-CN.md"
72
72
  ],
73
73
  "dependencies": {
74
- "@file-viewer/core": "3.3.0",
75
- "@kenjiuno/msgreader": "^1.28.0",
74
+ "@file-viewer/core": "3.3.3",
75
+ "@kenjiuno/msgreader": "^1.29.0",
76
76
  "buffer": "^6.0.3",
77
- "postal-mime": "4.0.8"
77
+ "postal-mime": "4.1.4"
78
78
  },
79
79
  "fileViewer": {
80
80
  "capabilityManifest": "./file-viewer.capability.json",