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.4.8 to 0.4.9

54

lib/datetime.js

@@ -136,3 +136,4 @@ "use strict";

var i, match, s, strTmp = '', parse = '';
var i, match, s, strTmp = '',
parse = '';

@@ -144,7 +145,7 @@ strTmp = str;

if (strTmp == 'now') {
return (new Date()).getTime()/1000; // Return seconds, not milli-seconds
return (new Date()).getTime() / 1000; // Return seconds, not milli-seconds
} else if (!isNaN(parse = Date.parse(strTmp))) {
return (parse/1000);
return (parse / 1000);
} else if (now) {
now = new Date(now*1000); // Accept PHP-style seconds
now = new Date(now * 1000); // Accept PHP-style seconds
} else {

@@ -156,6 +157,4 @@ now = new Date();

var __is =
{
day:
{
var __is = {
day: {
'sun': 0,

@@ -169,4 +168,3 @@ 'mon': 1,

},
mon:
{
mon: {
'jan': 0,

@@ -187,3 +185,3 @@ 'feb': 1,

var process = function (m) {
var process = function(m) {
var ago = (m[2] && m[2] == 'ago');

@@ -219,3 +217,3 @@ var num = (num = m[0] == 'last' ? -1 : 1) * (ago ? -1 : 1);

var day;
if (typeof (day = __is.day[m[1].substring(0, 3)]) != 'undefined') {
if (typeof(day = __is.day[m[1].substring(0, 3)]) != 'undefined') {
var diff = day - now.getDay();

@@ -225,5 +223,9 @@ if (diff === 0) {

} else if (diff > 0) {
if (m[0] == 'last') {diff -= 7;}
if (m[0] == 'last') {
diff -= 7;
}
} else {
if (m[0] == 'next') {diff += 7;}
if (m[0] == 'next') {
diff += 7;
}
}

@@ -287,14 +289,14 @@ now.setDate(now.getDate() + diff);

s[0] = (s[0] >= 0 && s[0] <= 69) ? '20'+(s[0] < 10 ? '0'+s[0] : s[0]+'') : (s[0] >= 70 && s[0] <= 99) ? '19'+s[0] : s[0]+'';
return parseInt(this.strtotime(s[2] + ' ' + s[1] + ' ' + s[0] + ' ' + match[2])+(match[4] ? match[4]/1000 : ''), 10);
s[0] = (s[0] >= 0 && s[0] <= 69) ? '20' + (s[0] < 10 ? '0' + s[0] : s[0] + '') : (s[0] >= 70 && s[0] <= 99) ? '19' + s[0] : s[0] + '';
return parseInt(this.strtotime(s[2] + ' ' + s[1] + ' ' + s[0] + ' ' + match[2]) + (match[4] ? match[4] / 1000 : ''), 10);
}
var regex = '([+-]?\\d+\\s'+
'(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?'+
'|sun\\.?|sunday|mon\\.?|monday|tue\\.?|tuesday|wed\\.?|wednesday'+
'|thu\\.?|thursday|fri\\.?|friday|sat\\.?|saturday)'+
'|(last|next)\\s'+
'(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?'+
'|sun\\.?|sunday|mon\\.?|monday|tue\\.?|tuesday|wed\\.?|wednesday'+
'|thu\\.?|thursday|fri\\.?|friday|sat\\.?|saturday))'+
var regex = '([+-]?\\d+\\s' +
'(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?' +
'|sun\\.?|sunday|mon\\.?|monday|tue\\.?|tuesday|wed\\.?|wednesday' +
'|thu\\.?|thursday|fri\\.?|friday|sat\\.?|saturday)' +
'|(last|next)\\s' +
'(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?' +
'|sun\\.?|sunday|mon\\.?|monday|tue\\.?|tuesday|wed\\.?|wednesday' +
'|thu\\.?|thursday|fri\\.?|friday|sat\\.?|saturday))' +
'(\\sago)?';

@@ -313,3 +315,3 @@

return (now.getTime()/1000);
};
return (now.getTime() / 1000);
};

@@ -46,71 +46,71 @@ "use strict";

// Make MailParser a Stream object
Stream.call(this);
this.writable = true;
// Make MailParser a Stream object
Stream.call(this);
this.writable = true;
/**
* Options object
* @public */
this.options = options || {};
/**
* Options object
* @public */
this.options = options || {};
/**
* Indicates current state the parser is in
* @private */
this._state = STATES.header;
/**
* Indicates current state the parser is in
* @private */
this._state = STATES.header;
/**
* The remaining data from the previos chunk which is waiting to be processed
* @private */
this._remainder = "";
/**
* The remaining data from the previos chunk which is waiting to be processed
* @private */
this._remainder = "";
/**
* The complete tree structure of the e-mail
* @public */
this.mimeTree = this._createMimeNode();
/**
* The complete tree structure of the e-mail
* @public */
this.mimeTree = this._createMimeNode();
/**
* Current node of the multipart mime tree that is being processed
* @private */
this._currentNode = this.mimeTree;
/**
* Current node of the multipart mime tree that is being processed
* @private */
this._currentNode = this.mimeTree;
// default values for the root node
this._currentNode.priority = "normal";
// default values for the root node
this._currentNode.priority = "normal";
/**
* An object of already used attachment filenames
* @private */
this._fileNames = {};
/**
* An object of already used attachment filenames
* @private */
this._fileNames = {};
/**
* An array of multipart nodes
* @private */
this._multipartTree = [];
/**
* An array of multipart nodes
* @private */
this._multipartTree = [];
/**
* This is the final mail structure object that is returned to the client
* @public */
this.mailData = {};
/**
* This is the final mail structure object that is returned to the client
* @public */
this.mailData = {};
/**
* Line counter for debugging
* @private */
this._lineCounter = 0;
/**
* Line counter for debugging
* @private */
this._lineCounter = 0;
/**
* Did the last chunk end with \r
* @private */
this._lineFeed = false;
/**
* Did the last chunk end with \r
* @private */
this._lineFeed = false;
/**
* Is the "headers" event already emitted
* @private */
this._headersSent = false;
/**
* Is the "headers" event already emitted
* @private */
this._headersSent = false;
/**
* If the e-mail is in mbox format, unescape ">From " to "From " in body
* @private */
this._isMbox = -1;
}
// inherit methods and properties of Stream
/**
* If the e-mail is in mbox format, unescape ">From " to "From " in body
* @private */
this._isMbox = -1;
}
// inherit methods and properties of Stream
utillib.inherits(MailParser, Stream);

@@ -335,3 +335,3 @@

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

@@ -460,7 +460,8 @@ this._currentNode.content = undefined;

case "date":
this._currentNode.meta.date = new Date(value);
if (Object.prototype.toString.call(this._currentNode.meta.date) != "[object Date]" || this._currentNode.meta.date.toString() == "Invalid Date") {
this._currentNode.meta.date = datetime.strtotime(value) && new Date(datetime.strtotime(value) * 1000);
}
this._currentNode.meta.date = this._parseDateString(value);
break;
case "received":
case "x-received":
this._parseReceived(value);
break;
case "to":

@@ -594,3 +595,3 @@ if (this._currentNode.to && this._currentNode.to.length) {

parts = value.match(/(?:[^;"]+|"[^"]*")+/g) || [value];
parts = value.match(/(?:[^;"]+|"[^"]*")+/g) ||  [value];
returnValue.defaultValue = parts.shift().toLowerCase();

@@ -612,2 +613,69 @@

/**
* <p>Parses date string</o>
*
* <p>Receives possible date string in different formats and
* transforms it into a JS Date object</p>
*
* @param {String} value possible date string
* @returns {Date|Boolean} date object
*/
MailParser.prototype._parseDateString = function(value) {
var date;
date = new Date(value);
if (Object.prototype.toString.call(date) != "[object Date]" || date.toString() == "Invalid Date") {
date = datetime.strtotime(value);
if (date) {
date = new Date(date * 1000);
}
}
return date;
};
/**
* <p>Parses Received and X-Received header field value</p>
*
* <p>Pulls received date from the received and x-received header fields and
* update current node meta object with this date as long as it's later as the
* existing date of the meta object</p>
*
* <p>Example: <code>by 10.25.25.72 with SMTP id 69csp2404548lfz; Fri, 6 Feb 2015 15:15:32 -0800 (PST)</code>
* will become:
* </p>
*
* <pre>new Date('2015-02-06T23:15:32.000Z')</pre>
*
* @param {String} value Received string
* @returns {Date|Boolean} parsed received date
*/
MailParser.prototype._parseReceived = function(value) {
var receivedDate, date, splitString;
if (!value) {
return false;
}
splitString = value.split(';');
value = splitString[splitString.length - 1];
date = this._parseDateString(value);
receivedDate = this._currentNode.meta.receivedDate;
if (!date) {
if (!receivedDate) {
this._currentNode.meta.receivedDate = date;
}
return date;
}
if (!receivedDate) {
this._currentNode.meta.receivedDate = date;
} else if (date > receivedDate) {
this._currentNode.meta.receivedDate = date;
}
return date;
};
/**
* <p>Parses a Content-Type header field value</p>

@@ -1031,2 +1099,6 @@ *

if (this.mimeTree.meta.receivedDate) {
returnValue.receivedDate = this.mimeTree.meta.receivedDate;
}
if (this.mailData.attachments.length) {

@@ -1352,3 +1424,3 @@ returnValue.attachments = [];

if (fileRootName in this._fileNames) {
this._fileNames[fileRootName]++;
this._fileNames[fileRootName] ++;
ext = fileName.substr((fileName.lastIndexOf(".") || 0) + 1);

@@ -1420,2 +1492,2 @@ if (ext == fileName) {

return charset;
};
};

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

function Base64Stream(){
function Base64Stream() {
Stream.call(this);

@@ -27,3 +27,3 @@ this.writable = true;

Base64Stream.prototype.write = function(data){
Base64Stream.prototype.write = function(data) {
this.handleInput(data);

@@ -33,3 +33,3 @@ return true;

Base64Stream.prototype.end = function(data){
Base64Stream.prototype.end = function(data) {
this.handleInput(data);

@@ -43,4 +43,4 @@ this.emit("end");

Base64Stream.prototype.handleInput = function(data){
if(!data || !data.length){
Base64Stream.prototype.handleInput = function(data) {
if (!data || !data.length) {
return;

@@ -52,5 +52,5 @@ }

var remainder = 0;
this.current += data.replace(/[^\w\+\/=]/g,'');
var buffer = new Buffer(this.current.substr(0, this.current.length - this.current.length % 4),"base64");
if(buffer.length){
this.current += data.replace(/[^\w\+\/=]/g, '');
var buffer = new Buffer(this.current.substr(0, this.current.length - this.current.length % 4), "base64");
if (buffer.length) {
this.length += buffer.length;

@@ -60,6 +60,6 @@ this.checksum.update(buffer);

}
this.current = (remainder=this.current.length % 4)?this.current.substr(- remainder):"";
this.current = (remainder = this.current.length % 4) ? this.current.substr(-remainder) : "";
};
function QPStream(charset){
function QPStream(charset) {
Stream.call(this);

@@ -76,3 +76,3 @@ this.writable = true;

QPStream.prototype.write = function(data){
QPStream.prototype.write = function(data) {
this.handleInput(data);

@@ -82,3 +82,3 @@ return true;

QPStream.prototype.end = function(data){
QPStream.prototype.end = function(data) {
this.handleInput(data);

@@ -93,4 +93,4 @@ this.flush();

QPStream.prototype.handleInput = function(data){
if(!data || !data.length){
QPStream.prototype.handleInput = function(data) {
if (!data || !data.length) {
return;

@@ -100,9 +100,9 @@ }

data = (data || "").toString("utf-8");
if(data.match(/^\r\n/)){
if (data.match(/^\r\n/)) {
data = data.substr(2);
}
if(typeof this.current !="string"){
if (typeof this.current != "string") {
this.current = data;
}else{
} else {
this.current += "\r\n" + data;

@@ -112,10 +112,10 @@ }

QPStream.prototype.flush = function(){
QPStream.prototype.flush = function() {
var buffer = mimelib.decodeQuotedPrintable(this.current, false, this.charset);
if(this.charset.toLowerCase() == "binary"){
if (this.charset.toLowerCase() == "binary") {
// do nothing
}else if(this.charset.toLowerCase() != "utf-8"){
} else if (this.charset.toLowerCase() != "utf-8") {
buffer = encodinglib.convert(buffer, "utf-8", this.charset);
}else{
} else {
buffer = new Buffer(buffer, "utf-8");

@@ -130,3 +130,3 @@ }

function BinaryStream(charset){
function BinaryStream(charset) {
Stream.call(this);

@@ -143,4 +143,4 @@ this.writable = true;

BinaryStream.prototype.write = function(data){
if(data && data.length){
BinaryStream.prototype.write = function(data) {
if (data && data.length) {
this.length += data.length;

@@ -153,4 +153,4 @@ this.checksum.update(data);

BinaryStream.prototype.end = function(data){
if(data && data.length){
BinaryStream.prototype.end = function(data) {
if (data && data.length) {
this.emit("data", data);

@@ -166,3 +166,3 @@ }

// this is not a stream, it buffers data and decodes after end
function UUEStream(charset){
function UUEStream(charset) {
Stream.call(this);

@@ -181,3 +181,3 @@ this.writable = true;

UUEStream.prototype.write = function(data){
UUEStream.prototype.write = function(data) {
this.buf.push(data);

@@ -188,4 +188,4 @@ this.buflen += data.length;

UUEStream.prototype.end = function(data){
if(data){
UUEStream.prototype.end = function(data) {
if (data) {
this.write(data);

@@ -203,3 +203,3 @@ }

UUEStream.prototype.flush = function(){
UUEStream.prototype.flush = function() {
var buffer = this.decode(Buffer.concat(this.buf, this.buflen));

@@ -213,7 +213,7 @@

UUEStream.prototype.decode = function(buffer){
UUEStream.prototype.decode = function(buffer) {
var filename;
filename = buffer.slice(0, Math.min(buffer.length, 1024)).toString().split(/\s/)[2] || '';
if(!filename){
filename = buffer.slice(0, Math.min(buffer.length, 1024)).toString().split(/\s/)[2] || '';
if (!filename) {
return new Buffer(0);

@@ -224,5 +224,5 @@ }

if(this.charset.toLowerCase() == "binary"){
if (this.charset.toLowerCase() == "binary") {
// do nothing
}else if(this.charset.toLowerCase() != "utf-8"){
} else if (this.charset.toLowerCase() != "utf-8") {
buffer = encodinglib.convert(buffer, "utf-8", this.charset);

@@ -229,0 +229,0 @@ }

{
"name": "mailparser",
"description": "Asynchronous and non-blocking parser for mime encoded e-mail messages",
"version": "0.4.8",
"version": "0.4.9",
"author": "Andris Reinman",
"maintainers": [
{
"name": "andris",
"email": "andris@node.ee"
}
],
"maintainers": [{
"name": "andris",
"email": "andris@node.ee"
}],
"repository": {

@@ -20,8 +18,6 @@ "type": "git",

"main": "./lib/mailparser",
"licenses": [
{
"type": "MIT",
"url": "http://github.com/andris9/mailparser/blob/master/LICENSE"
}
],
"licenses": [{
"type": "MIT",
"url": "http://github.com/andris9/mailparser/blob/master/LICENSE"
}],
"dependencies": {

@@ -44,2 +40,2 @@ "mimelib": ">=0.2.17",

]
}
}

@@ -0,4 +1,4 @@

"use strict";
var MailParser = require("../lib/mailparser").MailParser,
testCase = require('nodeunit').testCase,
utillib = require("util"),
encodinglib = require("encoding"),

@@ -8,7 +8,7 @@ fs = require("fs");

exports["General tests"] = {
"Many chunks": function(test){
"Many chunks": function(test) {
var encodedText = "Content-Type: text/plain; charset=utf-8\r\n" +
"\r\n" +
"ÕÄ\r\n" +
"ÖÜ", // \r\nÕÄÖÜ
"\r\n" +
"ÕÄ\r\n" +
"ÖÜ", // \r\nÕÄÖÜ
mail = new Buffer(encodedText, "utf-8");

@@ -19,3 +19,3 @@

for(var i=0, len = mail.length; i<len; i++){
for (var i = 0, len = mail.length; i < len; i++) {
mailparser.write(new Buffer([mail[i]]));

@@ -25,3 +25,3 @@ }

mailparser.end();
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "ÕÄ\nÖÜ");

@@ -32,3 +32,3 @@ test.done();

"Many chunks - split line endings": function(test){
"Many chunks - split line endings": function(test) {
var chunks = [

@@ -43,9 +43,9 @@ "Content-Type: text/plain; charset=utf-8\r",

var writeNextChunk = function(){
var writeNextChunk = function() {
var chunk = chunks.shift();
if( chunk !== undefined ){
if (chunk !== undefined) {
mailparser.write(chunk, 'utf8');
if(typeof setImmediate == "function"){
if (typeof setImmediate == "function") {
setImmediate(writeNextChunk);
}else{
} else {
process.nextTick(writeNextChunk);

@@ -58,3 +58,3 @@ }

mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "hello");

@@ -64,5 +64,5 @@ test.done();

if(typeof setImmediate == "function"){
if (typeof setImmediate == "function") {
setImmediate(writeNextChunk);
}else{
} else {
process.nextTick(writeNextChunk);

@@ -72,5 +72,5 @@ }

"Headers only": function(test){
"Headers only": function(test) {
var encodedText = "Content-type: text/plain; charset=utf-8\r\n" +
"Subject: ÕÄÖÜ",
"Subject: ÕÄÖÜ",
mail = new Buffer(encodedText, "utf-8");

@@ -81,3 +81,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.subject, "ÕÄÖÜ");

@@ -88,5 +88,5 @@ test.done();

"Body only": function(test){
"Body only": function(test) {
var encodedText = "\r\n" +
"===",
"===",
mail = new Buffer(encodedText, "utf-8");

@@ -97,3 +97,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "===");

@@ -104,10 +104,10 @@ test.done();

"Different line endings": function(test){
"Different line endings": function(test) {
var encodedText = "Content-type: text/plain; charset=utf-8\r" +
"Subject: ÕÄÖÜ\n" +
"\r" +
"1234\r\n" +
"ÕÄÖÜ\r\n" +
"ÜÖÄÕ\n" +
"1234",
"Subject: ÕÄÖÜ\n" +
"\r" +
"1234\r\n" +
"ÕÄÖÜ\r\n" +
"ÜÖÄÕ\n" +
"1234",
mail = new Buffer(encodedText, "utf-8");

@@ -118,3 +118,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.subject, "ÕÄÖÜ");

@@ -126,14 +126,14 @@ test.equal(mail.text, "1234\nÕÄÖÜ\nÜÖÄÕ\n1234");

"Headers event": function(test){
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n"+
"X-Test: =?UTF-8?Q?=C3=95=C3=84?= =?UTF-8?Q?=C3=96=C3=9C?=\r\n"+
"Subject: ABCDEF\r\n"+
"\r\n"+
"--ABC\r\n"+
"Content-Type: application/octet-stream\r\n"+
"Content-Transfer-Encoding: base64\r\n"+
"Content-Disposition: attachment; filename=\"test.pdf\"\r\n"+
"\r\n"+
"AAECAwQFBg==\r\n"+
"--ABC--",
"Headers event": function(test) {
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n" +
"X-Test: =?UTF-8?Q?=C3=95=C3=84?= =?UTF-8?Q?=C3=96=C3=9C?=\r\n" +
"Subject: ABCDEF\r\n" +
"\r\n" +
"--ABC\r\n" +
"Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: base64\r\n" +
"Content-Disposition: attachment; filename=\"test.pdf\"\r\n" +
"\r\n" +
"AAECAwQFBg==\r\n" +
"--ABC--",
mail = new Buffer(encodedText, "utf-8");

@@ -144,3 +144,3 @@

mailparser.on("headers", function(headers){
mailparser.on("headers", function(headers) {
test.equal(headers.subject, "ABCDEF");

@@ -151,3 +151,3 @@ test.equal(headers['x-test'], "ÕÄÖÜ");

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function() {
test.ok(1, "Parsing ended");

@@ -158,7 +158,7 @@ test.done();

"No priority": function(test){
"No priority": function(test) {
var encodedText = "Content-type: text/plain; charset=utf-8\r" +
"Subject: ÕÄÖÜ\n" +
"\r" +
"1234",
"Subject: ÕÄÖÜ\n" +
"\r" +
"1234",
mail = new Buffer(encodedText, "utf-8");

@@ -169,3 +169,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.priority, "normal");

@@ -176,8 +176,8 @@ test.done();

"MS Style priority": function(test){
"MS Style priority": function(test) {
var encodedText = "Content-type: text/plain; charset=utf-8\r" +
"Subject: ÕÄÖÜ\n" +
"X-Priority: 1 (Highest)\n" +
"\r" +
"1234",
"Subject: ÕÄÖÜ\n" +
"X-Priority: 1 (Highest)\n" +
"\r" +
"1234",
mail = new Buffer(encodedText, "utf-8");

@@ -188,3 +188,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.priority, "high");

@@ -195,7 +195,7 @@ test.done();

"Single reference": function(test){
"Single reference": function(test) {
var encodedText = "Content-type: text/plain\r" +
"References: <mail1>\n" +
"\r" +
"1234",
"References: <mail1>\n" +
"\r" +
"1234",
mail = new Buffer(encodedText, "utf-8");

@@ -206,3 +206,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.deepEqual(mail.references, ["mail1"]);

@@ -213,8 +213,8 @@ test.done();

"Multiple reference values": function(test){
"Multiple reference values": function(test) {
var encodedText = "Content-type: text/plain\r" +
"References: <mail1>\n" +
" <mail2> <mail3>\n" +
"\r" +
"1234",
"References: <mail1>\n" +
" <mail2> <mail3>\n" +
"\r" +
"1234",
mail = new Buffer(encodedText, "utf-8");

@@ -225,3 +225,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.deepEqual(mail.references, ["mail1", "mail2", "mail3"]);

@@ -232,8 +232,8 @@ test.done();

"Multiple reference fields": function(test){
"Multiple reference fields": function(test) {
var encodedText = "Content-type: text/plain\r" +
"References: <mail1>\n" +
"References: <mail3>\n" +
"\r" +
"1234",
"References: <mail1>\n" +
"References: <mail3>\n" +
"\r" +
"1234",
mail = new Buffer(encodedText, "utf-8");

@@ -244,3 +244,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.deepEqual(mail.references, ["mail1", "mail3"]);

@@ -251,7 +251,7 @@ test.done();

"Single in-reply-to": function(test){
"Single in-reply-to": function(test) {
var encodedText = "Content-type: text/plain\r" +
"in-reply-to: <mail1>\n" +
"\r" +
"1234",
"in-reply-to: <mail1>\n" +
"\r" +
"1234",
mail = new Buffer(encodedText, "utf-8");

@@ -262,3 +262,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.deepEqual(mail.inReplyTo, ["mail1"]);

@@ -269,8 +269,8 @@ test.done();

"Multiple in-reply-to values": function(test){
"Multiple in-reply-to values": function(test) {
var encodedText = "Content-type: text/plain\r" +
"in-reply-to: <mail1>\n" +
" <mail2> <mail3>\n" +
"\r" +
"1234",
"in-reply-to: <mail1>\n" +
" <mail2> <mail3>\n" +
"\r" +
"1234",
mail = new Buffer(encodedText, "utf-8");

@@ -281,3 +281,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.deepEqual(mail.inReplyTo, ["mail1", "mail2", "mail3"]);

@@ -288,8 +288,8 @@ test.done();

"Multiple in-reply-to fields": function(test){
"Multiple in-reply-to fields": function(test) {
var encodedText = "Content-type: text/plain\r" +
"in-reply-to: <mail1>\n" +
"in-reply-to: <mail3>\n" +
"\r" +
"1234",
"in-reply-to: <mail1>\n" +
"in-reply-to: <mail3>\n" +
"\r" +
"1234",
mail = new Buffer(encodedText, "utf-8");

@@ -300,3 +300,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.deepEqual(mail.inReplyTo, ["mail1", "mail3"]);

@@ -307,7 +307,7 @@ test.done();

"Reply To address": function(test){
"Reply To address": function(test) {
var encodedText = "Reply-TO: andris <andris@disposebox.com>\r" +
"Subject: ÕÄÖÜ\n" +
"\r" +
"1234",
"Subject: ÕÄÖÜ\n" +
"\r" +
"1234",
mail = new Buffer(encodedText, "utf-8");

@@ -318,4 +318,7 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
test.deepEqual(mail.replyTo, [{name:"andris", address:"andris@disposebox.com"}]);
mailparser.on("end", function(mail) {
test.deepEqual(mail.replyTo, [{
name: "andris",
address: "andris@disposebox.com"
}]);
test.done();

@@ -329,4 +332,4 @@ });

"Plaintext encoding: Default": function(test){
var encodedText = [13,10, 213, 196, 214, 220], // \r\nÕÄÖÜ
"Plaintext encoding: Default": function(test) {
var encodedText = [13, 10, 213, 196, 214, 220], // \r\nÕÄÖÜ
mail = new Buffer(encodedText);

@@ -338,3 +341,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "ÕÄÖÜ");

@@ -345,6 +348,6 @@ test.done();

"Plaintext encoding: Header defined": function(test){
"Plaintext encoding: Header defined": function(test) {
var encodedText = "Content-Type: TEXT/PLAIN; CHARSET=UTF-8\r\n" +
"\r\n" +
"ÕÄÖÜ",
"\r\n" +
"ÕÄÖÜ",
mail = new Buffer(encodedText, "utf-8");

@@ -355,3 +358,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "ÕÄÖÜ");

@@ -362,6 +365,6 @@ test.done();

"HTML encoding: From <meta>": function(test){
"HTML encoding: From <meta>": function(test) {
var encodedText = "Content-Type: text/html\r\n" +
"\r\n" +
"<html><head><meta charset=\"utf-8\"/></head><body>ÕÄÖÜ",
"\r\n" +
"<html><head><meta charset=\"utf-8\"/></head><body>ÕÄÖÜ",
mail = new Buffer(encodedText, "utf-8");

@@ -373,3 +376,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal((mail.html || "").substr(-4), "ÕÄÖÜ");

@@ -380,6 +383,6 @@ test.done();

"HTML encoding: Conflicting headers": function(test){
"HTML encoding: Conflicting headers": function(test) {
var encodedText = "Content-Type: text/html; charset=iso-8859-1\r\n" +
"\r\n" +
"<html><head><meta charset=\"utf-8\"/></head><body>ÕÄÖÜ",
"\r\n" +
"<html><head><meta charset=\"utf-8\"/></head><body>ÕÄÖÜ",
mail = new Buffer(encodedText, "utf-8");

@@ -391,3 +394,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal((mail.html || "").substr(-4), "ÕÄÖÜ");

@@ -397,6 +400,6 @@ test.done();

},
"HTML encoding: Header defined": function(test){
var encodedText = "Content-Type: text/html; charset=iso-UTF-8\r\n"+
"\r\n"+
"ÕÄÖÜ",
"HTML encoding: Header defined": function(test) {
var encodedText = "Content-Type: text/html; charset=iso-UTF-8\r\n" +
"\r\n" +
"ÕÄÖÜ",
mail = new Buffer(encodedText, "utf-8");

@@ -407,3 +410,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.html, "ÕÄÖÜ");

@@ -413,7 +416,7 @@ test.done();

},
"Mime Words": function(test){
"Mime Words": function(test) {
var encodedText = "Content-type: text/plain; charset=utf-8\r\n" +
"From: =?utf-8?q??= <sender@email.com>\r\n" +
"To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <to@email.com>\r\n" +
"Subject: =?iso-8859-1?Q?Avaldu?= =?iso-8859-1?Q?s_lepingu_?=\r\n =?iso-8859-1?Q?l=F5petamise?= =?iso-8859-1?Q?ks?=\r\n",
"From: =?utf-8?q??= <sender@email.com>\r\n" +
"To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <to@email.com>\r\n" +
"Subject: =?iso-8859-1?Q?Avaldu?= =?iso-8859-1?Q?s_lepingu_?=\r\n =?iso-8859-1?Q?l=F5petamise?= =?iso-8859-1?Q?ks?=\r\n",
mail = new Buffer(encodedText, "utf-8");

@@ -423,3 +426,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.subject, "Avaldus lepingu lõpetamiseks");

@@ -434,7 +437,7 @@ test.equal(mail.from[0].name, "");

exports["Binary attachment encodings"] = {
"Quoted-Printable": function(test){
var encodedText = "Content-Type: application/octet-stream\r\n"+
"Content-Transfer-Encoding: QUOTED-PRINTABLE\r\n"+
"\r\n"+
"=00=01=02=03=FD=FE=FF",
"Quoted-Printable": function(test) {
var encodedText = "Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: QUOTED-PRINTABLE\r\n" +
"\r\n" +
"=00=01=02=03=FD=FE=FF",
mail = new Buffer(encodedText, "utf-8");

@@ -444,3 +447,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(Array.prototype.slice.apply(mail.attachments && mail.attachments[0] && mail.attachments[0].content && mail.attachments[0].content || []).join(","), "0,1,2,3,253,254,255");

@@ -450,7 +453,7 @@ test.done();

},
"Base64": function(test){
var encodedText = "Content-Type: application/octet-stream\r\n"+
"Content-Transfer-Encoding: base64\r\n"+
"\r\n"+
"AAECA/3+/w==",
"Base64": function(test) {
var encodedText = "Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: base64\r\n" +
"\r\n" +
"AAECA/3+/w==",
mail = new Buffer(encodedText, "utf-8");

@@ -460,3 +463,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(Array.prototype.slice.apply(mail.attachments && mail.attachments[0] && mail.attachments[0].content && mail.attachments[0].content || []).join(","), "0,1,2,3,253,254,255");

@@ -466,6 +469,6 @@ test.done();

},
"8bit": function(test){
var encodedText = "Content-Type: application/octet-stream\r\n"+
"\r\n"+
"ÕÄÖÜ",
"8bit": function(test) {
var encodedText = "Content-Type: application/octet-stream\r\n" +
"\r\n" +
"ÕÄÖÜ",
mail = new Buffer(encodedText, "utf-8");

@@ -475,3 +478,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(Array.prototype.slice.apply(mail.attachments && mail.attachments[0] && mail.attachments[0].content && mail.attachments[0].content || []).join(","), "195,149,195,132,195,150,195,156");

@@ -481,10 +484,10 @@ test.done();

},
"UUENCODE": function(test){
var encodedText = "Content-Type: application/octet-stream\r\n"+
"Content-Transfer-Encoding: uuencode\r\n"+
"\r\n"+
"begin 644 buffer.bin\r\n"+
"#0V%T\r\n"+
"`\r\n"+
"end",
"UUENCODE": function(test) {
var encodedText = "Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: uuencode\r\n" +
"\r\n" +
"begin 644 buffer.bin\r\n" +
"#0V%T\r\n" +
"`\r\n" +
"end",
mail = new Buffer(encodedText, "utf-8");

@@ -494,3 +497,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.attachments[0].content.toString(), "Cat");

@@ -504,8 +507,8 @@ test.done();

exports["Attachment Content-Id"] = {
"Default": function(test){
var encodedText = "Content-Type: application/octet-stream\r\n"+
"Content-Transfer-Encoding: QUOTED-PRINTABLE\r\n"+
"Content-Disposition: attachment; filename=\"=?UTF-8?Q?=C3=95=C3=84=C3=96=C3=9C?=\"\r\n"+
"\r\n"+
"=00=01=02=03=FD=FE=FF",
"Default": function(test) {
var encodedText = "Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: QUOTED-PRINTABLE\r\n" +
"Content-Disposition: attachment; filename=\"=?UTF-8?Q?=C3=95=C3=84=C3=96=C3=9C?=\"\r\n" +
"\r\n" +
"=00=01=02=03=FD=FE=FF",
mail = new Buffer(encodedText, "utf-8");

@@ -515,3 +518,3 @@

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

@@ -522,9 +525,9 @@ test.done();

"Defined": function(test){
var encodedText = "Content-Type: application/octet-stream\r\n"+
"Content-Transfer-Encoding: QUOTED-PRINTABLE\r\n"+
"Content-Disposition: attachment; filename=\"=?UTF-8?Q?=C3=95=C3=84=C3=96=C3=9C?=\"\r\n"+
"Content-Id: test@localhost\r\n"+
"\r\n"+
"=00=01=02=03=FD=FE=FF",
"Defined": function(test) {
var encodedText = "Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: QUOTED-PRINTABLE\r\n" +
"Content-Disposition: attachment; filename=\"=?UTF-8?Q?=C3=95=C3=84=C3=96=C3=9C?=\"\r\n" +
"Content-Id: test@localhost\r\n" +
"\r\n" +
"=00=01=02=03=FD=FE=FF",
mail = new Buffer(encodedText, "utf-8");

@@ -534,3 +537,3 @@

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

@@ -544,8 +547,8 @@ test.done();

"Content-Disposition filename": function(test){
var encodedText = "Content-Type: application/octet-stream\r\n"+
"Content-Transfer-Encoding: QUOTED-PRINTABLE\r\n"+
"Content-Disposition: attachment; filename=\"=?UTF-8?Q?=C3=95=C3=84=C3=96=C3=9C?=\"\r\n"+
"\r\n"+
"=00=01=02=03=FD=FE=FF",
"Content-Disposition filename": function(test) {
var encodedText = "Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: QUOTED-PRINTABLE\r\n" +
"Content-Disposition: attachment; filename=\"=?UTF-8?Q?=C3=95=C3=84=C3=96=C3=9C?=\"\r\n" +
"\r\n" +
"=00=01=02=03=FD=FE=FF",
mail = new Buffer(encodedText, "utf-8");

@@ -555,3 +558,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].content && mail.attachments[0].fileName, "ÕÄÖÜ");

@@ -561,8 +564,8 @@ test.done();

},
"Content-Disposition filename*": function(test){
var encodedText = "Content-Type: application/octet-stream\r\n"+
"Content-Transfer-Encoding: QUOTED-PRINTABLE\r\n"+
"Content-Disposition: attachment; filename*=\"UTF-8''%C3%95%C3%84%C3%96%C3%9C\"\r\n"+
"\r\n"+
"=00=01=02=03=FD=FE=FF",
"Content-Disposition filename*": function(test) {
var encodedText = "Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: QUOTED-PRINTABLE\r\n" +
"Content-Disposition: attachment; filename*=\"UTF-8''%C3%95%C3%84%C3%96%C3%9C\"\r\n" +
"\r\n" +
"=00=01=02=03=FD=FE=FF",
mail = new Buffer(encodedText, "utf-8");

@@ -572,3 +575,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].content && mail.attachments[0].fileName, "ÕÄÖÜ");

@@ -578,10 +581,10 @@ test.done();

},
"Content-Disposition filename*X*": function(test){
var encodedText = "Content-Type: application/octet-stream\r\n"+
"Content-Transfer-Encoding: QUOTED-PRINTABLE\r\n"+
"Content-Disposition: attachment;\r\n"+
" filename*0*=UTF-8''%C3%95%C3%84;\r\n"+
" filename*1*=%C3%96%C3%9C\r\n"+
"\r\n"+
"=00=01=02=03=FD=FE=FF",
"Content-Disposition filename*X*": function(test) {
var encodedText = "Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: QUOTED-PRINTABLE\r\n" +
"Content-Disposition: attachment;\r\n" +
" filename*0*=UTF-8''%C3%95%C3%84;\r\n" +
" filename*1*=%C3%96%C3%9C\r\n" +
"\r\n" +
"=00=01=02=03=FD=FE=FF",
mail = new Buffer(encodedText, "utf-8");

@@ -591,3 +594,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].content && mail.attachments[0].fileName, "ÕÄÖÜ");

@@ -598,7 +601,7 @@ test.done();

"Content-Type name": function(test){
var encodedText = "Content-Type: application/octet-stream; name=\"=?UTF-8?Q?=C3=95=C3=84=C3=96=C3=9C?=\"\r\n"+
"Content-Transfer-Encoding: QUOTED-PRINTABLE\r\n"+
"\r\n"+
"=00=01=02=03=FD=FE=FF",
"Content-Type name": function(test) {
var encodedText = "Content-Type: application/octet-stream; name=\"=?UTF-8?Q?=C3=95=C3=84=C3=96=C3=9C?=\"\r\n" +
"Content-Transfer-Encoding: QUOTED-PRINTABLE\r\n" +
"\r\n" +
"=00=01=02=03=FD=FE=FF",
mail = new Buffer(encodedText, "utf-8");

@@ -608,3 +611,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].content && mail.attachments[0].fileName, "ÕÄÖÜ");

@@ -614,8 +617,8 @@ test.done();

},
"Content-Type name*": function(test){
var encodedText = "Content-Type: application/octet-stream;\r\n"+
" name*=UTF-8''%C3%95%C3%84%C3%96%C3%9C\r\n"+
"Content-Transfer-Encoding: QUOTED-PRINTABLE\r\n"+
"\r\n"+
"=00=01=02=03=FD=FE=FF",
"Content-Type name*": function(test) {
var encodedText = "Content-Type: application/octet-stream;\r\n" +
" name*=UTF-8''%C3%95%C3%84%C3%96%C3%9C\r\n" +
"Content-Transfer-Encoding: QUOTED-PRINTABLE\r\n" +
"\r\n" +
"=00=01=02=03=FD=FE=FF",
mail = new Buffer(encodedText, "utf-8");

@@ -625,3 +628,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].content && mail.attachments[0].fileName, "ÕÄÖÜ");

@@ -631,9 +634,9 @@ test.done();

},
"Content-Type name*X*": function(test){
var encodedText = "Content-Type: application/octet-stream;\r\n"+
" name*0*=UTF-8''%C3%95%C3%84;\r\n"+
" name*1*=%C3%96%C3%9C\r\n"+
"Content-Transfer-Encoding: QUOTED-PRINTABLE\r\n"+
"\r\n"+
"=00=01=02=03=FD=FE=FF",
"Content-Type name*X*": function(test) {
var encodedText = "Content-Type: application/octet-stream;\r\n" +
" name*0*=UTF-8''%C3%95%C3%84;\r\n" +
" name*1*=%C3%96%C3%9C\r\n" +
"Content-Transfer-Encoding: QUOTED-PRINTABLE\r\n" +
"\r\n" +
"=00=01=02=03=FD=FE=FF",
mail = new Buffer(encodedText, "utf-8");

@@ -643,3 +646,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].content && mail.attachments[0].fileName, "ÕÄÖÜ");

@@ -649,7 +652,7 @@ test.done();

},
"Default name from Content-type": function(test){
var encodedText = "Content-Type: application/pdf\r\n"+
"Content-Transfer-Encoding: QUOTED-PRINTABLE\r\n"+
"\r\n"+
"=00=01=02=03=FD=FE=FF",
"Default name from Content-type": function(test) {
var encodedText = "Content-Type: application/pdf\r\n" +
"Content-Transfer-Encoding: QUOTED-PRINTABLE\r\n" +
"\r\n" +
"=00=01=02=03=FD=FE=FF",
mail = new Buffer(encodedText, "utf-8");

@@ -659,3 +662,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].content && mail.attachments[0].generatedFileName, "attachment.pdf");

@@ -665,7 +668,7 @@ test.done();

},
"Default name": function(test){
var encodedText = "Content-Type: application/octet-stream\r\n"+
"Content-Transfer-Encoding: QUOTED-PRINTABLE\r\n"+
"\r\n"+
"=00=01=02=03=FD=FE=FF",
"Default name": function(test) {
var encodedText = "Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: QUOTED-PRINTABLE\r\n" +
"\r\n" +
"=00=01=02=03=FD=FE=FF",
mail = new Buffer(encodedText, "utf-8");

@@ -675,3 +678,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].content && mail.attachments[0].generatedFileName, "attachment.bin");

@@ -681,14 +684,14 @@ test.done();

},
"Multiple filenames - Same": function(test){
var encodedText = "Content-Type: multipart/mixed; boundary=ABC\r\n"+
"\r\n"+
"--ABC\r\n"+
"Content-Type: application/octet-stream; name=\"test.txt\"\r\n"+
"\r\n"+
"=00=01=02=03=FD=FE=FF\r\n"+
"--ABC\r\n"+
"Content-Type: application/octet-stream; name=\"test.txt\"\r\n"+
"\r\n"+
"=00=01=02=03=FD=FE=FF\r\n"+
"--ABC--",
"Multiple filenames - Same": function(test) {
var encodedText = "Content-Type: multipart/mixed; boundary=ABC\r\n" +
"\r\n" +
"--ABC\r\n" +
"Content-Type: application/octet-stream; name=\"test.txt\"\r\n" +
"\r\n" +
"=00=01=02=03=FD=FE=FF\r\n" +
"--ABC\r\n" +
"Content-Type: application/octet-stream; name=\"test.txt\"\r\n" +
"\r\n" +
"=00=01=02=03=FD=FE=FF\r\n" +
"--ABC--",
mail = new Buffer(encodedText, "utf-8");

@@ -698,3 +701,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].content && mail.attachments[0].generatedFileName, "test.txt");

@@ -705,14 +708,14 @@ test.equal(mail.attachments && mail.attachments[1] && mail.attachments[1].content && mail.attachments[1].generatedFileName, "test-1.txt");

},
"Multiple filenames - Different": function(test){
var encodedText = "Content-Type: multipart/mixed; boundary=ABC\r\n"+
"\r\n"+
"--ABC\r\n"+
"Content-Type: application/octet-stream\r\n"+
"\r\n"+
"=00=01=02=03=FD=FE=FF\r\n"+
"--ABC\r\n"+
"Content-Type: application/octet-stream; name=\"test.txt\"\r\n"+
"\r\n"+
"=00=01=02=03=FD=FE=FF\r\n"+
"--ABC--",
"Multiple filenames - Different": function(test) {
var encodedText = "Content-Type: multipart/mixed; boundary=ABC\r\n" +
"\r\n" +
"--ABC\r\n" +
"Content-Type: application/octet-stream\r\n" +
"\r\n" +
"=00=01=02=03=FD=FE=FF\r\n" +
"--ABC\r\n" +
"Content-Type: application/octet-stream; name=\"test.txt\"\r\n" +
"\r\n" +
"=00=01=02=03=FD=FE=FF\r\n" +
"--ABC--",
mail = new Buffer(encodedText, "utf-8");

@@ -722,3 +725,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].content && mail.attachments[0].generatedFileName, "attachment.bin");

@@ -729,22 +732,22 @@ test.equal(mail.attachments && mail.attachments[1] && mail.attachments[1].content && mail.attachments[1].generatedFileName, "test.txt");

},
"Multiple filenames - with number": function(test){
var encodedText = "Content-Type: multipart/mixed; boundary=ABC\r\n"+
"\r\n"+
"--ABC\r\n"+
"Content-Type: application/octet-stream; name=\"somename.txt\"\r\n"+
"\r\n"+
"=00=01=02=03=FD=FE=FF\r\n"+
"--ABC\r\n"+
"Content-Type: application/octet-stream; name=\"somename-1.txt\"\r\n"+
"\r\n"+
"=00=01=02=03=FD=FE=FF\r\n"+
"--ABC\r\n"+
"Content-Type: application/octet-stream; name=\"somename.txt\"\r\n"+
"\r\n"+
"=00=01=02=03=FD=FE=FF\r\n"+
"--ABC\r\n"+
"Content-Type: application/octet-stream; name=\"somename-1-1.txt\"\r\n"+
"\r\n"+
"=00=01=02=03=FD=FE=FF\r\n"+
"--ABC--",
"Multiple filenames - with number": function(test) {
var encodedText = "Content-Type: multipart/mixed; boundary=ABC\r\n" +
"\r\n" +
"--ABC\r\n" +
"Content-Type: application/octet-stream; name=\"somename.txt\"\r\n" +
"\r\n" +
"=00=01=02=03=FD=FE=FF\r\n" +
"--ABC\r\n" +
"Content-Type: application/octet-stream; name=\"somename-1.txt\"\r\n" +
"\r\n" +
"=00=01=02=03=FD=FE=FF\r\n" +
"--ABC\r\n" +
"Content-Type: application/octet-stream; name=\"somename.txt\"\r\n" +
"\r\n" +
"=00=01=02=03=FD=FE=FF\r\n" +
"--ABC\r\n" +
"Content-Type: application/octet-stream; name=\"somename-1-1.txt\"\r\n" +
"\r\n" +
"=00=01=02=03=FD=FE=FF\r\n" +
"--ABC--",
mail = new Buffer(encodedText, "utf-8");

@@ -754,3 +757,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].content && mail.attachments[0].generatedFileName, "somename.txt");

@@ -763,10 +766,10 @@ test.equal(mail.attachments && mail.attachments[1] && mail.attachments[1].content && mail.attachments[1].generatedFileName, "somename-1-1.txt");

},
"Generate filename from Content-Type": function(test){
var encodedText = "Content-Type: multipart/mixed; boundary=ABC\r\n"+
"\r\n"+
"--ABC\r\n"+
"Content-Type: application/pdf\r\n"+
"\r\n"+
"=00=01=02=03=FD=FE=FF\r\n"+
"--ABC--",
"Generate filename from Content-Type": function(test) {
var encodedText = "Content-Type: multipart/mixed; boundary=ABC\r\n" +
"\r\n" +
"--ABC\r\n" +
"Content-Type: application/pdf\r\n" +
"\r\n" +
"=00=01=02=03=FD=FE=FF\r\n" +
"--ABC--",
mail = new Buffer(encodedText, "utf-8");

@@ -776,3 +779,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].content && mail.attachments[0].generatedFileName, "attachment.pdf");

@@ -782,10 +785,10 @@ test.done();

},
"Filename with semicolon": function(test){
var encodedText = "Content-Type: multipart/mixed; boundary=ABC\r\n"+
"\r\n"+
"--ABC\r\n"+
"Content-Disposition: attachment; filename=\"hello;world;test.txt\"\r\n"+
"\r\n"+
"=00=01=02=03=FD=FE=FF\r\n"+
"--ABC--",
"Filename with semicolon": function(test) {
var encodedText = "Content-Type: multipart/mixed; boundary=ABC\r\n" +
"\r\n" +
"--ABC\r\n" +
"Content-Disposition: attachment; filename=\"hello;world;test.txt\"\r\n" +
"\r\n" +
"=00=01=02=03=FD=FE=FF\r\n" +
"--ABC--",
mail = new Buffer(encodedText, "utf-8");

@@ -795,3 +798,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].content && mail.attachments[0].generatedFileName, "hello;world;test.txt");

@@ -805,3 +808,3 @@ test.done();

exports["Plaintext format"] = {
"Default": function(test){
"Default": function(test) {
var encodedText = "Content-Type: text/plain;\r\n\r\nFirst line \r\ncontinued",

@@ -812,3 +815,3 @@ mail = new Buffer(encodedText, "utf-8");

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "First line \ncontinued");

@@ -818,3 +821,3 @@ test.done();

},
"Flowed": function(test){
"Flowed": function(test) {
var encodedText = "Content-Type: text/plain; format=flowed\r\n\r\nFirst line \r\ncontinued \r\nand so on",

@@ -825,3 +828,3 @@ mail = new Buffer(encodedText, "utf-8");

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "First line continued and so on");

@@ -831,5 +834,5 @@ test.done();

},
"Flowed Signature": function(test){
var encodedText = "Content-Type: text/plain; format=flowed\r\n\r\nHow are you today?\r\n"+
"-- \r\n"+
"Flowed Signature": function(test) {
var encodedText = "Content-Type: text/plain; format=flowed\r\n\r\nHow are you today?\r\n" +
"-- \r\n" +
"Signature\r\n",

@@ -840,3 +843,3 @@ mail = new Buffer(encodedText, "utf-8");

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "How are you today?\n-- \nSignature\n");

@@ -846,3 +849,3 @@ test.done();

},
"Fixed": function(test){
"Fixed": function(test) {
var encodedText = "Content-Type: text/plain; format=fixed\r\n\r\nFirst line \r\ncontinued \r\nand so on",

@@ -853,3 +856,3 @@ mail = new Buffer(encodedText, "utf-8");

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "First line \ncontinued \nand so on");

@@ -859,3 +862,3 @@ test.done();

},
"DelSp": function(test){
"DelSp": function(test) {
var encodedText = "Content-Type: text/plain; format=flowed; delsp=yes\r\n\r\nFirst line \r\ncontinued \r\nand so on",

@@ -866,3 +869,3 @@ mail = new Buffer(encodedText, "utf-8");

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "First linecontinuedand so on");

@@ -872,3 +875,3 @@ test.done();

},
"Quoted printable, Flowed": function(test){
"Quoted printable, Flowed": function(test) {
var encodedText = "Content-Type: text/plain; format=flowed\r\nContent-Transfer-Encoding: QUOTED-PRINTABLE\r\n\r\nFoo =\n\nBar =\n\nBaz",

@@ -879,3 +882,3 @@ mail = new Buffer(encodedText, "utf-8");

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "Foo Bar Baz");

@@ -885,5 +888,5 @@ test.done();

},
"Quoted printable, Flowed Signature": function(test){
var encodedText = "Content-Type: text/plain; format=flowed\r\nContent-Transfer-Encoding: QUOTED-PRINTABLE\r\n\r\nHow are you today?\r\n"+
"-- \r\n"+
"Quoted printable, Flowed Signature": function(test) {
var encodedText = "Content-Type: text/plain; format=flowed\r\nContent-Transfer-Encoding: QUOTED-PRINTABLE\r\n\r\nHow are you today?\r\n" +
"-- \r\n" +
"Signature\r\n",

@@ -894,3 +897,3 @@ mail = new Buffer(encodedText, "utf-8");

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "How are you today?\n-- \nSignature\n");

@@ -900,3 +903,3 @@ test.done();

},
"Quoted printable, DelSp": function(test){
"Quoted printable, DelSp": function(test) {
var encodedText = "Content-Type: text/plain; format=flowed; delsp=yes\r\nContent-Transfer-Encoding: QUOTED-PRINTABLE\r\n\r\nFoo =\n\nBar =\n\nBaz",

@@ -907,3 +910,3 @@ mail = new Buffer(encodedText, "utf-8");

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "FooBarBaz");

@@ -916,3 +919,3 @@ test.done();

exports["Transfer encoding"] = {
"Quoted-Printable Default charset": function(test){
"Quoted-Printable Default charset": function(test) {
var encodedText = "Content-type: text/plain\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n=D5=C4=D6=DC",

@@ -923,3 +926,3 @@ mail = new Buffer(encodedText, "utf-8");

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "ÕÄÖÜ");

@@ -929,3 +932,3 @@ test.done();

},
"Quoted-Printable UTF-8": function(test){
"Quoted-Printable UTF-8": function(test) {
var encodedText = "Content-type: text/plain; charset=utf-8\r\nContent-Transfer-Encoding: QUOTED-PRINTABLE\r\n\r\n=C3=95=C3=84=C3=96=C3=9C",

@@ -936,3 +939,3 @@ mail = new Buffer(encodedText, "utf-8");

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "ÕÄÖÜ");

@@ -942,3 +945,3 @@ test.done();

},
"Base64 Default charset": function(test){
"Base64 Default charset": function(test) {
var encodedText = "Content-type: text/plain\r\nContent-Transfer-Encoding: bAse64\r\n\r\n1cTW3A==",

@@ -949,3 +952,3 @@ mail = new Buffer(encodedText, "utf-8");

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "ÕÄÖÜ");

@@ -955,3 +958,3 @@ test.done();

},
"Base64 UTF-8": function(test){
"Base64 UTF-8": function(test) {
var encodedText = "Content-type: text/plain; charset=utf-8\r\nContent-Transfer-Encoding: bAse64\r\n\r\nw5XDhMOWw5w=",

@@ -962,3 +965,3 @@ mail = new Buffer(encodedText, "utf-8");

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "ÕÄÖÜ");

@@ -968,3 +971,3 @@ test.done();

},
"Mime Words": function(test){
"Mime Words": function(test) {
var encodedText = "Content-type: text/plain; charset=utf-8\r\nSubject: =?iso-8859-1?Q?Avaldu?= =?iso-8859-1?Q?s_lepingu_?=\r\n =?iso-8859-1?Q?l=F5petamise?= =?iso-8859-1?Q?ks?=\r\n",

@@ -975,3 +978,3 @@ mail = new Buffer(encodedText, "utf-8");

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.subject, "Avaldus lepingu lõpetamiseks");

@@ -981,6 +984,6 @@ test.done();

},
"Mime Words with invalid linebreaks (Sparrow)": function(test){
"Mime Words with invalid linebreaks (Sparrow)": function(test) {
var encodedText = "Content-type: text/plain; charset=utf-8\r\n" +
"Subject: abc=?utf-8?Q?=C3=B6=C\r\n"+
" 3=B5=C3=BC?=",
"Subject: abc=?utf-8?Q?=C3=B6=C\r\n" +
" 3=B5=C3=BC?=",
mail = new Buffer(encodedText, "utf-8");

@@ -990,3 +993,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.subject, "abcöõü");

@@ -996,5 +999,7 @@ test.done();

},
"8bit Default charset": function(test){
"8bit Default charset": function(test) {
var encodedText = "Content-type: text/plain\r\nContent-Transfer-Encoding: 8bit\r\n\r\nÕÄÖÜ",
textmap = encodedText.split('').map(function(chr){return chr.charCodeAt(0);}),
textmap = encodedText.split('').map(function(chr) {
return chr.charCodeAt(0);
}),
mail = new Buffer(textmap);

@@ -1004,3 +1009,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "ÕÄÖÜ");

@@ -1010,3 +1015,3 @@ test.done();

},
"8bit UTF-8": function(test){
"8bit UTF-8": function(test) {
var encodedText = "Content-type: text/plain; charset=utf-8\r\nContent-Transfer-Encoding: 8bit\r\n\r\nÕÄÖÜ",

@@ -1017,3 +1022,3 @@ mail = new Buffer(encodedText, "utf-8");

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "ÕÄÖÜ");

@@ -1023,3 +1028,3 @@ test.done();

},
"Invalid Quoted-Printable": function(test){
"Invalid Quoted-Printable": function(test) {
var encodedText = "Content-type: text/plain; charset=utf-8\r\nContent-Transfer-Encoding: QUOTED-PRINTABLE\r\n\r\n==C3==95=C3=84=C3=96=C3=9C=",

@@ -1030,3 +1035,3 @@ mail = new Buffer(encodedText, "utf-8");

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "=�=�ÄÖÜ");

@@ -1036,3 +1041,3 @@ test.done();

},
"Invalid BASE64": function(test){
"Invalid BASE64": function(test) {
var encodedText = "Content-type: text/plain; charset=utf-8\r\nContent-Transfer-Encoding: base64\r\n\r\nw5XDhMOWw5",

@@ -1043,8 +1048,10 @@ mail = new Buffer(encodedText, "utf-8");

mailparser.end(mail);
mailparser.on("end", function(mail){
test.equal(Array.prototype.map.call(mail.text, function(chr){return chr.charCodeAt(0);}).join(","), "213,196,214,65533");
mailparser.on("end", function(mail) {
test.equal(Array.prototype.map.call(mail.text, function(chr) {
return chr.charCodeAt(0);
}).join(","), "213,196,214,65533");
test.done();
});
},
"gb2312 mime words": function(test){
"gb2312 mime words": function(test) {
var encodedText = "From: =?gb2312?B?086yyZjl?= user@ldkf.com.tw\r\n\r\nBody",

@@ -1055,8 +1062,11 @@ mail = new Buffer(encodedText, "utf-8");

mailparser.end(mail);
mailparser.on("end", function(mail){
test.deepEqual(mail.from, [{address: 'user@ldkf.com.tw', name: '游采樺'}]);
mailparser.on("end", function(mail) {
test.deepEqual(mail.from, [{
address: 'user@ldkf.com.tw',
name: '游采樺'
}]);
test.done();
});
},
"Valid Date header": function(test){
"Valid Date header": function(test) {
var encodedText = "Date: Wed, 08 Jan 2014 09:52:26 -0800\r\n\r\n1cTW3A==",

@@ -1067,3 +1077,3 @@ mail = new Buffer(encodedText, "utf-8");

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.date.toISOString(), "2014-01-08T17:52:26.000Z");

@@ -1074,3 +1084,3 @@ test.equal(mail.headers.date, "Wed, 08 Jan 2014 09:52:26 -0800");

},
"Invalid Date header": function(test){
"Invalid Date header": function(test) {
var encodedText = "Date: zzzzz\r\n\r\n1cTW3A==",

@@ -1081,3 +1091,3 @@ mail = new Buffer(encodedText, "utf-8");

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.ok(!mail.date);

@@ -1088,3 +1098,3 @@ test.equal(mail.headers.date, "zzzzz");

},
"Missing Date header": function(test){
"Missing Date header": function(test) {
var encodedText = "Subject: test\r\n\r\n1cTW3A==",

@@ -1095,3 +1105,3 @@ mail = new Buffer(encodedText, "utf-8");

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.ok(!mail.date);

@@ -1101,2 +1111,29 @@ test.equal(mail.headers.date, undefined);

});
},
"Received Headers": function(test) {
var encodedTest = "Received: by 10.25.25.72 with SMTP id 69csp2404548lfz;\r\n" +
" Fri, 6 Feb 2015 20:15:32 -0800 (PST)\r\n" +
"X-Received: by 10.194.200.68 with SMTP id jq4mr7518476wjc.128.1423264531879;\r\n" +
" Fri, 06 Feb 2015 15:15:31 -0800 (PST)\r\n" +
"Received: from mail.formilux.org (flx02.formilux.org. [195.154.117.161])\r\n" +
" by mx.google.com with ESMTP id wn4si6920692wjc.106.2015.02.06.15.15.31\r\n" +
" for <test@example.com>;\r\n" +
" Fri, 06 Feb 2015 15:15:31 -0800 (PST)\r\n" +
"Received: from flx02.formilux.org (flx02.formilux.org [127.0.0.1])\r\n" +
" by mail.formilux.org (Postfix) with SMTP id 9D262450C77\r\n" +
" for <test@example.com>; Sat, 7 Feb 2015 00:15:31 +0100 (CET)\r\n" +
"Date: Fri, 6 Feb 2015 16:13:51 -0700 (MST)\r\n" +
"\r\n" +
"1cTW3A==",
mail = new Buffer(encodedTest, "utf-8");
var mailparser = new MailParser();
mailparser.end(mail);
mailparser.on("end", function(mail) {
test.ok(mail.date);
test.ok(mail.receivedDate);
test.equal(mail.date.toISOString(), "2015-02-06T23:13:51.000Z");
test.equal(mail.receivedDate.toISOString(), "2015-02-07T04:15:32.000Z");
test.done();
});
}

@@ -1106,3 +1143,3 @@ };

exports["Multipart content"] = {
"Simple": function(test){
"Simple": function(test) {
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n\r\n--ABC\r\nContent-type: text/plain; charset=utf-8\r\n\r\nÕÄÖÜ\r\n--ABC--",

@@ -1113,3 +1150,3 @@ mail = new Buffer(encodedText, "utf-8");

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "ÕÄÖÜ");

@@ -1119,14 +1156,14 @@ test.done();

},
"Nested": function(test){
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n"+
"\r\n"+
"--ABC\r\n"+
"Content-type: multipart/related; boundary=DEF\r\n"+
"\r\n"+
"--DEF\r\n"+
"Content-type: text/plain; charset=utf-8\r\n"+
"\r\n"+
"ÕÄÖÜ\r\n"+
"--DEF--\r\n"+
"--ABC--",
"Nested": function(test) {
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n" +
"\r\n" +
"--ABC\r\n" +
"Content-type: multipart/related; boundary=DEF\r\n" +
"\r\n" +
"--DEF\r\n" +
"Content-type: text/plain; charset=utf-8\r\n" +
"\r\n" +
"ÕÄÖÜ\r\n" +
"--DEF--\r\n" +
"--ABC--",
mail = new Buffer(encodedText, "utf-8");

@@ -1136,3 +1173,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "ÕÄÖÜ");

@@ -1142,12 +1179,12 @@ test.done();

},
"Inline text (Sparrow)": function(test){
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n"+
"\r\n"+
"--ABC\r\n"+
"Content-Type: text/plain; charset=\"utf-8\"\r\n"+
"Content-Transfer-Encoding: 8bit\r\n"+
"Content-Disposition: inline\r\n"+
"\r\n"+
"ÕÄÖÜ\r\n"+
"--ABC--",
"Inline text (Sparrow)": function(test) {
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n" +
"\r\n" +
"--ABC\r\n" +
"Content-Type: text/plain; charset=\"utf-8\"\r\n" +
"Content-Transfer-Encoding: 8bit\r\n" +
"Content-Disposition: inline\r\n" +
"\r\n" +
"ÕÄÖÜ\r\n" +
"--ABC--",
mail = new Buffer(encodedText, "utf-8");

@@ -1157,3 +1194,3 @@

mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "ÕÄÖÜ");

@@ -1163,18 +1200,18 @@ test.done();

},
"Different Levels": function(test){
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n"+
"\r\n"+
"--ABC\r\n"+
"Content-type: text/html; charset=utf-8\r\n"+
"\r\n"+
"ÕÄÖÜ2\r\n"+
"--ABC\r\n"+
"Content-type: multipart/related; boundary=DEF\r\n"+
"\r\n"+
"--DEF\r\n"+
"Content-type: text/plain; charset=utf-8\r\n"+
"\r\n"+
"ÕÄÖÜ1\r\n"+
"--DEF--\r\n"+
"--ABC--",
"Different Levels": function(test) {
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n" +
"\r\n" +
"--ABC\r\n" +
"Content-type: text/html; charset=utf-8\r\n" +
"\r\n" +
"ÕÄÖÜ2\r\n" +
"--ABC\r\n" +
"Content-type: multipart/related; boundary=DEF\r\n" +
"\r\n" +
"--DEF\r\n" +
"Content-type: text/plain; charset=utf-8\r\n" +
"\r\n" +
"ÕÄÖÜ1\r\n" +
"--DEF--\r\n" +
"--ABC--",
mail = new Buffer(encodedText, "utf-8");

@@ -1185,3 +1222,3 @@

mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "ÕÄÖÜ1");

@@ -1195,12 +1232,12 @@ test.equal(mail.html, "ÕÄÖÜ2");

exports["Attachment info"] = {
"Included integrity": function(test){
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n"+
"\r\n"+
"--ABC\r\n"+
"Content-Type: application/octet-stream\r\n"+
"Content-Transfer-Encoding: quoted-printable\r\n"+
"Content-Disposition: attachment\r\n"+
"\r\n"+
"=00=01=02=03=04=05=06\r\n"+
"--ABC--",
"Included integrity": function(test) {
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n" +
"\r\n" +
"--ABC\r\n" +
"Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: quoted-printable\r\n" +
"Content-Disposition: attachment\r\n" +
"\r\n" +
"=00=01=02=03=04=05=06\r\n" +
"--ABC--",
expectedHash = "9aa461e1eca4086f9230aa49c90b0c61",

@@ -1211,3 +1248,3 @@ mail = new Buffer(encodedText, "utf-8");

for(var i=0, len = mail.length; i<len; i++){
for (var i = 0, len = mail.length; i < len; i++) {
mailparser.write(new Buffer([mail[i]]));

@@ -1217,3 +1254,3 @@ }

mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].checksum, expectedHash);

@@ -1224,18 +1261,20 @@ test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].length, 7);

},
"Stream integrity base64": function(test){
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n"+
"\r\n"+
"--ABC\r\n"+
"Content-Type: application/octet-stream\r\n"+
"Content-Transfer-Encoding: base64\r\n"+
"Content-Disposition: attachment\r\n"+
"\r\n"+
"AAECAwQFBg==\r\n"+
"--ABC--",
"Stream integrity base64": function(test) {
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n" +
"\r\n" +
"--ABC\r\n" +
"Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: base64\r\n" +
"Content-Disposition: attachment\r\n" +
"\r\n" +
"AAECAwQFBg==\r\n" +
"--ABC--",
expectedHash = "9aa461e1eca4086f9230aa49c90b0c61",
mail = new Buffer(encodedText, "utf-8");
var mailparser = new MailParser({streamAttachments: true});
var mailparser = new MailParser({
streamAttachments: true
});
for(var i=0, len = mail.length; i<len; i++){
for (var i = 0, len = mail.length; i < len; i++) {
mailparser.write(new Buffer([mail[i]]));

@@ -1246,3 +1285,3 @@ }

mailparser.on("attachment", function(attachment){
mailparser.on("attachment", function(attachment) {
test.ok(attachment.stream, "Stream detected");

@@ -1253,3 +1292,3 @@ });

mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].checksum, expectedHash);

@@ -1260,26 +1299,29 @@ test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].length, 7);

},
"Stream integrity - 8bit": function(test){
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n"+
"\r\n"+
"--ABC\r\n"+
"Content-Type: application/octet-stream\r\n"+
"Content-Transfer-Encoding: 8bit\r\n"+
"Content-Disposition: attachment\r\n"+
"\r\n"+
"ÕÄ\r\n"+
"ÖÜ\r\n"+
"--ABC--",
"Stream integrity - 8bit": function(test) {
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n" +
"\r\n" +
"--ABC\r\n" +
"Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: 8bit\r\n" +
"Content-Disposition: attachment\r\n" +
"\r\n" +
"ÕÄ\r\n" +
"ÖÜ\r\n" +
"--ABC--",
expectedHash = "cad0f72629a7245dd3d2cbf41473e3ca",
mail = new Buffer(encodedText, "utf-8");
var mailparser = new MailParser({streamAttachments: true});
var mailparser = new MailParser({
streamAttachments: true
});
for(var i=0, len = mail.length; i<len; i++){
for (var i = 0, len = mail.length; i < len; i++) {
mailparser.write(new Buffer([mail[i]]));
}
test.expect(3);
test.expect(4);
mailparser.on("attachment", function(attachment){
mailparser.on("attachment", function(attachment, node) {
test.ok(attachment.stream, "Stream detected");
test.ok(node);
});

@@ -1289,3 +1331,3 @@

mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].checksum, expectedHash);

@@ -1296,20 +1338,22 @@ test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].length, 10);

},
"Stream integrity - binary, non utf-8": function(test){
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n"+
"\r\n"+
"--ABC\r\n"+
"Content-Type: application/octet-stream\r\n"+
"Content-Transfer-Encoding: 8bit\r\n"+
"Content-Disposition: attachment\r\n"+
"\r\n"+
"ÕÄ\r\n"+
"ÖÜ\r\n"+
"ŽŠ\r\n"+
"--ABC--",
"Stream integrity - binary, non utf-8": function(test) {
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n" +
"\r\n" +
"--ABC\r\n" +
"Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: 8bit\r\n" +
"Content-Disposition: attachment\r\n" +
"\r\n" +
"ÕÄ\r\n" +
"ÖÜ\r\n" +
"ŽŠ\r\n" +
"--ABC--",
expectedHash = "34bca86f8cc340bbd11446ee16ee3cae",
mail = encodinglib.convert(encodedText, "latin-13");
var mailparser = new MailParser({streamAttachments: true});
var mailparser = new MailParser({
streamAttachments: true
});
for(var i=0, len = mail.length; i<len; i++){
for (var i = 0, len = mail.length; i < len; i++) {
mailparser.write(new Buffer([mail[i]]));

@@ -1320,3 +1364,3 @@ }

mailparser.on("attachment", function(attachment){
mailparser.on("attachment", function(attachment) {
test.ok(attachment.stream, "Stream detected");

@@ -1327,3 +1371,3 @@ });

mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].checksum, expectedHash);

@@ -1334,20 +1378,22 @@ test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].length, 10);

},
"Stream integrity - qp, non utf-8": function(test){
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n"+
"\r\n"+
"--ABC\r\n"+
"Content-Type: application/octet-stream; charset=iso-8859-13\r\n"+
"Content-Transfer-Encoding: quoted-printable\r\n"+
"Content-Disposition: attachment\r\n"+
"\r\n"+
"=d5=c4\r\n"+
"=d6=dc\r\n"+
"=de=d0\r\n"+
"--ABC--",
"Stream integrity - qp, non utf-8": function(test) {
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n" +
"\r\n" +
"--ABC\r\n" +
"Content-Type: application/octet-stream; charset=iso-8859-13\r\n" +
"Content-Transfer-Encoding: quoted-printable\r\n" +
"Content-Disposition: attachment\r\n" +
"\r\n" +
"=d5=c4\r\n" +
"=d6=dc\r\n" +
"=de=d0\r\n" +
"--ABC--",
expectedHash = "34bca86f8cc340bbd11446ee16ee3cae",
mail = new Buffer(encodedText, "utf-8");
var mailparser = new MailParser({streamAttachments: true});
var mailparser = new MailParser({
streamAttachments: true
});
for(var i=0, len = mail.length; i<len; i++){
for (var i = 0, len = mail.length; i < len; i++) {
mailparser.write(new Buffer([mail[i]]));

@@ -1358,3 +1404,3 @@ }

mailparser.on("attachment", function(attachment){
mailparser.on("attachment", function(attachment) {
test.ok(attachment.stream, "Stream detected");

@@ -1365,3 +1411,3 @@ });

mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].checksum, expectedHash);

@@ -1372,20 +1418,22 @@ test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].length, 10);

},
"Stream integrity - uuencode": function(test){
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n"+
"\r\n"+
"--ABC\r\n"+
"Content-Type: application/octet-stream\r\n"+
"Content-Transfer-Encoding: uuencode\r\n"+
"\r\n"+
"begin 644 buffer.bin\r\n"+
"#0V%T\r\n"+
"`\r\n"+
"end\r\n"+
"--ABC--",
"Stream integrity - uuencode": function(test) {
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n" +
"\r\n" +
"--ABC\r\n" +
"Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: uuencode\r\n" +
"\r\n" +
"begin 644 buffer.bin\r\n" +
"#0V%T\r\n" +
"`\r\n" +
"end\r\n" +
"--ABC--",
expectedHash = "fa3ebd6742c360b2d9652b7f78d9bd7d",
mail = new Buffer(encodedText, "utf-8");
var mailparser = new MailParser({streamAttachments: true});
var mailparser = new MailParser({
streamAttachments: true
});
for(var i=0, len = mail.length; i<len; i++){
for (var i = 0, len = mail.length; i < len; i++) {
mailparser.write(new Buffer([mail[i]]));

@@ -1396,3 +1444,3 @@ }

mailparser.on("attachment", function(attachment){
mailparser.on("attachment", function(attachment) {
test.ok(attachment.stream, "Stream detected");

@@ -1403,3 +1451,3 @@ });

mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].checksum, expectedHash);

@@ -1410,30 +1458,65 @@ test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].length, 3);

},
"Stream multiple attachments": function(test){
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n"+
"\r\n"+
"--ABC\r\n"+
"Content-Type: application/octet-stream\r\n"+
"Content-Transfer-Encoding: base64\r\n"+
"Content-Disposition: attachment\r\n"+
"\r\n"+
"AAECAwQFBg==\r\n"+
"--ABC\r\n"+
"Content-Type: application/octet-stream\r\n"+
"Content-Transfer-Encoding: base64\r\n"+
"Content-Disposition: attachment\r\n"+
"\r\n"+
"AAECAwQFBg==\r\n"+
"--ABC\r\n"+
"Content-Type: application/octet-stream\r\n"+
"Content-Transfer-Encoding: base64\r\n"+
"Content-Disposition: attachment; filename=\"test.txt\"\r\n"+
"\r\n"+
"AAECAwQFBg==\r\n"+
"--ABC--",
"Attachment in root node": function(test) {
var encodedText = "Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: 8bit\r\n" +
"Content-Disposition: attachment\r\n" +
"\r\n" +
"ÕÄ\r\n" +
"ÖÜ",
expectedHash = "cad0f72629a7245dd3d2cbf41473e3ca",
mail = new Buffer(encodedText, "utf-8");
var mailparser = new MailParser({streamAttachments: true});
var mailparser = new MailParser({
streamAttachments: true
});
for (var i = 0, len = mail.length; i < len; i++) {
mailparser.write(new Buffer([mail[i]]));
}
test.expect(4);
mailparser.on("attachment", function(attachment, node) {
test.ok(attachment.stream, "Stream detected");
test.ok(node);
});
mailparser.end();
mailparser.on("end", function(mail) {
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].checksum, expectedHash);
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].length, 10);
test.done();
});
},
"Stream multiple attachments": function(test) {
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n" +
"\r\n" +
"--ABC\r\n" +
"Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: base64\r\n" +
"Content-Disposition: attachment\r\n" +
"\r\n" +
"AAECAwQFBg==\r\n" +
"--ABC\r\n" +
"Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: base64\r\n" +
"Content-Disposition: attachment\r\n" +
"\r\n" +
"AAECAwQFBg==\r\n" +
"--ABC\r\n" +
"Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: base64\r\n" +
"Content-Disposition: attachment; filename=\"test.txt\"\r\n" +
"\r\n" +
"AAECAwQFBg==\r\n" +
"--ABC--",
mail = new Buffer(encodedText, "utf-8");
var mailparser = new MailParser({
streamAttachments: true
});
test.expect(3); // should be 3 attachments
mailparser.on("attachment", function(attachment){
mailparser.on("attachment", function(attachment) {
test.ok(attachment.stream, "Stream detected");

@@ -1444,3 +1527,3 @@ });

mailparser.on("end", function(mail){
mailparser.on("end", function() {
test.done();

@@ -1450,19 +1533,20 @@ });

"Pass mail node to headers event": function(test){
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n"+
"Subject: ABCDEF\r\n"+
"\r\n"+
"--ABC\r\n"+
"Content-Type: application/octet-stream\r\n"+
"Content-Transfer-Encoding: base64\r\n"+
"Content-Disposition: attachment\r\n"+
"\r\n"+
"AAECAwQFBg==\r\n"+
"--ABC--",
expectedHash = "9aa461e1eca4086f9230aa49c90b0c61",
"Pass mail node to headers event": function(test) {
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n" +
"Subject: ABCDEF\r\n" +
"\r\n" +
"--ABC\r\n" +
"Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: base64\r\n" +
"Content-Disposition: attachment\r\n" +
"\r\n" +
"AAECAwQFBg==\r\n" +
"--ABC--",
mail = new Buffer(encodedText, "utf-8");
var mailparser = new MailParser({streamAttachments: true});
var mailparser = new MailParser({
streamAttachments: true
});
for(var i=0, len = mail.length; i<len; i++){
for (var i = 0, len = mail.length; i < len; i++) {
mailparser.write(new Buffer([mail[i]]));

@@ -1473,3 +1557,3 @@ }

mailparser.on("attachment", function(attachment, email){
mailparser.on("attachment", function(attachment, email) {
test.equal(email.subject, "ABCDEF");

@@ -1480,3 +1564,3 @@ });

mailparser.on("end", function(mail){
mailparser.on("end", function() {
test.ok(1, "Done");

@@ -1486,12 +1570,12 @@ test.done();

},
"Detect Content-Type by filename": function(test){
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n"+
"\r\n"+
"--ABC\r\n"+
"Content-Type: application/octet-stream\r\n"+
"Content-Transfer-Encoding: base64\r\n"+
"Content-Disposition: attachment; filename=\"test.pdf\"\r\n"+
"\r\n"+
"AAECAwQFBg==\r\n"+
"--ABC--",
"Detect Content-Type by filename": function(test) {
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n" +
"\r\n" +
"--ABC\r\n" +
"Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: base64\r\n" +
"Content-Disposition: attachment; filename=\"test.pdf\"\r\n" +
"\r\n" +
"AAECAwQFBg==\r\n" +
"--ABC--",
mail = new Buffer(encodedText, "utf-8");

@@ -1504,3 +1588,3 @@

mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.attachments && mail.attachments[0] && mail.attachments[0].contentType, "application/pdf");

@@ -1511,29 +1595,31 @@ test.done();

"Inline attachments": function(test){
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n"+
"X-Test: =?UTF-8?Q?=C3=95=C3=84?= =?UTF-8?Q?=C3=96=C3=9C?=\r\n"+
"Subject: ABCDEF\r\n"+
"\r\n"+
"--ABC\r\n"+
"Content-Type: text/html\r\n"+
"\r\n"+
"<p>test 1</p>\r\n"+
"--ABC\r\n"+
"Content-Type: application/octet-stream\r\n"+
"Content-Transfer-Encoding: base64\r\n"+
"Content-Disposition: attachment; filename=\"test.pdf\"\r\n"+
"\r\n"+
"AAECAwQFBg==\r\n"+
"--ABC\r\n"+
"Content-Type: text/html\r\n"+
"\r\n"+
"<p>test 2</p>\r\n"+
"--ABC--",
"Inline attachments": function(test) {
var encodedText = "Content-type: multipart/mixed; boundary=ABC\r\n" +
"X-Test: =?UTF-8?Q?=C3=95=C3=84?= =?UTF-8?Q?=C3=96=C3=9C?=\r\n" +
"Subject: ABCDEF\r\n" +
"\r\n" +
"--ABC\r\n" +
"Content-Type: text/html\r\n" +
"\r\n" +
"<p>test 1</p>\r\n" +
"--ABC\r\n" +
"Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: base64\r\n" +
"Content-Disposition: attachment; filename=\"test.pdf\"\r\n" +
"\r\n" +
"AAECAwQFBg==\r\n" +
"--ABC\r\n" +
"Content-Type: text/html\r\n" +
"\r\n" +
"<p>test 2</p>\r\n" +
"--ABC--",
mail = new Buffer(encodedText, "utf-8");
test.expect(1);
var mailparser = new MailParser({showAttachmentLinks: true});
var mailparser = new MailParser({
showAttachmentLinks: true
});
mailparser.end(mail);
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.html, '<p>test 1</p><br/>\n\n<div class="mailparser-attachment"><a href="cid:754dc77d28e62763c4916970d595a10f@mailparser">&lt;test.pdf&gt;</a></div><br/>\n<p>test 2</p>');

@@ -1545,3 +1631,3 @@ test.done();

exports["Advanced nested HTML"] = function(test){
exports["Advanced nested HTML"] = function(test) {
var mail = fs.readFileSync(__dirname + "/nested.eml");

@@ -1552,3 +1638,3 @@

for(var i=0, len = mail.length; i<len; i++){
for (var i = 0, len = mail.length; i < len; i++) {
mailparser.write(new Buffer([mail[i]]));

@@ -1558,3 +1644,3 @@ }

mailparser.end();
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "\nDear Sir,\n\nGood evening.\n\n\n \n\n\n\nThe footer\n");

@@ -1567,7 +1653,7 @@ test.equal(mail.html, "<p>Dear Sir</p>\n<p>Good evening.</p>\n<p></p><p>The footer</p>\n");

exports["MBOX format"] = {
"Not a mbox": function(test){
"Not a mbox": function(test) {
var encodedText = "Content-Type: text/plain; charset=utf-8\r\n" +
"\r\n" +
"ÕÄ\r\n" +
"ÖÜ", // \r\nÕÄÖÜ
"\r\n" +
"ÕÄ\r\n" +
"ÖÜ", // \r\nÕÄÖÜ
mail = new Buffer(encodedText, "utf-8");

@@ -1578,3 +1664,3 @@

for(var i=0, len = mail.length; i<len; i++){
for (var i = 0, len = mail.length; i < len; i++) {
mailparser.write(new Buffer([mail[i]]));

@@ -1584,3 +1670,3 @@ }

mailparser.end();
mailparser.on("end", function(mail){
mailparser.on("end", function() {
test.equal(mailparser._isMbox, false);

@@ -1591,8 +1677,8 @@ test.done();

"Is a mbox": function(test){
var encodedText = "From MAILER-DAEMON Fri Jul 8 12:08:34 2011\r\n"+
"Content-Type: text/plain; charset=utf-8\r\n" +
"\r\n" +
"ÕÄ\r\n" +
"ÖÜ", // \r\nÕÄÖÜ
"Is a mbox": function(test) {
var encodedText = "From MAILER-DAEMON Fri Jul 8 12:08:34 2011\r\n" +
"Content-Type: text/plain; charset=utf-8\r\n" +
"\r\n" +
"ÕÄ\r\n" +
"ÖÜ", // \r\nÕÄÖÜ
mail = new Buffer(encodedText, "utf-8");

@@ -1603,3 +1689,3 @@

for(var i=0, len = mail.length; i<len; i++){
for (var i = 0, len = mail.length; i < len; i++) {
mailparser.write(new Buffer([mail[i]]));

@@ -1609,3 +1695,3 @@ }

mailparser.end();
mailparser.on("end", function(mail){
mailparser.on("end", function() {
test.equal(mailparser._isMbox, true);

@@ -1616,7 +1702,7 @@ test.done();

"Don't unescape '>From '": function(test){
"Don't unescape '>From '": function(test) {
var encodedText = "Content-Type: text/plain; charset=utf-8\r\n" +
"\r\n" +
">From test\r\n" +
">>From pest", // \r\nÕÄÖÜ
"\r\n" +
">From test\r\n" +
">>From pest", // \r\nÕÄÖÜ
mail = new Buffer(encodedText, "utf-8");

@@ -1627,3 +1713,3 @@

for(var i=0, len = mail.length; i<len; i++){
for (var i = 0, len = mail.length; i < len; i++) {
mailparser.write(new Buffer([mail[i]]));

@@ -1633,3 +1719,3 @@ }

mailparser.end();
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, ">From test\n>>From pest");

@@ -1640,8 +1726,8 @@ test.done();

"Unescape '>From '": function(test){
var encodedText = "From MAILER-DAEMON Fri Jul 8 12:08:34 2011\r\n"+
"Content-Type: text/plain; charset=utf-8\r\n" +
"\r\n" +
">From test\r\n" +
">>From pest", // \r\nÕÄÖÜ
"Unescape '>From '": function(test) {
var encodedText = "From MAILER-DAEMON Fri Jul 8 12:08:34 2011\r\n" +
"Content-Type: text/plain; charset=utf-8\r\n" +
"\r\n" +
">From test\r\n" +
">>From pest", // \r\nÕÄÖÜ
mail = new Buffer(encodedText, "utf-8");

@@ -1652,3 +1738,3 @@

for(var i=0, len = mail.length; i<len; i++){
for (var i = 0, len = mail.length; i < len; i++) {
mailparser.write(new Buffer([mail[i]]));

@@ -1658,3 +1744,3 @@ }

mailparser.end();
mailparser.on("end", function(mail){
mailparser.on("end", function(mail) {
test.equal(mail.text, "From test\n>From pest");

@@ -1664,2 +1750,2 @@ test.done();

}
};
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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