@file-viewer/renderer-email 2.1.2 → 2.1.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 +21 -20
- package/package.json +2 -2
package/dist/email.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { disposeFileViewerRendered } from '@file-viewer/core';
|
|
1
|
+
import { createFileViewerTranslator, disposeFileViewerRendered, } from '@file-viewer/core';
|
|
2
2
|
const emailStyle = `
|
|
3
3
|
.email-viewer{position:relative;height:100%;min-height:0;display:flex;flex-direction:column;background:#f3f6f8;color:#172033;box-sizing:border-box}
|
|
4
4
|
.email-viewer *{box-sizing:border-box}
|
|
@@ -141,7 +141,7 @@ const parseEml = async (buffer, filename, objectUrls, cidUrls) => {
|
|
|
141
141
|
attachments,
|
|
142
142
|
};
|
|
143
143
|
};
|
|
144
|
-
const parseMbox = async (buffer, filename, objectUrls, cidUrls) => {
|
|
144
|
+
const parseMbox = async (buffer, filename, objectUrls, cidUrls, t) => {
|
|
145
145
|
var _a, _b, _c, _d;
|
|
146
146
|
const source = new TextDecoder('utf-8', { fatal: false }).decode(buffer);
|
|
147
147
|
const starts = [...source.matchAll(/^From .*$\n/gm)].map(match => match.index || 0);
|
|
@@ -158,12 +158,12 @@ const parseMbox = async (buffer, filename, objectUrls, cidUrls) => {
|
|
|
158
158
|
const attachments = await createPostalAttachments(email, objectUrls, cidUrls);
|
|
159
159
|
return {
|
|
160
160
|
kind: 'mbox',
|
|
161
|
-
subject: email.subject ||
|
|
161
|
+
subject: email.subject || t('email.mbox.subject', { filename }),
|
|
162
162
|
from: normalizeAddress(email.from),
|
|
163
163
|
to: normalizeAddress(email.to),
|
|
164
164
|
cc: normalizeAddress(email.cc),
|
|
165
165
|
date: email.date,
|
|
166
|
-
text:
|
|
166
|
+
text: `${t('email.mbox.summary', { count: Math.max(1, starts.length) })}\n\n${email.text || ''}`,
|
|
167
167
|
html: email.html,
|
|
168
168
|
headers: ((_c = email.headerLines) === null || _c === void 0 ? void 0 : _c.map((item) => item.line).join('\n'))
|
|
169
169
|
|| ((_d = email.headers) === null || _d === void 0 ? void 0 : _d.map((item) => `${item.originalKey}: ${item.value}`).join('\n')),
|
|
@@ -203,12 +203,12 @@ const parseMsg = async (buffer, filename) => {
|
|
|
203
203
|
attachments,
|
|
204
204
|
};
|
|
205
205
|
};
|
|
206
|
-
const parseEmail = (buffer, type, filename, objectUrls, cidUrls) => {
|
|
206
|
+
const parseEmail = (buffer, type, filename, objectUrls, cidUrls, t) => {
|
|
207
207
|
if (type === 'msg') {
|
|
208
208
|
return parseMsg(buffer, filename);
|
|
209
209
|
}
|
|
210
210
|
if (type === 'mbox') {
|
|
211
|
-
return parseMbox(buffer, filename, objectUrls, cidUrls);
|
|
211
|
+
return parseMbox(buffer, filename, objectUrls, cidUrls, t);
|
|
212
212
|
}
|
|
213
213
|
return parseEml(buffer, filename, objectUrls, cidUrls);
|
|
214
214
|
};
|
|
@@ -251,6 +251,7 @@ export default async function renderEmail(buffer, target, type = 'eml', context)
|
|
|
251
251
|
const filename = (context === null || context === void 0 ? void 0 : context.filename) || `message.${normalizedType}`;
|
|
252
252
|
const objectUrls = [];
|
|
253
253
|
const cidUrls = new Map();
|
|
254
|
+
const t = createFileViewerTranslator(context === null || context === void 0 ? void 0 : context.options);
|
|
254
255
|
const cleanups = [];
|
|
255
256
|
let nestedRendered;
|
|
256
257
|
let overlay = null;
|
|
@@ -281,7 +282,7 @@ export default async function renderEmail(buffer, target, type = 'eml', context)
|
|
|
281
282
|
const showError = (message) => {
|
|
282
283
|
errorElement === null || errorElement === void 0 ? void 0 : errorElement.remove();
|
|
283
284
|
errorElement = createElement('div', 'email-error');
|
|
284
|
-
errorElement.append(createElement('strong', undefined, '
|
|
285
|
+
errorElement.append(createElement('strong', undefined, t('email.error.title')));
|
|
285
286
|
errorElement.append(createElement('p', undefined, message));
|
|
286
287
|
root.append(errorElement);
|
|
287
288
|
};
|
|
@@ -310,12 +311,12 @@ export default async function renderEmail(buffer, target, type = 'eml', context)
|
|
|
310
311
|
header.append(createElement('span', undefined, parsed.kind.toUpperCase()));
|
|
311
312
|
header.append(createElement('h2', undefined, parsed.subject || filename));
|
|
312
313
|
const meta = createElement('div', 'email-meta');
|
|
313
|
-
appendMeta(meta, '
|
|
314
|
-
appendMeta(meta, '
|
|
314
|
+
appendMeta(meta, t('email.meta.from'), addressText(parsed.from));
|
|
315
|
+
appendMeta(meta, t('email.meta.to'), addressText(parsed.to));
|
|
315
316
|
if (parsed.cc.length) {
|
|
316
|
-
appendMeta(meta, '
|
|
317
|
+
appendMeta(meta, t('email.meta.cc'), addressText(parsed.cc));
|
|
317
318
|
}
|
|
318
|
-
appendMeta(meta, '
|
|
319
|
+
appendMeta(meta, t('email.meta.date'), parsed.date || '-');
|
|
319
320
|
header.append(meta);
|
|
320
321
|
const body = createElement('div', 'email-body');
|
|
321
322
|
const sidebar = createElement('aside', 'email-sidebar');
|
|
@@ -326,7 +327,7 @@ export default async function renderEmail(buffer, target, type = 'eml', context)
|
|
|
326
327
|
attachmentPreview.hidden = true;
|
|
327
328
|
const attachmentPreviewHead = createElement('div', 'attachment-preview-head');
|
|
328
329
|
const attachmentPreviewTitle = createElement('strong');
|
|
329
|
-
const attachmentDownload = createElement('button', undefined, '
|
|
330
|
+
const attachmentDownload = createElement('button', undefined, t('email.attachments.download'));
|
|
330
331
|
attachmentDownload.type = 'button';
|
|
331
332
|
const attachmentTarget = createElement('div', 'attachment-target');
|
|
332
333
|
attachmentPreviewHead.append(attachmentPreviewTitle, attachmentDownload);
|
|
@@ -351,8 +352,8 @@ export default async function renderEmail(buffer, target, type = 'eml', context)
|
|
|
351
352
|
};
|
|
352
353
|
const bodyModes = [
|
|
353
354
|
{ key: 'html', label: 'HTML', disabled: !parsed.html },
|
|
354
|
-
{ key: 'text', label: '
|
|
355
|
-
{ key: 'headers', label: '
|
|
355
|
+
{ key: 'text', label: t('email.tabs.text'), disabled: !parsed.text },
|
|
356
|
+
{ key: 'headers', label: t('email.tabs.headers'), disabled: !parsed.headers },
|
|
356
357
|
];
|
|
357
358
|
bodyModes.forEach(mode => {
|
|
358
359
|
const button = createElement('button', undefined, mode.label);
|
|
@@ -372,10 +373,10 @@ export default async function renderEmail(buffer, target, type = 'eml', context)
|
|
|
372
373
|
syncTabState();
|
|
373
374
|
const attachmentPanel = createElement('section', 'attachment-panel');
|
|
374
375
|
const attachmentTitle = createElement('div', 'attachment-title');
|
|
375
|
-
attachmentTitle.append(createElement('strong', undefined, '
|
|
376
|
+
attachmentTitle.append(createElement('strong', undefined, t('email.attachments.title')), createElement('span', undefined, String(parsed.attachments.length)));
|
|
376
377
|
attachmentPanel.append(attachmentTitle);
|
|
377
378
|
if (!parsed.attachments.length) {
|
|
378
|
-
attachmentPanel.append(createElement('p', 'attachment-empty', '
|
|
379
|
+
attachmentPanel.append(createElement('p', 'attachment-empty', t('email.attachments.empty')));
|
|
379
380
|
}
|
|
380
381
|
const syncAttachmentState = () => {
|
|
381
382
|
attachmentButtons.forEach(({ id, button }) => {
|
|
@@ -387,7 +388,7 @@ export default async function renderEmail(buffer, target, type = 'eml', context)
|
|
|
387
388
|
syncAttachmentState();
|
|
388
389
|
attachmentPreview.hidden = false;
|
|
389
390
|
attachmentPreviewTitle.textContent = attachment.name;
|
|
390
|
-
showLoading(
|
|
391
|
+
showLoading(t('email.attachments.opening', { name: attachment.name }));
|
|
391
392
|
try {
|
|
392
393
|
await clearAttachmentPreview();
|
|
393
394
|
attachmentTarget.replaceChildren();
|
|
@@ -403,7 +404,7 @@ export default async function renderEmail(buffer, target, type = 'eml', context)
|
|
|
403
404
|
});
|
|
404
405
|
}
|
|
405
406
|
else {
|
|
406
|
-
child.append(createElement('div', undefined,
|
|
407
|
+
child.append(createElement('div', undefined, t('email.attachments.nestedUnavailable', { name: attachment.name })));
|
|
407
408
|
}
|
|
408
409
|
}
|
|
409
410
|
catch (nextError) {
|
|
@@ -438,9 +439,9 @@ export default async function renderEmail(buffer, target, type = 'eml', context)
|
|
|
438
439
|
body.append(sidebar, messagePanel);
|
|
439
440
|
root.append(header, body);
|
|
440
441
|
};
|
|
441
|
-
showLoading('
|
|
442
|
+
showLoading(t('email.loading.parsing'));
|
|
442
443
|
try {
|
|
443
|
-
const parsed = await parseEmail(buffer, normalizedType, filename, objectUrls, cidUrls);
|
|
444
|
+
const parsed = await parseEmail(buffer, normalizedType, filename, objectUrls, cidUrls, t);
|
|
444
445
|
renderParsedEmail(parsed);
|
|
445
446
|
}
|
|
446
447
|
catch (nextError) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@file-viewer/renderer-email",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Standalone email renderer plugin for Flyfish File Viewer with EML, MSG, MBOX, attachments, and nested previews.",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"LICENSE"
|
|
56
56
|
],
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@file-viewer/core": "^2.1.
|
|
58
|
+
"@file-viewer/core": "^2.1.3",
|
|
59
59
|
"@kenjiuno/msgreader": "^1.28.0",
|
|
60
60
|
"postal-mime": "^2.7.4"
|
|
61
61
|
},
|