mailparser 0.6.1 → 0.6.2
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/README.md +6 -0
- package/lib/mailparser.js +12 -5
- package/package.json +5 -5
- package/test/mailparser.js +37 -1
package/README.md
CHANGED
|
@@ -9,6 +9,12 @@ MailParser
|
|
|
9
9
|
Handles even large attachments with ease - attachments can be parsed
|
|
10
10
|
in chunks and streamed if needed.
|
|
11
11
|
|
|
12
|
+
### Community version
|
|
13
|
+
|
|
14
|
+
This module is unmaintained. For an upgrade see [Mailparser2](https://gitlab.com/nodemailer/mailparser2). The upgraded version is more effective, has vastly better stream handling through Streams3 interface and is able to build up more accurate versions of HTML and Text contents.
|
|
15
|
+
|
|
16
|
+
### Usage
|
|
17
|
+
|
|
12
18
|
**MailParser** parses raw source of e-mail messages into a structured object.
|
|
13
19
|
|
|
14
20
|
No need to worry about charsets or decoding *quoted-printable* or
|
package/lib/mailparser.js
CHANGED
|
@@ -269,6 +269,7 @@ MailParser.prototype._process = function(finalPart) {
|
|
|
269
269
|
MailParser.prototype._processStateHeader = function(line) {
|
|
270
270
|
var attachment, lastPos = this._currentNode.headers.length - 1,
|
|
271
271
|
textContent = false,
|
|
272
|
+
rootNode,
|
|
272
273
|
extension;
|
|
273
274
|
|
|
274
275
|
// Check if the header ends and body starts
|
|
@@ -309,7 +310,7 @@ MailParser.prototype._processStateHeader = function(line) {
|
|
|
309
310
|
this._currentNode.meta.generatedFileName = this._generateFileName(this._currentNode.meta.fileName, this._currentNode.meta.contentType);
|
|
310
311
|
|
|
311
312
|
this._currentNode.meta.contentId = this._currentNode.meta.contentId ||
|
|
312
|
-
crypto.createHash("md5").update(this._currentNode.meta.generatedFileName).digest("hex") + "@mailparser";
|
|
313
|
+
crypto.createHash("md5").update(new Buffer(this._currentNode.meta.generatedFileName, 'utf-8')).digest("hex") + "@mailparser";
|
|
313
314
|
|
|
314
315
|
extension = this._currentNode.meta.generatedFileName.split(".").pop().toLowerCase();
|
|
315
316
|
|
|
@@ -330,8 +331,14 @@ MailParser.prototype._processStateHeader = function(line) {
|
|
|
330
331
|
this._currentNode.stream = new Streams.BinaryStream();
|
|
331
332
|
}
|
|
332
333
|
attachment.stream = this._currentNode.stream;
|
|
334
|
+
|
|
335
|
+
rootNode = this._currentNode;
|
|
336
|
+
|
|
337
|
+
while (rootNode.parentNode) {
|
|
338
|
+
rootNode = rootNode.parentNode;
|
|
339
|
+
}
|
|
333
340
|
|
|
334
|
-
this.emit("attachment", attachment,
|
|
341
|
+
this.emit("attachment", attachment, rootNode);
|
|
335
342
|
} else {
|
|
336
343
|
this._currentNode.content = undefined;
|
|
337
344
|
}
|
|
@@ -790,10 +797,10 @@ MailParser.prototype._detectFilename = function(value) {
|
|
|
790
797
|
|
|
791
798
|
if (fileName) {
|
|
792
799
|
parts = fileName.split("'");
|
|
793
|
-
encoding = parts.
|
|
800
|
+
encoding = (parts.length > 1) ? parts[0] : "us-ascii";
|
|
794
801
|
name = parts.pop();
|
|
795
802
|
if (name) {
|
|
796
|
-
return this._replaceMimeWords(this._replaceMimeWords("=?" +
|
|
803
|
+
return this._replaceMimeWords(this._replaceMimeWords("=?" + encoding + "?Q?" + name.replace(/%/g, "=") + "?="));
|
|
797
804
|
}
|
|
798
805
|
}
|
|
799
806
|
return "";
|
|
@@ -866,7 +873,7 @@ MailParser.prototype._parsePriority = function(value) {
|
|
|
866
873
|
case "low":
|
|
867
874
|
return "low";
|
|
868
875
|
case "urgent":
|
|
869
|
-
case "
|
|
876
|
+
case "high":
|
|
870
877
|
return "high";
|
|
871
878
|
}
|
|
872
879
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mailparser",
|
|
3
3
|
"description": "Asynchronous and non-blocking parser for mime encoded e-mail messages",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.2",
|
|
5
5
|
"author": "Andris Reinman",
|
|
6
6
|
"maintainers": [{
|
|
7
7
|
"name": "andris",
|
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
"main": "./lib/mailparser",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"mimelib": "^0.
|
|
21
|
-
"encoding": "^0.1.
|
|
20
|
+
"mimelib": "^0.3.0",
|
|
21
|
+
"encoding": "^0.1.12",
|
|
22
22
|
"mime": "^1.3.4",
|
|
23
|
-
"uue": "^3.
|
|
23
|
+
"uue": "^3.1.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"nodeunit": "^0.
|
|
26
|
+
"nodeunit": "^0.10.2"
|
|
27
27
|
},
|
|
28
28
|
"keywords": [
|
|
29
29
|
"e-mail",
|
package/test/mailparser.js
CHANGED
|
@@ -501,6 +501,24 @@ exports["Attachment filename"] = {
|
|
|
501
501
|
test.done();
|
|
502
502
|
});
|
|
503
503
|
},
|
|
504
|
+
"Content-Disposition filename*X": function(test) {
|
|
505
|
+
var encodedText = "Content-Type: application/octet-stream\r\n" +
|
|
506
|
+
"Content-Transfer-Encoding: QUOTED-PRINTABLE\r\n" +
|
|
507
|
+
"Content-Disposition: attachment;\r\n" +
|
|
508
|
+
" filename*0=OA;\r\n" +
|
|
509
|
+
" filename*1=U;\r\n" +
|
|
510
|
+
" filename*2=.txt\r\n" +
|
|
511
|
+
"\r\n" +
|
|
512
|
+
"=00=01=02=03=FD=FE=FF",
|
|
513
|
+
mail = new Buffer(encodedText, "utf-8");
|
|
514
|
+
|
|
515
|
+
var mailparser = new MailParser();
|
|
516
|
+
mailparser.end(mail);
|
|
517
|
+
mailparser.on("end", function(mail) {
|
|
518
|
+
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].content && mail.attachments[0].fileName, "OAU.txt");
|
|
519
|
+
test.done();
|
|
520
|
+
});
|
|
521
|
+
},
|
|
504
522
|
"Content-Disposition filename*X*": function(test) {
|
|
505
523
|
var encodedText = "Content-Type: application/octet-stream\r\n" +
|
|
506
524
|
"Content-Transfer-Encoding: QUOTED-PRINTABLE\r\n" +
|
|
@@ -551,6 +569,23 @@ exports["Attachment filename"] = {
|
|
|
551
569
|
test.done();
|
|
552
570
|
});
|
|
553
571
|
},
|
|
572
|
+
"Content-Type ; name": function(test) {
|
|
573
|
+
var encodedText = "Content-Type: ; name=\"test\"\r\n" +
|
|
574
|
+
"Content-Transfer-Encoding: QUOTED-PRINTABLE\r\n" +
|
|
575
|
+
"\r\n" +
|
|
576
|
+
"=00=01=02=03=FD=FE=FF",
|
|
577
|
+
mail = new Buffer(encodedText, "utf-8");
|
|
578
|
+
|
|
579
|
+
var mailparser = new MailParser();
|
|
580
|
+
|
|
581
|
+
mailparser.write(mail);
|
|
582
|
+
mailparser.end();
|
|
583
|
+
|
|
584
|
+
mailparser.on("end", function(mail) {
|
|
585
|
+
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].fileName, "test");
|
|
586
|
+
test.done();
|
|
587
|
+
});
|
|
588
|
+
},
|
|
554
589
|
"Content-Type name*": function(test) {
|
|
555
590
|
var encodedText = "Content-Type: application/octet-stream;\r\n" +
|
|
556
591
|
" name*=UTF-8''%C3%95%C3%84%C3%96%C3%9C\r\n" +
|
|
@@ -1493,7 +1528,7 @@ exports["Attachment info"] = {
|
|
|
1493
1528
|
};
|
|
1494
1529
|
|
|
1495
1530
|
exports["Advanced nested HTML"] = function(test) {
|
|
1496
|
-
var mail = fs.readFileSync(__dirname + "/
|
|
1531
|
+
var mail = fs.readFileSync(__dirname + "/ali.eml");
|
|
1497
1532
|
|
|
1498
1533
|
test.expect(2);
|
|
1499
1534
|
var mailparser = new MailParser();
|
|
@@ -1504,6 +1539,7 @@ exports["Advanced nested HTML"] = function(test) {
|
|
|
1504
1539
|
|
|
1505
1540
|
mailparser.end();
|
|
1506
1541
|
mailparser.on("end", function(mail) {
|
|
1542
|
+
console.log(require('util').inspect(mail, false, 22));
|
|
1507
1543
|
test.equal(mail.text, "\nDear Sir,\n\nGood evening.\n\n\n \n\n\n\nThe footer\n");
|
|
1508
1544
|
test.equal(mail.html, "<p>Dear Sir</p>\n<p>Good evening.</p>\n<p></p><p>The footer</p>\n");
|
|
1509
1545
|
test.done();
|