@zone-eu/mailsplit 5.4.8 → 5.4.9
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/headers.js +30 -6
- package/package.json +2 -2
package/lib/headers.js
CHANGED
|
@@ -42,7 +42,7 @@ class Headers {
|
|
|
42
42
|
this._parseHeaders();
|
|
43
43
|
}
|
|
44
44
|
key = this._normalizeHeader(key);
|
|
45
|
-
let lines = this.lines.filter(line => line.key === key).map(line => line.line);
|
|
45
|
+
let lines = this.lines.filter(line => line.key === key).map(line => this._decodeHeaderValue(line.line));
|
|
46
46
|
|
|
47
47
|
return lines;
|
|
48
48
|
}
|
|
@@ -62,7 +62,7 @@ class Headers {
|
|
|
62
62
|
if (!header) {
|
|
63
63
|
return '';
|
|
64
64
|
}
|
|
65
|
-
return ((this.libmime.decodeHeader(header.line) || {}).value || '').toString().trim();
|
|
65
|
+
return ((this.libmime.decodeHeader(this._decodeHeaderValue(header.line)) || {}).value || '').toString().trim();
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
getList() {
|
|
@@ -174,17 +174,27 @@ class Headers {
|
|
|
174
174
|
|
|
175
175
|
lineEnd = lineEnd || '\r\n';
|
|
176
176
|
|
|
177
|
-
let headers = this.lines
|
|
177
|
+
let headers = this.lines
|
|
178
|
+
.map(line => this._buildHeaderLine(line.line.replace(/\r?\n/g, lineEnd)))
|
|
179
|
+
.reduce((joined, line, idx) => {
|
|
180
|
+
if (idx) {
|
|
181
|
+
joined.push(Buffer.from(lineEnd, 'binary'));
|
|
182
|
+
}
|
|
183
|
+
joined.push(line);
|
|
184
|
+
return joined;
|
|
185
|
+
}, []);
|
|
186
|
+
|
|
187
|
+
headers.push(Buffer.from(lineEnd + lineEnd, 'binary'));
|
|
178
188
|
|
|
179
189
|
if (this.mbox) {
|
|
180
|
-
headers
|
|
190
|
+
headers.unshift(Buffer.from(this.mbox + lineEnd, 'binary'));
|
|
181
191
|
}
|
|
182
192
|
|
|
183
193
|
if (this.http) {
|
|
184
|
-
headers
|
|
194
|
+
headers.unshift(Buffer.from(this.http + lineEnd, 'binary'));
|
|
185
195
|
}
|
|
186
196
|
|
|
187
|
-
return Buffer.
|
|
197
|
+
return Buffer.concat(headers);
|
|
188
198
|
}
|
|
189
199
|
|
|
190
200
|
_normalizeHeader(key) {
|
|
@@ -232,6 +242,20 @@ class Headers {
|
|
|
232
242
|
this.lines = lines;
|
|
233
243
|
this.parsed = true;
|
|
234
244
|
}
|
|
245
|
+
|
|
246
|
+
_buildHeaderLine(line) {
|
|
247
|
+
let value = this._decodeHeaderValue(line);
|
|
248
|
+
return Buffer.from(value, value === line ? 'binary' : 'utf8');
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
_decodeHeaderValue(str) {
|
|
252
|
+
if (!str) {
|
|
253
|
+
return str;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
let utf8 = Buffer.from(str, 'binary').toString('utf8');
|
|
257
|
+
return utf8.includes('\uFFFD') ? str : utf8;
|
|
258
|
+
}
|
|
235
259
|
}
|
|
236
260
|
|
|
237
261
|
// expose to the world
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zone-eu/mailsplit",
|
|
3
|
-
"version": "5.4.
|
|
3
|
+
"version": "5.4.9",
|
|
4
4
|
"description": "Split email messages into an object stream",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"directories": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"license": "(MIT OR EUPL-1.1+)",
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"libbase64": "1.3.0",
|
|
17
|
-
"libmime": "5.3.
|
|
17
|
+
"libmime": "5.3.8",
|
|
18
18
|
"libqp": "2.1.1"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|