@zone-eu/mailsplit 5.4.28 → 5.4.29
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/mime-node.js +9 -57
- package/package.json +1 -1
package/lib/mime-node.js
CHANGED
|
@@ -12,7 +12,7 @@ const pathlib = require('path');
|
|
|
12
12
|
/** @typedef {import('..').PartNumberItem} PartNumberItem */
|
|
13
13
|
/** @typedef {import('..').PartNumber} PartNumber */
|
|
14
14
|
/** @typedef {import('..').SplitterOptions} SplitterOptions */
|
|
15
|
-
/** @typedef {import('libmime').
|
|
15
|
+
/** @typedef {import('libmime').ParsedHeaderValue} StructuredHeader */
|
|
16
16
|
/** @typedef {import('stream').Transform | import('stream').PassThrough} ContentStream */
|
|
17
17
|
/** @typedef {import('..').MimeNode} MimeNodeType */
|
|
18
18
|
|
|
@@ -51,59 +51,6 @@ function stripComments(value) {
|
|
|
51
51
|
.join('');
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
/**
|
|
55
|
-
* Lists the parameters a header value gives in RFC 2231 form (`name*=`, `name*0=` or
|
|
56
|
-
* `name*0*=`). libmime decodes those while parsing the header, so the result must not
|
|
57
|
-
* go through `decodeWords` as well: a value like `filename*=utf-8''a%3D%3Futf-8%3FQ%3F%3D2Eexe%3F%3D`
|
|
58
|
-
* would otherwise come out as `a.exe` while a parser that decodes once sees the encoded word.
|
|
59
|
-
*
|
|
60
|
-
* @param {string} value Raw header value.
|
|
61
|
-
* @returns {Set<string>} Lowercased parameter names.
|
|
62
|
-
*/
|
|
63
|
-
function rfc2231ParamNames(value) {
|
|
64
|
-
let names = new Set();
|
|
65
|
-
let quote = false;
|
|
66
|
-
let escaped = false;
|
|
67
|
-
let start = 0;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* @param {number} end End offset of the segment starting at `start`.
|
|
71
|
-
* @returns {void}
|
|
72
|
-
*/
|
|
73
|
-
let addSegment = end => {
|
|
74
|
-
let segment = value.substring(start, end);
|
|
75
|
-
let eq = segment.indexOf('=');
|
|
76
|
-
if (eq < 0) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
let match = segment
|
|
80
|
-
.substring(0, eq)
|
|
81
|
-
.trim()
|
|
82
|
-
.toLowerCase()
|
|
83
|
-
.match(/^(.+?)\*(\d+\*?)?$/);
|
|
84
|
-
if (match) {
|
|
85
|
-
names.add(match[1]);
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
for (let i = 0; i < value.length; i++) {
|
|
90
|
-
let chr = value.charAt(i);
|
|
91
|
-
if (escaped) {
|
|
92
|
-
escaped = false;
|
|
93
|
-
} else if (chr === '\\') {
|
|
94
|
-
escaped = true;
|
|
95
|
-
} else if (chr === '"') {
|
|
96
|
-
quote = !quote;
|
|
97
|
-
} else if (chr === ';' && !quote) {
|
|
98
|
-
addSegment(i);
|
|
99
|
-
start = i + 1;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
addSegment(value.length);
|
|
103
|
-
|
|
104
|
-
return names;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
54
|
/**
|
|
108
55
|
* Parsed MIME node with mutable headers and transfer-encoding helpers.
|
|
109
56
|
*/
|
|
@@ -283,10 +230,15 @@ class MimeNode {
|
|
|
283
230
|
}
|
|
284
231
|
|
|
285
232
|
if (this.filename) {
|
|
286
|
-
//
|
|
233
|
+
// A parameter given in RFC 2231 form was decoded by libmime already, which names
|
|
234
|
+
// it in decodedParams, and must not go through decodeWords as well:
|
|
235
|
+
// filename*=utf-8''a%3D%3Futf-8%3FQ%3F%3D2Eexe%3F%3D would otherwise come out as
|
|
236
|
+
// a.exe while a parser that decodes once sees the encoded word. A second scan of
|
|
237
|
+
// the raw header for the name used to decide this, and read `(c)filename*=` as
|
|
238
|
+
// a parameter named `(c)filename` once the comment was dropped from the real one
|
|
287
239
|
let decoded = parsedContentDisposition.params.filename
|
|
288
|
-
?
|
|
289
|
-
:
|
|
240
|
+
? parsedContentDisposition.decodedParams.includes('filename')
|
|
241
|
+
: parsedContentType.decodedParams.includes('name');
|
|
290
242
|
if (!decoded) {
|
|
291
243
|
try {
|
|
292
244
|
this.filename = this.libmime.decodeWords(this.filename);
|