libmime 2.0.3 → 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 CHANGED
@@ -45,7 +45,8 @@ module.exports = {
45
45
  'no-bitwise': 2,
46
46
  'no-lonely-if': 2,
47
47
  'no-mixed-spaces-and-tabs': 2,
48
- 'no-console': 2
48
+ 'no-console': 2,
49
+ 'no-control-regex': 0
49
50
  },
50
51
  env: {
51
52
  es6: false,
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
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
+
3
7
  ## v2.0.3 2016-02-29
4
8
 
5
9
  * Fixed an issue with rfc2231 filenames
package/lib/charset.js CHANGED
@@ -72,7 +72,7 @@ var charset = module.exports = {
72
72
  return 'UTF-' + match[1];
73
73
  }
74
74
 
75
- if ((match = charset.match(/^win[\-_]?(\d+)$/i))) {
75
+ if ((match = charset.match(/^win(?:dows)?[\-_]?(\d+)$/i))) {
76
76
  return 'WINDOWS-' + match[1];
77
77
  }
78
78
 
package/lib/libmime.js CHANGED
@@ -229,14 +229,29 @@ var libmime = module.exports = {
229
229
  * @return {String} Decoded unicode string
230
230
  */
231
231
  decodeWords: function (str) {
232
- str = (str || '').toString();
233
- str = str.
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
234
249
  replace(/(=\?[^?]+\?[QqBb]\?[^?]+\?=)\s+(?==\?[^?]+\?[QqBb]\?[^?]+\?=)/g, '$1').
250
+
251
+ // decode words
235
252
  replace(/\=\?([\w_\-\*]+)\?([QqBb])\?[^\?]+\?\=/g, function (mimeWord) {
236
253
  return libmime.decodeWord(mimeWord);
237
254
  });
238
-
239
- return str;
240
255
  },
241
256
 
242
257
  /**
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.0.3",
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",
@@ -25,10 +25,10 @@
25
25
  },
26
26
  "devDependencies": {
27
27
  "chai": "^3.5.0",
28
- "grunt": "^0.4.5",
29
- "grunt-cli": "^0.1.13",
30
- "grunt-eslint": "^18.0.0",
28
+ "grunt": "^1.0.1",
29
+ "grunt-cli": "^1.2.0",
30
+ "grunt-eslint": "^19.0.0",
31
31
  "grunt-mocha-test": "^0.12.7",
32
- "mocha": "^2.4.5"
32
+ "mocha": "^3.0.2"
33
33
  }
34
34
  }