libmime 2.0.0 → 2.1.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/.eslintrc.js +2 -1
- package/CHANGELOG.md +16 -0
- package/lib/charset.js +1 -1
- package/lib/libmime.js +38 -11
- package/package.json +7 -6
package/.eslintrc.js
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v2.1.0 2016-07-24
|
|
4
|
+
|
|
5
|
+
* Changed handling of base64 encoded mime words where multiple words are joined together if possible. This fixes issues with multi byte characters getting split into different mime words (against the RFC but occurs)
|
|
6
|
+
|
|
7
|
+
## v2.0.3 2016-02-29
|
|
8
|
+
|
|
9
|
+
* Fixed an issue with rfc2231 filenames
|
|
10
|
+
|
|
11
|
+
## v2.0.2 2016-02-11
|
|
12
|
+
|
|
13
|
+
* Fixed an issue with base64 mime words encoding
|
|
14
|
+
|
|
15
|
+
## v2.0.1 2016-02-11
|
|
16
|
+
|
|
17
|
+
* Fix base64 mime-word encoding. Final string length was calculated invalidly
|
|
18
|
+
|
|
3
19
|
## v2.0.0 2016-01-04
|
|
4
20
|
|
|
5
21
|
* Replaced jshint with eslint
|
package/lib/charset.js
CHANGED
package/lib/libmime.js
CHANGED
|
@@ -105,7 +105,7 @@ var libmime = module.exports = {
|
|
|
105
105
|
|
|
106
106
|
var encodedStr,
|
|
107
107
|
toCharset = 'UTF-8',
|
|
108
|
-
i, len, parts;
|
|
108
|
+
i, len, parts, lpart, chr;
|
|
109
109
|
|
|
110
110
|
if (maxLength && maxLength > 7 + toCharset.length) {
|
|
111
111
|
maxLength -= (7 + toCharset.length);
|
|
@@ -123,18 +123,30 @@ var libmime = module.exports = {
|
|
|
123
123
|
});
|
|
124
124
|
} else if (mimeWordEncoding === 'B') {
|
|
125
125
|
encodedStr = typeof data === 'string' ? data : libbase64.encode(data);
|
|
126
|
-
maxLength = Math.max(3, (maxLength - maxLength % 4) / 4 * 3);
|
|
126
|
+
maxLength = maxLength ? Math.max(3, (maxLength - maxLength % 4) / 4 * 3) : 0;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
if (maxLength && encodedStr.length > maxLength) {
|
|
129
|
+
if (maxLength && (mimeWordEncoding !== 'B' ? encodedStr : libbase64.encode(data)).length > maxLength) {
|
|
130
130
|
if (mimeWordEncoding === 'Q') {
|
|
131
131
|
encodedStr = splitMimeEncodedString(encodedStr, maxLength).join('?= =?' + toCharset + '?' + mimeWordEncoding + '?');
|
|
132
132
|
} else {
|
|
133
|
-
|
|
134
133
|
// RFC2047 6.3 (2) states that encoded-word must include an integral number of characters, so no chopping unicode sequences
|
|
135
134
|
parts = [];
|
|
136
|
-
|
|
137
|
-
|
|
135
|
+
lpart = '';
|
|
136
|
+
for (i = 0, len = encodedStr.length; i < len; i++) {
|
|
137
|
+
chr = encodedStr.charAt(i);
|
|
138
|
+
// check if we can add this character to the existing string
|
|
139
|
+
// without breaking byte length limit
|
|
140
|
+
if (Buffer.byteLength(lpart + chr) <= maxLength || i === 0) {
|
|
141
|
+
lpart += chr;
|
|
142
|
+
} else {
|
|
143
|
+
// we hit the length limit, so push the existing string and start over
|
|
144
|
+
parts.push(libbase64.encode(lpart));
|
|
145
|
+
lpart = chr;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (lpart) {
|
|
149
|
+
parts.push(libbase64.encode(lpart));
|
|
138
150
|
}
|
|
139
151
|
|
|
140
152
|
if (parts.length > 1) {
|
|
@@ -217,14 +229,29 @@ var libmime = module.exports = {
|
|
|
217
229
|
* @return {String} Decoded unicode string
|
|
218
230
|
*/
|
|
219
231
|
decodeWords: function (str) {
|
|
220
|
-
|
|
221
|
-
|
|
232
|
+
return (str || '').toString().
|
|
233
|
+
|
|
234
|
+
// find base64 words that can be joined
|
|
235
|
+
replace(/(=\?([^?]+)\?[Bb]\?[^?]+[^^=]\?=)\s*(?==\?([^?]+)\?[Bb]\?[^?]+\?=)/g,
|
|
236
|
+
function (match, left, chLeft, chRight) {
|
|
237
|
+
// only mark to b64 chunks to be joined if charsets match
|
|
238
|
+
if (libcharset.normalizeCharset(chLeft || '').toLowerCase().trim() === libcharset.normalizeCharset(chRight || '').toLowerCase().trim()) {
|
|
239
|
+
// set a joiner marker
|
|
240
|
+
return left + '__\x00JOIN\x00__';
|
|
241
|
+
}
|
|
242
|
+
return match;
|
|
243
|
+
}).
|
|
244
|
+
|
|
245
|
+
// join base64 encoded words
|
|
246
|
+
replace(/(\?=)?__\x00JOIN\x00__(=\?([^?]+)\?[Bb]\?)?/g, '').
|
|
247
|
+
|
|
248
|
+
// remove spaces between mime encoded words
|
|
222
249
|
replace(/(=\?[^?]+\?[QqBb]\?[^?]+\?=)\s+(?==\?[^?]+\?[QqBb]\?[^?]+\?=)/g, '$1').
|
|
250
|
+
|
|
251
|
+
// decode words
|
|
223
252
|
replace(/\=\?([\w_\-\*]+)\?([QqBb])\?[^\?]+\?\=/g, function (mimeWord) {
|
|
224
253
|
return libmime.decodeWord(mimeWord);
|
|
225
254
|
});
|
|
226
|
-
|
|
227
|
-
return str;
|
|
228
255
|
},
|
|
229
256
|
|
|
230
257
|
/**
|
|
@@ -293,7 +320,7 @@ var libmime = module.exports = {
|
|
|
293
320
|
var value = structured.params[param];
|
|
294
321
|
if (!libmime.isPlainText(value) || value.length >= 75) {
|
|
295
322
|
libmime.buildHeaderParam(param, value, 50).forEach(function (encodedParam) {
|
|
296
|
-
if (!/[\s"\\;\/=]|^[\-']|'$/.test(encodedParam.value)) {
|
|
323
|
+
if (!/[\s"\\;\/=]|^[\-']|'$/.test(encodedParam.value) || encodedParam.key.substr(-1) === '*') {
|
|
297
324
|
paramsArray.push(encodedParam.key + '=' + encodedParam.value);
|
|
298
325
|
} else {
|
|
299
326
|
paramsArray.push(encodedParam.key + '=' + JSON.stringify(encodedParam.value));
|
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": "2.
|
|
4
|
+
"version": "2.1.0",
|
|
5
5
|
"main": "lib/libmime",
|
|
6
6
|
"homepage": "https://github.com/andris9/libmime",
|
|
7
7
|
"repository": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
],
|
|
17
17
|
"author": "Andris Reinman <andris@kreata.ee>",
|
|
18
18
|
"scripts": {
|
|
19
|
-
"test": "grunt"
|
|
19
|
+
"test": "grunt mochaTest"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"iconv-lite": "0.4.13",
|
|
@@ -24,10 +24,11 @@
|
|
|
24
24
|
"libqp": "1.1.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"chai": "^3.
|
|
28
|
-
"grunt": "^0.
|
|
29
|
-
"grunt-
|
|
27
|
+
"chai": "^3.5.0",
|
|
28
|
+
"grunt": "^1.0.1",
|
|
29
|
+
"grunt-cli": "^1.2.0",
|
|
30
|
+
"grunt-eslint": "^19.0.0",
|
|
30
31
|
"grunt-mocha-test": "^0.12.7",
|
|
31
|
-
"mocha": "^
|
|
32
|
+
"mocha": "^3.0.2"
|
|
32
33
|
}
|
|
33
34
|
}
|