mailparser
Advanced tools
Comparing version 0.2.8 to 0.2.9
@@ -130,3 +130,3 @@ | ||
if(this.options.debug && this._remainder){ | ||
console.log("REMAINDER: "+this._remainder) | ||
console.log("REMAINDER: "+this._remainder); | ||
} | ||
@@ -496,3 +496,3 @@ | ||
value = parts[i].split("="); | ||
key = value.shift().trim(); | ||
key = value.shift().trim().toLowerCase(); | ||
value = value.join("=").trim(); | ||
@@ -623,3 +623,3 @@ | ||
if(["quoted-printable", "base64"].indexOf(this._currentNode.meta.transferEncoding)>=0){ | ||
if(["quoted-printable", "base64"].indexOf(this._currentNode.meta.transferEncoding)>=0 || this._currentNode.meta.textFormat != "flowed"){ | ||
if(typeof this._currentNode.content != "string"){ | ||
@@ -631,16 +631,8 @@ this._currentNode.content = line; | ||
}else{ | ||
if(this._currentNode.meta.textFormat != "flowed"){ | ||
if(typeof this._currentNode.content != "string"){ | ||
this._currentNode.content = this._encodeString(line); | ||
}else{ | ||
this._currentNode.content += "\n" + this._encodeString(line); | ||
} | ||
if(typeof this._currentNode.content != "string"){ | ||
this._currentNode.content = line; | ||
}else if(this._currentNode.content.match(/[ ]{1,}$/)){ | ||
this._currentNode.content += line; | ||
}else{ | ||
if(typeof this._currentNode.content != "string"){ | ||
this._currentNode.content = this._encodeString(line); | ||
}else if(this._currentNode.content.match(/[ ]{1,}$/)){ | ||
this._currentNode.content += this._encodeString(line); | ||
}else{ | ||
this._currentNode.content += "\n"+this._encodeString(line); | ||
} | ||
this._currentNode.content += "\n"+line; | ||
} | ||
@@ -684,3 +676,9 @@ } | ||
if(this._currentNode.content){ | ||
if(!this._currentNode.attachment){ | ||
if(this._currentNode.meta.contentType == "text/html"){ | ||
this._currentNode.meta.charset = this._detectHTMLCharset(this._currentNode.content) || this.options.defaultCharset || "iso-8859-1"; | ||
} | ||
if(this._currentNode.meta.transferEncoding == "quoted-printable"){ | ||
@@ -690,2 +688,4 @@ this._currentNode.content = mimelib.decodeQuotedPrintable(this._currentNode.content, false, this._currentNode.meta.charset || this.options.defaultCharset || "iso-8859-1"); | ||
this._currentNode.content = mimelib.decodeBase64(this._currentNode.content, false, this._currentNode.meta.charset || this.options.defaultCharset || "iso-8859-1"); | ||
}else{ | ||
this._currentNode.content = this._encodeString(this._currentNode.content); | ||
} | ||
@@ -977,3 +977,3 @@ }else{ | ||
if(meta.match(/\scharset\s*=\s*['"]?[\w\-]+["'\s>\/]/i)){ | ||
return '<meta charset="utf-8"/>' | ||
return '<meta charset="utf-8"/>'; | ||
} | ||
@@ -985,2 +985,33 @@ return meta; | ||
return html; | ||
}; | ||
/** | ||
* <p>Detects the charset of an HTML file</p> | ||
* | ||
* @param {String} HTML html contents | ||
* @returns {String} Charset for the HTML | ||
*/ | ||
MailParser.prototype._detectHTMLCharset = function(html){ | ||
var charset, input, meta; | ||
if(typeof html !=" string"){ | ||
html = html.toString("ascii"); | ||
} | ||
if((meta = html.match(/<meta\s+http-equiv=["']content-type["'][^>]*?>/i))){ | ||
input = meta[0]; | ||
} | ||
if(input){ | ||
charset = input.match(/charset\s?=\s?([a-zA-Z\-_:0-9]*);?/); | ||
if(charset){ | ||
charset = (charset[1] || "").trim().toLowerCase(); | ||
} | ||
} | ||
if(!charset && (meta = html.match(/<meta\s+charset=["']([^'"<\/]*?)["']/i))){ | ||
charset = (meta[1] || "").trim().toLowerCase(); | ||
} | ||
return charset; | ||
}; |
{ | ||
"name": "mailparser", | ||
"description": "Asynchronous and non-blocking parser for mime encoded e-mail messages", | ||
"version": "0.2.8", | ||
"version": "0.2.9", | ||
"author" : "Andris Reinman", | ||
@@ -27,4 +27,7 @@ "maintainers":[ | ||
}, | ||
"devDependencies": { | ||
"nodeunit": "*" | ||
}, | ||
"engines": ["node >=0.6.0"], | ||
"keywords": ["e-mail", "mime", "parser"] | ||
} |
@@ -181,5 +181,12 @@ | ||
### Running tests | ||
You need to have nodeunit installed for running tests | ||
nodeunit test/run_tests.js | ||
There aren't many tests yet but basics should be covered | ||
## License | ||
**MIT** |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
2460
191
0
524465
1
27