libmime 2.1.3 → 3.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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## v3.0.0 2016-12-08
4
+
5
+ * Updated encoded-word generation. Previously a minimal value was encoded, so it was possible to have multiple encoded words in a string separated by non encoded-words. This was an issue with some webmail clients that stripped out the non-encoded parts between encoded-words so the updated method uses wide match by encoding from the first word with unicode characters to the last word. "a =?b?= c =?d?= e" -> "a =?bcd?= e"
6
+
3
7
  ## v2.1.3 2016-12-08
4
8
 
5
9
  * Revert dot as a special symbol
package/lib/libmime.js CHANGED
@@ -220,12 +220,27 @@ var libmime = module.exports = {
220
220
 
221
221
  maxLength = maxLength || 0;
222
222
 
223
- var decodedValue = libcharset.decode(libcharset.convert((data || ''), fromCharset)),
224
- encodedValue;
223
+ var decodedValue = libcharset.decode(libcharset.convert((data || ''), fromCharset));
224
+ var encodedValue;
225
225
 
226
- encodedValue = decodedValue.replace(/([^\s\u0080-\uFFFF]*[\u0080-\uFFFF]+[^\s\u0080-\uFFFF]*(?:\s+[^\s\u0080-\uFFFF]*[\u0080-\uFFFF]+[^\s\u0080-\uFFFF]*\s*)?)+(?=\s|$)/g, function (match) {
227
- return match.length ? libmime.encodeWord(match, mimeWordEncoding || 'Q', maxLength) : '';
228
- });
226
+ var firstMatch = decodedValue.match(/(?:^|\s)([^\s]*[\u0080-\uFFFF])/);
227
+ if (!firstMatch) {
228
+ return decodedValue;
229
+ }
230
+ var lastMatch = decodedValue.match(/([\u0080-\uFFFF][^\s]*)[^\u0080-\uFFFF]*$/);
231
+ if (!lastMatch) {
232
+ // should not happen
233
+ return decodedValue;
234
+ }
235
+ var startIndex = firstMatch.index + (firstMatch[0].match(/[^\s]/) || {
236
+ index: 0
237
+ }).index;
238
+ var endIndex = lastMatch.index + (lastMatch[1] || '').length;
239
+
240
+ encodedValue =
241
+ (startIndex ? decodedValue.substr(0, startIndex) : '') +
242
+ libmime.encodeWord(decodedValue.substring(startIndex, endIndex), mimeWordEncoding || 'Q', maxLength) +
243
+ (endIndex < decodedValue.length ? decodedValue.substr(endIndex) : '');
229
244
 
230
245
  return encodedValue;
231
246
  },
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.1.3",
4
+ "version": "3.0.0",
5
5
  "main": "lib/libmime",
6
6
  "homepage": "https://github.com/andris9/libmime",
7
7
  "repository": {