postal-mime 2.2.9 → 2.3.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/CHANGELOG.md +7 -0
- package/package.json +2 -2
- package/src/postal-mime.js +21 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.3.0](https://github.com/postalsys/postal-mime/compare/v2.2.9...v2.3.0) (2024-09-23)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* Treat message/rfc822 as an attachment for delivery-status and feedback-report ([21e6224](https://github.com/postalsys/postal-mime/commit/21e62245aeb416b921ba683dd8628f5948831c56))
|
|
9
|
+
|
|
3
10
|
## [2.2.9](https://github.com/postalsys/postal-mime/compare/v2.2.8...v2.2.9) (2024-09-16)
|
|
4
11
|
|
|
5
12
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postal-mime",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Email parser for browser environments",
|
|
5
5
|
"main": "./src/postal-mime.js",
|
|
6
6
|
"exports": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"author": "Andris Reinman",
|
|
29
29
|
"license": "MIT-0",
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@types/node": "22.
|
|
31
|
+
"@types/node": "22.6.0",
|
|
32
32
|
"cross-blob": "3.0.2",
|
|
33
33
|
"cross-env": "7.0.3",
|
|
34
34
|
"eslint": "8.57.0",
|
package/src/postal-mime.js
CHANGED
|
@@ -123,15 +123,15 @@ export default class PostalMime {
|
|
|
123
123
|
let textTypes = new Set();
|
|
124
124
|
let textMap = (this.textMap = new Map());
|
|
125
125
|
|
|
126
|
+
let forceRfc822Attachments = this.forceRfc822Attachments();
|
|
127
|
+
|
|
126
128
|
let walk = async (node, alternative, related) => {
|
|
127
129
|
alternative = alternative || false;
|
|
128
130
|
related = related || false;
|
|
129
131
|
|
|
130
132
|
if (!node.contentType.multipart) {
|
|
131
|
-
// regular node
|
|
132
|
-
|
|
133
133
|
// is it inline message/rfc822
|
|
134
|
-
if (this.isInlineMessageRfc822(node)) {
|
|
134
|
+
if (this.isInlineMessageRfc822(node) && !forceRfc822Attachments) {
|
|
135
135
|
const subParser = new PostalMime();
|
|
136
136
|
node.subMessage = await subParser.parse(node.content);
|
|
137
137
|
|
|
@@ -168,9 +168,6 @@ export default class PostalMime {
|
|
|
168
168
|
// is it text?
|
|
169
169
|
else if (this.isInlineTextNode(node)) {
|
|
170
170
|
let textType = node.contentType.parsed.value.substr(node.contentType.parsed.value.indexOf('/') + 1);
|
|
171
|
-
if (node.contentType.parsed.value === 'message/delivery-status') {
|
|
172
|
-
textType = 'plain';
|
|
173
|
-
}
|
|
174
171
|
|
|
175
172
|
let selectorNode = alternative || node;
|
|
176
173
|
if (!textMap.has(selectorNode)) {
|
|
@@ -218,13 +215,6 @@ export default class PostalMime {
|
|
|
218
215
|
break;
|
|
219
216
|
}
|
|
220
217
|
|
|
221
|
-
case 'message/delivery-status': {
|
|
222
|
-
// Enforce into unicode
|
|
223
|
-
const decodedText = node.getTextContent().replace(/\r?\n/g, '\n').replace(/\n*$/, '\n');
|
|
224
|
-
attachment.content = textEncoder.encode(decodedText);
|
|
225
|
-
break;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
218
|
// Regular attachments
|
|
229
219
|
default:
|
|
230
220
|
attachment.content = node.content;
|
|
@@ -330,8 +320,6 @@ export default class PostalMime {
|
|
|
330
320
|
switch (node.contentType.parsed.value) {
|
|
331
321
|
case 'text/html':
|
|
332
322
|
case 'text/plain':
|
|
333
|
-
// message/delivery-status is cast into regular plaintext content
|
|
334
|
-
case 'message/delivery-status':
|
|
335
323
|
return true;
|
|
336
324
|
|
|
337
325
|
case 'text/calendar':
|
|
@@ -349,6 +337,24 @@ export default class PostalMime {
|
|
|
349
337
|
return disposition === 'inline';
|
|
350
338
|
}
|
|
351
339
|
|
|
340
|
+
// Check if this is a specially crafted report email where message/rfc822 content should not be inlined
|
|
341
|
+
forceRfc822Attachments() {
|
|
342
|
+
let forceRfc822Attachments = false;
|
|
343
|
+
let walk = node => {
|
|
344
|
+
if (!node.contentType.multipart) {
|
|
345
|
+
if (['message/delivery-status', 'message/feedback-report'].includes(node.contentType.parsed.value)) {
|
|
346
|
+
forceRfc822Attachments = true;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
for (let childNode of node.childNodes) {
|
|
351
|
+
walk(childNode);
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
walk(this.root);
|
|
355
|
+
return forceRfc822Attachments;
|
|
356
|
+
}
|
|
357
|
+
|
|
352
358
|
async resolveStream(stream) {
|
|
353
359
|
let chunkLen = 0;
|
|
354
360
|
let chunks = [];
|