New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mailparser

Package Overview
Dependencies
Maintainers
1
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mailparser - npm Package Compare versions

Comparing version 0.2.22 to 0.2.23

55

lib/mailparser.js

@@ -5,3 +5,3 @@

* @author <a href="mailto:andris@node.ee">Andris Reinman</a>
* @version 0.2.22
* @version 0.2.23
*/

@@ -112,13 +112,6 @@

MailParser.prototype.write = function(chunk, encoding){
if(typeof chunk == "string"){
chunk = new Buffer(chunk, encoding);
}
if(chunk && chunk.length){
this._remainder += chunk.toString("binary");
if( this._write(chunk, encoding) ){
process.nextTick(this._process.bind(this));
return true;
}else{
return true;
}
return true;
};

@@ -135,25 +128,41 @@

MailParser.prototype.end = function(chunk, encoding){
this._write(chunk, encoding);
if(this.options.debug && this._remainder){
console.log("REMAINDER: "+this._remainder);
}
process.nextTick(this._process.bind(this, true));
};
/**
* <p>Normalizes CRLF's before writing to the Mailparser stream, does <i>not</i> call `_process`<p>
*
* @param {Buffer|String} chunk The data to be written to the MailParser stream
* @param {String} [encoding] The encoding to be used when "chunk" is a string
* @returns {Boolean} Returns true if writing the chunk was successful
*/
MailParser.prototype._write = function(chunk, encoding){
if(typeof chunk == "string"){
chunk = new Buffer(chunk, encoding);
}
if(this.options.debug && this._remainder){
console.log("REMAINDER: "+this._remainder);
}
chunk = chunk && chunk.toString("binary") || "";
// if the last chunk ended with \r and this one begins
// with \n, it's a split line ending. Since the last \r
// was already used, skip the \n
if(this._lineFeed && chunk.charAt(0) == "\n"){
if(this._lineFeed && chunk.charAt(0) === "\n"){
chunk = chunk.substr(1);
}
this._lineFeed = chunk.substr(-1) == "\r";
this._remainder += chunk;
this._lineFeed = chunk.substr(-1) === "\r";
process.nextTick(this._process.bind(this, true));
if(chunk && chunk.length){
this._remainder += chunk;
return true;
}
return false;
};
/**

@@ -242,3 +251,3 @@ * <p>Processes the data written to the MailParser stream</p>

// Check if the header endas and body starts
// Check if the header ends and body starts
if(!line.length){

@@ -1216,2 +1225,2 @@ if(lastPos>=0){

return charset;
};
};
{
"name": "mailparser",
"description": "Asynchronous and non-blocking parser for mime encoded e-mail messages",
"version": "0.2.22",
"version": "0.2.23",
"author" : "Andris Reinman",

@@ -6,0 +6,0 @@ "maintainers":[

@@ -23,4 +23,2 @@ MailParser

[![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=andris9&url=https://github.com/andris9/mailparser&title=MailParser&language=&tags=github&category=software)
MailParser is not the fastest multipart parser though - it takes about 5 sec. to parse a 25MB e-mail (a letter with one large attachment), so there's some room for improvement.

@@ -30,2 +28,6 @@

## Support mailparser development
[![Donate to author](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DB26KWR2BQX5W)
Live Demo

@@ -58,2 +60,3 @@ ---------

* **defaultCharset** - the default charset for *text/plain* and *text/html* content, if not set reverts to *Latin-1*
* **showAttachmentLinks** - if set to true, show inlined attachment links `<a href="cid:...">filename</a>`

@@ -60,0 +63,0 @@ MailParser object is a writable Stream - you can pipe directly

@@ -27,3 +27,30 @@ var MailParser = require("../lib/mailparser").MailParser,

},
"Many chunks - split line endings": function(test){
var chunks = [
"Content-Type: text/plain; charset=utf-8\r",
"\nSubject: Hi Mom\r\n\r\n",
"hello"
];
test.expect(1);
var mailparser = new MailParser();
var writeNextChunk = function(){
var chunk = chunks.shift();
if( chunk !== undefined ){
mailparser.write(chunk, 'utf8');
process.nextTick(writeNextChunk);
} else {
mailparser.end();
}
};
mailparser.on("end", function(mail){
test.equal(mail.text, "hello");
test.done();
});
process.nextTick(writeNextChunk);
},
"Headers only": function(test){

@@ -30,0 +57,0 @@ var encodedText = "Content-type: text/plain; charset=utf-8\r\n" +

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc