Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed parseMimeWords

  • Loading branch information...
commit 4c80d5c7045ae2900013852539ed3dca988a8cb8 1 parent 220038a
Andris Reinman authored
Showing with 34 additions and 7 deletions.
  1. +5 −4 lib/mimelib.js
  2. +1 −1  package.json
  3. +28 −2 test/mimelib.js
View
9 lib/mimelib.js
@@ -17,7 +17,7 @@ module.exports.decodeMimeWord = function(str){
};
module.exports.parseMimeWords = function(str){
- return module.exports.decodeMimeWords(str).toString("utf-8");
+ return module.exports.mimeFunctions.decodeMimeWords(str).toString("utf-8");
};
module.exports.encodeQuotedPrintable = function(str, mimeWord, charset){
@@ -192,9 +192,10 @@ module.exports.mimeFunctions = {
decodeMimeWords: function(str, toCharset){
str = (str || "").toString();
- str = str.replace(/(\=\?[\w_\-]+\?[QB]\?[^\?]+\?\=)/g, (function(mimeWord){
- return this.decodeMimeWord(mimeWord);
- }).bind(this));
+ str = str.replace(/(\=\?[\w_\-]+\?[QB]\?[^\?]+\?\=)\s+(?=\=\?[\w_\-]+\?[QB]\?[^\?]+\?\=)/g,"$1").
+ replace(/\=\?[\w_\-]+\?[QB]\?[^\?]+\?\=/g, (function(mimeWord){
+ return this.decodeMimeWord(mimeWord);
+ }).bind(this));
return convert(str, toCharset);
},
View
2  package.json
@@ -1,7 +1,7 @@
{
"name": "mimelib",
"description": "MIME functions to encode/decode e-mails etc.",
- "version": "0.2.0",
+ "version": "0.2.1",
"author" : "Andris Reinman",
"homepage":"http://github.com/andris9/mimelib",
"maintainers":[
View
30 test/mimelib.js
@@ -52,5 +52,31 @@ exports["Quoted printable"] = {
}
exports["Base64"] = {
-
-}
+ "Convert string": function(test){
+ test.equal("VGVyZSDVxNbcIQ==", mimelib.encodeBase64("Tere ÕÄÖÜ!", "Latin_1"));
+ test.done();
+ },
+
+ "Decode string": function(test){
+ test.equal("Tere ÕÄÖÜ!", mimelib.decodeBase64("VGVyZSDVxNbcIQ==", "Latin_1"));
+ test.done();
+ }
+}
+
+exports["Mime Words"] = {
+ "Encode Mime Word QP": function(test){
+ test.equal("=?ISO-8859-13?Q?J=F5ge-va=DE?=", mimelib.encodeMimeWord("Jõge-vaŽ", "Q", "iso-8859-13"));
+ test.done();
+ },
+
+ "Decode Mime Word QP": function(test){
+ test.equal("Jõge-vaŽ", mimelib.decodeMimeWord("=?ISO-8859-13?Q?J=F5ge-va=DE?="));
+ test.done();
+ },
+
+ "Parse Mime Words": function(test){
+ test.equal("Jõge-vaŽ zz Jõge-vaŽJõge-vaŽJõge-vaŽ", mimelib.parseMimeWords("=?ISO-8859-13?Q?J=F5ge-va=DE?= zz =?ISO-8859-13?Q?J=F5ge-va=DE?= =?ISO-8859-13?Q?J=F5ge-va=DE?= =?ISO-8859-13?Q?J=F5ge-va=DE?="))
+ test.done();
+ }
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.