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

front-mailparser

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

front-mailparser - npm Package Compare versions

Comparing version 0.5.3-1 to 0.6.1-1

test/mixed.eml

65

lib/mailparser.js

@@ -272,2 +272,3 @@ "use strict";

textContent = false,
rootNode,
extension;

@@ -304,5 +305,4 @@

(!this._currentNode.meta.contentDisposition ||
(this._currentNode.meta.contentDisposition == "inline" &&
(this._currentNode.meta.transferEncoding != "base64" || this._currentNode.parsedHeaders.precedence === "bulk")
))) {
(this._currentNode.meta.contentDisposition == "inline") ||
(this._currentNode.meta.contentDisposition == "inline" && this._currentNode.parsedHeaders.precedence === "bulk") )) {
this._currentNode.attachment = false;

@@ -320,3 +320,3 @@ } else if ((!textContent || ["attachment", "inline"].indexOf(this._currentNode.meta.contentDisposition) >= 0) &&

this._currentNode.meta.contentId = this._currentNode.meta.contentId ||
crypto.createHash("md5").update(this._currentNode.meta.generatedFileName).digest("hex") + "@mailparser";
crypto.createHash("md5").update(new Buffer(this._currentNode.meta.generatedFileName, 'utf-8')).digest("hex") + "@mailparser";

@@ -343,3 +343,9 @@ extension = this._currentNode.meta.generatedFileName.split(".").pop().toLowerCase();

this.emit("attachment", attachment, this._currentNode.parentNode || this._currentNode);
rootNode = this._currentNode;
while (rootNode.parentNode) {
rootNode = rootNode.parentNode;
}
this.emit("attachment", attachment, rootNode);
} else {

@@ -837,2 +843,8 @@ this._currentNode.content = undefined;

function parseSpacedValueBetweenCarets(value) {
return ((value || "").toString().trim().match(/<[^>]+/g) || []).map(function (match) {
return match.replace(/\s+/g, "").slice(1);
});
}
/**

@@ -844,7 +856,5 @@ * <p>Parses "References" header</p>

MailParser.prototype._parseReferences = function(value) {
this._currentNode.references = (this._currentNode.references || []).concat(
((value || "").toString().trim().match(/<[^>]+/g) || []).map(function (match) {
return match.replace(/\s+/g, "").slice(1);
})
);
var parsed = parseSpacedValueBetweenCarets(value);
this._currentNode.references = (this._currentNode.references || []).concat(parsed);
};

@@ -858,5 +868,5 @@

MailParser.prototype._parseInReplyTo = function(value) {
this._currentNode.inReplyTo = (this._currentNode.inReplyTo || []).concat(
(value || "").toString().trim().split(/\s+/).map(this._trimQuotes.bind(this))
);
var parsed = parseSpacedValueBetweenCarets(value);
this._currentNode.inReplyTo = (this._currentNode.inReplyTo || []).concat(parsed);
};

@@ -887,3 +897,3 @@

case "urgent":
case "hight":
case "high":
return "high";

@@ -1058,12 +1068,25 @@ }

if (this.mailData.text.length) {
for (i = 0, len = this.mailData.text.length; i < len; i++) {
if (!returnValue.text && this.mailData.text[i].content) {
returnValue.text = this.mailData.text[i].content;
} else if (this.mailData.text[i].content) {
returnValue.text += this.mailData.text[i].content;
}
var len = this.mailData.text.length;
// if we have both html and text, process text till the length of html assuming its alternative for html
if (this.mailData.html.length) {
len = Math.min(len, this.mailData.html.length);
}
for (i = 0, len; i < len; i++) {
if (!returnValue.text && this.mailData.text[i].content) {
returnValue.text = this.mailData.text[i].content;
} else if (this.mailData.text[i].content) {
returnValue.text += this.mailData.text[i].content;
}
}
// all remaining text contents if present assumed as additional content and concatenated with html as well as text
for (len = this.mailData.text.length; i < len; i++) {
if (this.mailData.text[i].content) {
// concatenate to both text and html so that text and html are always same content
// user should be able to chose any one of them
returnValue.text += this.mailData.text[i].content;
returnValue.html += this.mailData.text[i].content;
}
}
}
if (this.mailData.calendar.length) {

@@ -1070,0 +1093,0 @@ returnValue.alternatives = [];

@@ -199,3 +199,3 @@ "use strict";

var re = /^begin [0-7]{3} (.*)/;
filename = buffer.slice(0, Math.min(buffer.length, 1024)).toString().match(re)[1] || '';
filename = buffer.slice(0, Math.min(buffer.length, 1024)).toString().match(re) || '';
if (!filename) {

@@ -205,3 +205,3 @@ return new Buffer(0);

buffer = uue.decodeFile(buffer.toString('ascii').replace(/\r\n/g, '\n'), filename);
buffer = uue.decodeFile(buffer.toString('ascii').replace(/\r\n/g, '\n'), filename[1]);

@@ -208,0 +208,0 @@ if (this.charset.toLowerCase() == "binary") {

{
"name": "front-mailparser",
"description": "Asynchronous and non-blocking parser for mime encoded e-mail messages",
"version": "0.5.3-1",
"version": "0.6.1-1",
"author": "Andris Reinman",

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

@@ -68,5 +68,5 @@ MailParser

```javascript
mailparser.on("end", function(mail){
mail; // object structure for parsed e-mail
});
mailparser.on("end", function(mail){
mail; // object structure for parsed e-mail
});
```

@@ -94,4 +94,4 @@ ### Parsed mail object

```javascript
var MailParser = require("mailparser").MailParser,
mailparser = new MailParser();
var MailParser = require("mailparser").MailParser;
var mailparser = new MailParser();

@@ -103,3 +103,4 @@ var email = "From: 'Sender Name' <sender@example.com>\r\n"+

"How are you today?";
// setup an event listener when the parsing finishes
// setup an event listener when the parsing finishes
mailparser.on("end", function(mail_object){

@@ -110,3 +111,4 @@ console.log("From:", mail_object.from); //[{address:'sender@example.com',name:'Sender Name'}]

});
// send the email source to the parser
// send the email source to the parser
mailparser.write(email);

@@ -119,6 +121,7 @@ mailparser.end();

```javascript
var MailParser = require("mailparser").MailParser,
mailparser = new MailParser(),
fs = require("fs");
mailparser.on("end", function(mail_object){
var MailParser = require("mailparser").MailParser;
var mailparser = new MailParser();
var fs = require("fs");
mailparser.on("end", function(mail_object){
console.log("Subject:", mail_object.subject);

@@ -147,13 +150,13 @@ });

```javascript
attachments = [{
contentType: 'image/png',
fileName: 'image.png',
contentDisposition: 'attachment',
contentId: '5.1321281380971@localhost',
transferEncoding: 'base64',
length: 126,
generatedFileName: 'image.png',
checksum: 'e4cef4c6e26037bcf8166905207ea09b',
content: <Buffer ...>
}];
attachments = [{
contentType: 'image/png',
fileName: 'image.png',
contentDisposition: 'attachment',
contentId: '5.1321281380971@localhost',
transferEncoding: 'base64',
length: 126,
generatedFileName: 'image.png',
checksum: 'e4cef4c6e26037bcf8166905207ea09b',
content: <Buffer ...>
}];
```

@@ -185,2 +188,3 @@ The property `generatedFileName` is usually the same as `fileName` but if several

}
mp.on("attachment", function(attachment, mail){

@@ -187,0 +191,0 @@ var output = fs.createWriteStream(attachment.generatedFileName);

@@ -225,2 +225,51 @@ "use strict";

"Single reference with spaces": function (test) {
var encodedText = "Content-type: text/plain\r" +
"References: <mail one>\n" +
"\r" +
"1234",
mail = new Buffer(encodedText, "utf-8");
test.expect(1);
var mailparser = new MailParser();
mailparser.end(mail);
mailparser.on("end", function (mail) {
test.deepEqual(mail.references, ["mailone"]);
test.done();
});
},
"Multiple references with spaces": function (test) {
var encodedText = "Content-type: text/plain\r" +
"References: <mail one> <mail2> <AWS mail3>\n" +
"\r" +
"1234",
mail = new Buffer(encodedText, "utf-8");
test.expect(1);
var mailparser = new MailParser();
mailparser.end(mail);
mailparser.on("end", function (mail) {
test.deepEqual(mail.references, ["mailone", "mail2", "AWSmail3"]);
test.done();
});
},
"Multiple references fields with spaces": function (test) {
var encodedText = "Content-type: text/plain\r" +
"References: <mail one> <mail2> \n" +
"References: <mail duo> <mail4> \n" +
"\r" +
"1234",
mail = new Buffer(encodedText, "utf-8");
test.expect(1);
var mailparser = new MailParser();
mailparser.end(mail);
mailparser.on("end", function (mail) {
test.deepEqual(mail.references, ["mailone", "mail2", "mailduo", "mail4"]);
test.done();
});
},
"Single in-reply-to": function(test) {

@@ -276,2 +325,52 @@ var encodedText = "Content-type: text/plain\r" +

"Single in-reply-to field/value with spaces": function (test) {
var encodedText = "Content-type: text/plain\r" +
"in-reply-to: <mail 1>\n" +
"\r" +
"1234",
mail = new Buffer(encodedText, "utf-8");
test.expect(1);
var mailparser = new MailParser();
mailparser.end(mail);
mailparser.on("end", function(mail) {
test.deepEqual(mail.inReplyTo, ["mail1"]);
test.done();
});
},
"Multiple in-reply-to values with spaces": function (test) {
var encodedText = "Content-type: text/plain\r" +
"in-reply-to: <mail1>\n" +
" <m ail2> <ma il3>\n" +
"\r" +
"1234",
mail = new Buffer(encodedText, "utf-8");
test.expect(1);
var mailparser = new MailParser();
mailparser.end(mail);
mailparser.on("end", function(mail) {
test.deepEqual(mail.inReplyTo, ["mail1", "mail2", "mail3"]);
test.done();
});
},
"Multiple in-reply-to fields with spaces": function(test) {
var encodedText = "Content-type: text/plain\r" +
"in-reply-to: <mail1>\n" +
"in-reply-to: <mail 3>\n" +
"\r" +
"1234",
mail = new Buffer(encodedText, "utf-8");
test.expect(1);
var mailparser = new MailParser();
mailparser.end(mail);
mailparser.on("end", function(mail) {
test.deepEqual(mail.inReplyTo, ["mail1", "mail3"]);
test.done();
});
},
"Reply To address": function(test) {

@@ -451,3 +550,3 @@ var encodedText = "Reply-TO: andris <andris@disposebox.com>\r" +

mailparser.on("end", function(mail) {
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].contentId, "ef694232fea1c01c16fb8a03a0ca710c@mailparser");
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].contentId, "7c7cf35ce5becf62faea56ed8d0ad6e4@mailparser");
test.done();

@@ -1516,2 +1615,20 @@ });

exports["Additional text"] = function(test) {
var mail = fs.readFileSync(__dirname + "/mixed.eml");
test.expect(2);
var mailparser = new MailParser();
for (var i = 0, len = mail.length; i < len; i++) {
mailparser.write(new Buffer([mail[i]]));
}
mailparser.end();
mailparser.on("end", function(mail) {
test.equal(mail.text, "\nThis e-mail message has been scanned for Viruses and Content and cleared\nGood Morning;\n\n");
test.equal(mail.html, "<HTML><HEAD>\n</HEAD><BODY> \n\n<HR>\nThis e-mail message has been scanned for Viruses and Content and cleared\n<HR>\n</BODY></HTML>\nGood Morning;\n\n");
test.done();
});
};
exports["MBOX format"] = {

@@ -1518,0 +1635,0 @@ "Not a mbox": function(test) {

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