libmime 4.1.2 → 4.2.1
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/.eslintrc +3 -2
- package/CHANGELOG.md +13 -0
- package/lib/charset.js +21 -0
- package/lib/libmime.js +10 -5
- package/package.json +8 -7
package/.eslintrc
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v4.2.1 2019-10-28
|
|
4
|
+
|
|
5
|
+
- Replace jconv with more recent encoding-japanese
|
|
6
|
+
|
|
7
|
+
## v4.2.0 2019-10-28
|
|
8
|
+
|
|
9
|
+
- Use jconv module to parse ISO-2022-JP by default
|
|
10
|
+
|
|
11
|
+
## v4.1.4 2019-10-28
|
|
12
|
+
|
|
13
|
+
- decodeWords should also decode empty content part [WeiAnAn](9bbcfd2)
|
|
14
|
+
- fix decode base64 ending with = [WeiAnAn](6e656e2)
|
|
15
|
+
|
|
3
16
|
## v4.1.0 2019-05-01
|
|
4
17
|
|
|
5
18
|
- Experimental support for node-iconv
|
package/lib/charset.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const iconv = require('iconv-lite');
|
|
4
|
+
const encodingJapanese = require('encoding-japanese');
|
|
4
5
|
const charsets = require('./charsets');
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -40,6 +41,26 @@ const charset = (module.exports = {
|
|
|
40
41
|
let decoder = new Iconv(fromCharset, 'UTF-8');
|
|
41
42
|
return decoder.convert(buf).toString();
|
|
42
43
|
}
|
|
44
|
+
|
|
45
|
+
if (/^jis|^iso-?2022-?jp|^EUCJP/i.test(fromCharset)) {
|
|
46
|
+
if (typeof buf === 'string') {
|
|
47
|
+
buf = Buffer.from(buf);
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
let output = encodingJapanese.convert(buf, {
|
|
51
|
+
to: 'UNICODE',
|
|
52
|
+
from: fromCharset,
|
|
53
|
+
type: 'string'
|
|
54
|
+
});
|
|
55
|
+
if (typeof output === 'string') {
|
|
56
|
+
output = Buffer.from(output);
|
|
57
|
+
}
|
|
58
|
+
return output;
|
|
59
|
+
} catch (err) {
|
|
60
|
+
// ignore, defaults to iconv-lite on error
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
43
64
|
return iconv.decode(buf, fromCharset);
|
|
44
65
|
} catch (err) {
|
|
45
66
|
// enforce utf-8, data loss might occur
|
package/lib/libmime.js
CHANGED
|
@@ -223,7 +223,12 @@ class Libmime {
|
|
|
223
223
|
}
|
|
224
224
|
str = Buffer.from(bytes);
|
|
225
225
|
} else if (encoding === 'B') {
|
|
226
|
-
str = Buffer.
|
|
226
|
+
str = Buffer.concat(
|
|
227
|
+
str
|
|
228
|
+
.split('=')
|
|
229
|
+
.filter(s => s !== '') // filter empty string
|
|
230
|
+
.map(str => Buffer.from(str, 'base64'))
|
|
231
|
+
);
|
|
227
232
|
} else {
|
|
228
233
|
// keep as is, convert Buffer to unicode string, assume utf8
|
|
229
234
|
str = Buffer.from(str);
|
|
@@ -289,7 +294,7 @@ class Libmime {
|
|
|
289
294
|
(str || '')
|
|
290
295
|
.toString()
|
|
291
296
|
// find base64 words that can be joined
|
|
292
|
-
.replace(/(=\?([^?]+)\?[Bb]\?[^?]
|
|
297
|
+
.replace(/(=\?([^?]+)\?[Bb]\?[^?]*\?=)\s*(?==\?([^?]+)\?[Bb]\?[^?]*\?=)/g, (match, left, chLeft, chRight) => {
|
|
293
298
|
// only mark b64 chunks to be joined if charsets match
|
|
294
299
|
if (libcharset.normalizeCharset(chLeft || '') === libcharset.normalizeCharset(chRight || '')) {
|
|
295
300
|
// set a joiner marker
|
|
@@ -298,7 +303,7 @@ class Libmime {
|
|
|
298
303
|
return match;
|
|
299
304
|
})
|
|
300
305
|
// find QP words that can be joined
|
|
301
|
-
.replace(/(=\?([^?]+)\?[Qq]\?[^?]
|
|
306
|
+
.replace(/(=\?([^?]+)\?[Qq]\?[^?]*\?=)\s*(?==\?([^?]+)\?[Qq]\?[^?]*\?=)/g, (match, left, chLeft, chRight) => {
|
|
302
307
|
// only mark QP chunks to be joined if charsets match
|
|
303
308
|
if (libcharset.normalizeCharset(chLeft || '') === libcharset.normalizeCharset(chRight || '')) {
|
|
304
309
|
// set a joiner marker
|
|
@@ -309,9 +314,9 @@ class Libmime {
|
|
|
309
314
|
// join base64 encoded words
|
|
310
315
|
.replace(/(\?=)?__\x00JOIN\x00__(=\?([^?]+)\?[QqBb]\?)?/g, '')
|
|
311
316
|
// remove spaces between mime encoded words
|
|
312
|
-
.replace(/(=\?[^?]+\?[QqBb]\?[^?]
|
|
317
|
+
.replace(/(=\?[^?]+\?[QqBb]\?[^?]*\?=)\s+(?==\?[^?]+\?[QqBb]\?[^?]*\?=)/g, '$1')
|
|
313
318
|
// decode words
|
|
314
|
-
.replace(/=\?([\w_\-*]+)\?([QqBb])\?([^?]
|
|
319
|
+
.replace(/=\?([\w_\-*]+)\?([QqBb])\?([^?]*)\?=/g, (m, charset, encoding, text) => this.decodeWord(charset, encoding, text))
|
|
315
320
|
);
|
|
316
321
|
}
|
|
317
322
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libmime",
|
|
3
3
|
"description": "Encode and decode quoted printable and base64 strings",
|
|
4
|
-
"version": "4.1
|
|
4
|
+
"version": "4.2.1",
|
|
5
5
|
"main": "lib/libmime",
|
|
6
6
|
"homepage": "https://github.com/andris9/libmime",
|
|
7
7
|
"repository": {
|
|
@@ -19,19 +19,20 @@
|
|
|
19
19
|
"test": "grunt"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"
|
|
23
|
-
"
|
|
22
|
+
"encoding-japanese": "1.0.30",
|
|
23
|
+
"iconv-lite": "0.5.0",
|
|
24
|
+
"libbase64": "1.2.1",
|
|
24
25
|
"libqp": "1.1.0"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
28
|
"chai": "4.2.0",
|
|
28
29
|
"eslint-config-nodemailer": "1.2.0",
|
|
29
|
-
"eslint-config-prettier": "
|
|
30
|
+
"eslint-config-prettier": "6.5.0",
|
|
30
31
|
"grunt": "1.0.4",
|
|
31
32
|
"grunt-cli": "1.3.2",
|
|
32
|
-
"grunt-eslint": "
|
|
33
|
+
"grunt-eslint": "22.0.0",
|
|
33
34
|
"grunt-mocha-test": "0.13.3",
|
|
34
|
-
"iconv": "
|
|
35
|
-
"mocha": "6.
|
|
35
|
+
"iconv": "2.3.5",
|
|
36
|
+
"mocha": "6.2.2"
|
|
36
37
|
}
|
|
37
38
|
}
|