mailparser
Advanced tools
@@ -57,3 +57,3 @@ | ||
* @param {String} [encoding] The encoding to be used when "chunk" is a string | ||
* @returns {Boolean} Returns true if nothing is buffered, for later draining returns false | ||
* @returns {Boolean} Returns true | ||
*/ | ||
@@ -67,6 +67,4 @@ MailParser.prototype.write = function(chunk, encoding){ | ||
this.remainder += chunk.toString("binary"); | ||
// to slow things down cache the input and process a bit later, | ||
// emit "drain" when data is processed | ||
process.nextTick(this.process.bind(this)); | ||
return false; | ||
return true; | ||
}else{ | ||
@@ -89,2 +87,7 @@ return true; | ||
} | ||
if(this.options.debug && this.remainder){ | ||
console.log("REMAINDER: "+this.remainder) | ||
} | ||
if(chunk){ | ||
@@ -128,3 +131,5 @@ this.remainder += chunk.toString("binary"); | ||
//console.log("LINE " + (++c) + " ("+this.state+"): "+line); | ||
if(this.options.debug){ | ||
console.log("LINE " + (++c) + " ("+this.state+"): "+line); | ||
} | ||
@@ -146,5 +151,3 @@ if(this.state == STATES.header){ | ||
if(!finalPart){ | ||
process.nextTick(this.emit.bind(this, "drain")); | ||
}else{ | ||
if(finalPart){ | ||
this.state = STATES.finished; | ||
@@ -300,2 +303,3 @@ process.nextTick(this.processMimeTree.bind(this)); | ||
} | ||
// handle text or attachment line | ||
@@ -569,4 +573,5 @@ if(["text/plain", "text/html"].indexOf(this.currentNode.meta.contentType || "")>=0 && | ||
this.currentNode.content = line; | ||
}else{ | ||
this.currentNode.content += "\n"+line; | ||
} | ||
this.currentNode.content += "\n"+line; | ||
}else{ | ||
@@ -573,0 +578,0 @@ if(this.currentNode.meta.textFormat != "flowed"){ |
{ | ||
"name": "mailparser", | ||
"description": "Asynchronous and non-blocking parser for mime encoded e-mail messages", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"author" : "Andris Reinman", | ||
@@ -6,0 +6,0 @@ "maintainers":[ |
@@ -6,12 +6,21 @@ | ||
**NB!** This version of MailParser is incompatible with pre 0.2.0, do not upgrade from 0.1.x without updating your code, the API is totally different. Also if the source is coming directly from SMTP you need to unescape dots in the beginning of the lines yourself! | ||
**NB!** This version of MailParser is incompatible with pre 0.2.0, do | ||
not upgrade from 0.1.x without updating your code, the API is totally | ||
different. Also if the source is coming directly from SMTP you need to | ||
unescape dots in the beginning of the lines yourself! | ||
**MailParser** is an asynchronous and non-blocking parser for [node.js](http://nodejs.org) to parse mime encoded e-mail messages. Handles even large | ||
attachments with ease - attachments can be parsed in chunks and streamed if needed. | ||
**MailParser** is an asynchronous and non-blocking parser for | ||
[node.js](http://nodejs.org) to parse mime encoded e-mail messages. | ||
Handles even large attachments with ease - attachments can be parsed | ||
in chunks and streamed if needed. | ||
**MailParser** parses raw source of e-mail messages into a structured object. | ||
**MailParser** parses raw source of e-mail messages into a structured | ||
object. | ||
No need to worry about charsets or decoding *quoted-printable* or *base64* data, **MailParser** (with the help of *node-iconv*) does all of it for you. All the textual output from **MailParser** (subject line, addressee names, message body) is always UTF-8. | ||
No need to worry about charsets or decoding *quoted-printable* or | ||
*base64* data, **MailParser** (with the help of *node-iconv*) does all | ||
of it for you. All the textual output from **MailParser** (subject line, | ||
addressee names, message body) is always UTF-8. | ||
@@ -34,6 +43,7 @@ Installation | ||
MailParser object is a writable Stream - you can pipe directly files etc. to it | ||
or you can send new chunks with `mailparser.write` | ||
MailParser object is a writable Stream - you can pipe directly | ||
files to it or you can send chunks with `mailparser.write` | ||
When the parsing ends an 'end' event is emitted which has an object with parsed e-mail. | ||
When the parsing ends an 'end' event is emitted which has an | ||
object parameter with parsed e-mail structure. | ||
@@ -47,4 +57,5 @@ mailparser.on("end", function(mail){ | ||
* **headers** - an array of headers, in the form of - `[{key: "key", value: "value"}]` | ||
* **from** - an array of parsed `From` addresses - `[{address:'sender@example.com',name:'Sender Name'}]` | ||
* **from** - an array of parsed `From` addresses - `[{address:'sender@example.com',name:'Sender Name'}]` (should be only one though) | ||
* **to** - an array of parsed `To` addresses | ||
* **cc** - an array of parsed `Cc` addresses | ||
* **subject** - the subject line | ||
@@ -143,3 +154,4 @@ * **text** - text body | ||
This way there will be no `content` property on final attachment objects (but the other fields will remain). | ||
This way there will be no `content` property on final attachment objects | ||
(but the other fields will remain). | ||
@@ -146,0 +158,0 @@ To catch the streams you should listen for `attachment` events on the MailParser |
2772696
02201
0.09%179
7.19%