libmime 4.2.1 → 5.0.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/.github/FUNDING.yml +4 -0
- package/.prettierrc.js +4 -1
- package/CHANGELOG.md +6 -0
- package/lib/charset.js +3 -9
- package/lib/libmime.js +7 -26
- package/package.json +6 -7
package/.prettierrc.js
CHANGED
package/CHANGELOG.md
CHANGED
package/lib/charset.js
CHANGED
|
@@ -26,10 +26,9 @@ const charset = (module.exports = {
|
|
|
26
26
|
*
|
|
27
27
|
* @param {Buffer} buf Binary data to be decoded
|
|
28
28
|
* @param {String} [fromCharset='UTF-8'] Binary data is decoded into string using this charset
|
|
29
|
-
* @param {Function} [Iconv] node-iconv function
|
|
30
29
|
* @return {String} Decded string
|
|
31
30
|
*/
|
|
32
|
-
decode(buf, fromCharset
|
|
31
|
+
decode(buf, fromCharset) {
|
|
33
32
|
fromCharset = charset.normalizeCharset(fromCharset || 'UTF-8');
|
|
34
33
|
|
|
35
34
|
if (/^(us-)?ascii|utf-8|7bit$/i.test(fromCharset)) {
|
|
@@ -37,11 +36,6 @@ const charset = (module.exports = {
|
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
try {
|
|
40
|
-
if (typeof Iconv === 'function') {
|
|
41
|
-
let decoder = new Iconv(fromCharset, 'UTF-8');
|
|
42
|
-
return decoder.convert(buf).toString();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
39
|
if (/^jis|^iso-?2022-?jp|^EUCJP/i.test(fromCharset)) {
|
|
46
40
|
if (typeof buf === 'string') {
|
|
47
41
|
buf = Buffer.from(buf);
|
|
@@ -75,7 +69,7 @@ const charset = (module.exports = {
|
|
|
75
69
|
* @param {String} [fromCharset='UTF-8'] Source encoding for the string
|
|
76
70
|
* @return {Buffer} UTF-8 encoded typed array
|
|
77
71
|
*/
|
|
78
|
-
convert(data, fromCharset
|
|
72
|
+
convert(data, fromCharset) {
|
|
79
73
|
fromCharset = charset.normalizeCharset(fromCharset || 'UTF-8');
|
|
80
74
|
|
|
81
75
|
let bufString;
|
|
@@ -85,7 +79,7 @@ const charset = (module.exports = {
|
|
|
85
79
|
return data;
|
|
86
80
|
}
|
|
87
81
|
|
|
88
|
-
bufString = charset.decode(data, fromCharset
|
|
82
|
+
bufString = charset.decode(data, fromCharset);
|
|
89
83
|
return charset.encode(bufString);
|
|
90
84
|
}
|
|
91
85
|
return charset.encode(data);
|
package/lib/libmime.js
CHANGED
|
@@ -112,11 +112,7 @@ class Libmime {
|
|
|
112
112
|
* @return {String} Single or several mime words joined together
|
|
113
113
|
*/
|
|
114
114
|
encodeWord(data, mimeWordEncoding, maxLength) {
|
|
115
|
-
mimeWordEncoding = (mimeWordEncoding || 'Q')
|
|
116
|
-
.toString()
|
|
117
|
-
.toUpperCase()
|
|
118
|
-
.trim()
|
|
119
|
-
.charAt(0);
|
|
115
|
+
mimeWordEncoding = (mimeWordEncoding || 'Q').toString().toUpperCase().trim().charAt(0);
|
|
120
116
|
maxLength = maxLength || 0;
|
|
121
117
|
|
|
122
118
|
let encodedStr;
|
|
@@ -129,10 +125,7 @@ class Libmime {
|
|
|
129
125
|
if (mimeWordEncoding === 'Q') {
|
|
130
126
|
// https://tools.ietf.org/html/rfc2047#section-5 rule (3)
|
|
131
127
|
encodedStr = libqp.encode(data).replace(/[^a-z0-9!*+\-/=]/gi, chr => {
|
|
132
|
-
let ord = chr
|
|
133
|
-
.charCodeAt(0)
|
|
134
|
-
.toString(16)
|
|
135
|
-
.toUpperCase();
|
|
128
|
+
let ord = chr.charCodeAt(0).toString(16).toUpperCase();
|
|
136
129
|
if (chr === ' ') {
|
|
137
130
|
return '_';
|
|
138
131
|
} else {
|
|
@@ -234,7 +227,7 @@ class Libmime {
|
|
|
234
227
|
str = Buffer.from(str);
|
|
235
228
|
}
|
|
236
229
|
|
|
237
|
-
return libcharset.decode(str, charset
|
|
230
|
+
return libcharset.decode(str, charset);
|
|
238
231
|
}
|
|
239
232
|
|
|
240
233
|
/**
|
|
@@ -254,7 +247,7 @@ class Libmime {
|
|
|
254
247
|
|
|
255
248
|
maxLength = maxLength || 0;
|
|
256
249
|
|
|
257
|
-
let decodedValue = libcharset.decode(libcharset.convert(data || '', fromCharset
|
|
250
|
+
let decodedValue = libcharset.decode(libcharset.convert(data || '', fromCharset));
|
|
258
251
|
let encodedValue;
|
|
259
252
|
|
|
260
253
|
let firstMatch = decodedValue.match(/(?:^|\s)([^\s]*[\u0080-\uFFFF])/);
|
|
@@ -723,10 +716,7 @@ class Libmime {
|
|
|
723
716
|
* @return {String} File extension
|
|
724
717
|
*/
|
|
725
718
|
detectExtension(mimeType) {
|
|
726
|
-
mimeType = (mimeType || '')
|
|
727
|
-
.toString()
|
|
728
|
-
.toLowerCase()
|
|
729
|
-
.replace(/\s/g, '');
|
|
719
|
+
mimeType = (mimeType || '').toString().toLowerCase().replace(/\s/g, '');
|
|
730
720
|
if (!(mimeType in mimetypes.list)) {
|
|
731
721
|
return 'bin';
|
|
732
722
|
}
|
|
@@ -756,13 +746,7 @@ class Libmime {
|
|
|
756
746
|
* @return {String} File extension
|
|
757
747
|
*/
|
|
758
748
|
detectMimeType(extension) {
|
|
759
|
-
extension = (extension || '')
|
|
760
|
-
.toString()
|
|
761
|
-
.toLowerCase()
|
|
762
|
-
.replace(/\s/g, '')
|
|
763
|
-
.replace(/^\./g, '')
|
|
764
|
-
.split('.')
|
|
765
|
-
.pop();
|
|
749
|
+
extension = (extension || '').toString().toLowerCase().replace(/\s/g, '').replace(/^\./g, '').split('.').pop();
|
|
766
750
|
|
|
767
751
|
if (!(extension in mimetypes.extensions)) {
|
|
768
752
|
return 'application/octet-stream';
|
|
@@ -882,10 +866,7 @@ class Libmime {
|
|
|
882
866
|
|
|
883
867
|
encodeURICharComponent(chr) {
|
|
884
868
|
let res = '';
|
|
885
|
-
let ord = chr
|
|
886
|
-
.charCodeAt(0)
|
|
887
|
-
.toString(16)
|
|
888
|
-
.toUpperCase();
|
|
869
|
+
let ord = chr.charCodeAt(0).toString(16).toUpperCase();
|
|
889
870
|
|
|
890
871
|
if (ord.length % 2) {
|
|
891
872
|
ord = '0' + ord;
|
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
|
+
"version": "5.0.0",
|
|
5
5
|
"main": "lib/libmime",
|
|
6
6
|
"homepage": "https://github.com/andris9/libmime",
|
|
7
7
|
"repository": {
|
|
@@ -20,19 +20,18 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"encoding-japanese": "1.0.30",
|
|
23
|
-
"iconv-lite": "0.
|
|
23
|
+
"iconv-lite": "0.6.2",
|
|
24
24
|
"libbase64": "1.2.1",
|
|
25
25
|
"libqp": "1.1.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"chai": "4.2.0",
|
|
29
29
|
"eslint-config-nodemailer": "1.2.0",
|
|
30
|
-
"eslint-config-prettier": "6.
|
|
31
|
-
"grunt": "1.
|
|
30
|
+
"eslint-config-prettier": "6.11.0",
|
|
31
|
+
"grunt": "1.2.1",
|
|
32
32
|
"grunt-cli": "1.3.2",
|
|
33
|
-
"grunt-eslint": "
|
|
33
|
+
"grunt-eslint": "23.0.0",
|
|
34
34
|
"grunt-mocha-test": "0.13.3",
|
|
35
|
-
"
|
|
36
|
-
"mocha": "6.2.2"
|
|
35
|
+
"mocha": "8.0.1"
|
|
37
36
|
}
|
|
38
37
|
}
|