mailcomposer
Advanced tools
Comparing version 0.1.34 to 0.2.0
@@ -20,3 +20,3 @@ var crypto = require("crypto"), | ||
* @param {Object} options DKIM options | ||
* @param {String} [options.headerFieldNames="from:to:cc:subject"] Header fields to sign | ||
* @param {String} [options.headerFieldNames="from:to:cc:subject"] Header fields to sign | ||
* @param {String} options.privateKey DKMI private key | ||
@@ -29,8 +29,8 @@ * @param {String} options.domainName Domain name to use for signing (ie: "domain.com") | ||
function DKIMSign(email, options){ | ||
options = options || {}; | ||
options = options || {}; | ||
email = (email || "").toString("utf-8"); | ||
var match = email.match(/^\r?\n|(?:\r?\n){2}/), | ||
headers = match && email.substr(0, match.index) || "", | ||
body = match && email.substr(match.index + match[0].length) || email; | ||
headers = match && email.substr(0, match.index) || "", | ||
body = match && email.substr(match.index + match[0].length) || email; | ||
@@ -142,3 +142,3 @@ // all listed fields from RFC4871 #5.5 | ||
relaxedHeaders: function(headers, fieldNames){ | ||
var includedFields = (fieldNames || "").toLowerCase(). | ||
var includedFields = (fieldNames || "").toLowerCase(). | ||
split(":"). | ||
@@ -145,0 +145,0 @@ map(function(field){ |
@@ -43,3 +43,3 @@ var Stream = require("stream").Stream, | ||
this.options.charset = (this.options.charset || "utf-8").toString().trim().toLowerCase(); | ||
this.options.identityString = (this.options.identityString || "mailcomposer").toString().trim().replace(/\s/g,"-"); | ||
this.options.identityString = (this.options.identityString || "mailcomposer").toString().trim().replace(/\s/g,"-"); | ||
@@ -124,4 +124,5 @@ this._init(); | ||
* @param {String} value Header value | ||
* @param {Boolean} [formatted] If set to true, the value is not modified and passed to output as is | ||
*/ | ||
MailComposer.prototype.addHeader = function(key, value){ | ||
MailComposer.prototype.addHeader = function(key, value, formatted){ | ||
key = this._normalizeKey(key); | ||
@@ -139,2 +140,9 @@ | ||
if(formatted){ | ||
value = { | ||
formatted: !!formatted, | ||
value: value | ||
}; | ||
} | ||
if(!(key in this._headers)){ | ||
@@ -356,3 +364,3 @@ this._headers[key] = value; | ||
this.on("data", function(chunk){ | ||
body += (chunk || "").toString(); | ||
body += (chunk || "").toString(); | ||
}); | ||
@@ -528,5 +536,12 @@ | ||
key = this._normalizeKey(key); | ||
value = this._headers[key] || ""; | ||
return value; | ||
value = [].concat(this._headers[key] || []).map(function(val){ | ||
return val && val.value || val; | ||
}); | ||
switch(value.length){ | ||
case 0: return ""; | ||
case 1: return value[0]; | ||
default: return value; | ||
} | ||
}; | ||
@@ -593,4 +608,4 @@ | ||
if([].concat(this._message.body || []).concat(this._message.html || []). | ||
concat(this._alternatives || []).length > 1){ | ||
if([].concat(this._message.body || []).concat(this._message.html || []). | ||
concat(this._alternatives || []).length > 1){ | ||
this._message.useAlternative = true; | ||
@@ -883,5 +898,4 @@ this._message.alternativeBoundary = this._generateBoundary(); | ||
contentType = alternative.contentType.split(";").map(function(part){ | ||
return (part || "").trim() | ||
}), | ||
fileName; | ||
return (part || "").trim(); | ||
}); | ||
@@ -931,4 +945,16 @@ node.contentEncoding = alternative.contentEncoding || "base64"; | ||
var key = this._normalizeKey(field.key || field[0]), | ||
value = this._sanitizeHeaderValue(field.value || field[1]); | ||
return mimelib.foldLine(key+": "+value, 76, false, false, 52); | ||
value = field.value || field[1]; | ||
if(typeof value == "string"){ | ||
value = { | ||
formatted: false, | ||
value: value | ||
}; | ||
} | ||
if(value.formatted){ | ||
return key + ": " +value.value; | ||
} | ||
return mimelib.foldLine(key + ": " + this._sanitizeHeaderValue(value.value), 76, false, false, 52); | ||
}).bind(this)); | ||
@@ -941,3 +967,14 @@ }else{ | ||
headersArr = headersArr.concat([].concat(headers[key]).map((function(field){ | ||
return mimelib.foldLine(key+": "+this._sanitizeHeaderValue(field), 76, false, false, 52); | ||
if(typeof field == "string"){ | ||
field = { | ||
formatted: false, | ||
value: field | ||
}; | ||
} | ||
if(field.formatted){ | ||
return key + ": " + field.value; | ||
} | ||
return mimelib.foldLine(key + ": " + this._sanitizeHeaderValue(field.value), 76, false, false, 52); | ||
}).bind(this))); | ||
@@ -961,3 +998,3 @@ } | ||
return value; | ||
} | ||
}; | ||
@@ -1227,3 +1264,3 @@ /** | ||
stream.on("end", (function(chunk){ | ||
stream.on("end", (function(){ | ||
var data; | ||
@@ -1388,6 +1425,6 @@ | ||
var cid; | ||
url = (url || "").trim(); | ||
prefix = prefix || ""; | ||
url = (url || "").trim(); | ||
prefix = prefix || ""; | ||
if(url.match(/^https?:\/\//i) || url.match(/^\//i)){ | ||
if(url.match(/^https?:\/\//i) || url.match(/^\//i)){ | ||
cid = crypto.randomBytes(20).toString("hex") + "@" + this.options.identityString; | ||
@@ -1404,2 +1441,2 @@ this.addAttachment({ | ||
}).bind(this)); | ||
} | ||
}; |
@@ -327,4 +327,4 @@ //Javascript Punycode converter derived from example in RFC3492. | ||
var domainParts = domain.split(/\./).map(punycode.ToASCII); | ||
return (start || "") + domainParts.join("."); | ||
return (start || "") + domainParts.join("."); | ||
}); | ||
}; |
@@ -22,3 +22,3 @@ var http = require("http"), | ||
function openUrlStream(url, options){ | ||
options = options || {}; | ||
options = options || {}; | ||
var urlparts = urllib.parse(url), | ||
@@ -28,6 +28,6 @@ urloptions = { | ||
port: urlparts.port || (urlparts.protocol=="https:"?443:80), | ||
path: urlparts.path || urlparts.pathname, | ||
path: urlparts.path || urlparts.pathname, | ||
method: "GET", | ||
headers: { | ||
"User-Agent": options.userAgent || "mailcomposer" | ||
"User-Agent": options.userAgent || "mailcomposer" | ||
}, | ||
@@ -47,3 +47,3 @@ agent: false | ||
request = client.request(urloptions, function(response) { | ||
if((response.statusCode || 0).toString().charAt(0) != "2"){ | ||
if((response.statusCode || 0).toString().charAt(0) != "2"){ | ||
stream.emit("error", "Invalid status code " + (response.statusCode || 0)); | ||
@@ -50,0 +50,0 @@ return; |
{ | ||
"name": "mailcomposer", | ||
"description": "Compose E-Mail messages", | ||
"version": "0.1.34", | ||
"version": "0.2.0", | ||
"author" : "Andris Reinman", | ||
@@ -6,0 +6,0 @@ "maintainers":[ |
@@ -100,3 +100,3 @@ # mailcomposer | ||
Headers can be added with `mailcomposer.addHeader(key, value)` | ||
Headers can be added with `mailcomposer.addHeader(key, value[, formatted])` where `formatted` indicates if the value should be kept as is. If the value is missing or falsy, header value is sanitized and folded. If true, the value is passed to output as is. | ||
@@ -103,0 +103,0 @@ var mailcomposer = new MailComposer(); |
@@ -48,2 +48,16 @@ var testCase = require('nodeunit').testCase, | ||
"Add formatted header": function(test){ | ||
var mc = new MailComposer(); | ||
mc.addHeader("test-key", "first", true); | ||
test.deepEqual(mc._headers["Test-Key"], {value: "first", formatted: true}); | ||
mc.addHeader("test-key", "second", true); | ||
test.deepEqual(mc._headers["Test-Key"], [{value: "first", formatted: true}, {value: "second", formatted: true}]); | ||
mc.addHeader("test-key", "third"); | ||
test.deepEqual(mc._headers["Test-Key"], [{value: "first", formatted: true}, {value: "second", formatted: true},"third"]); | ||
test.done(); | ||
}, | ||
"Get header": function(test){ | ||
@@ -60,2 +74,13 @@ var mc = new MailComposer(); | ||
"Get formatted header": function(test){ | ||
var mc = new MailComposer(); | ||
mc.addHeader("test-key", "first", true); | ||
test.equal(mc._getHeader("test-key"), "first"); | ||
mc.addHeader("test-key", "second"); | ||
test.deepEqual(mc._getHeader("test-key"), ["first", "second"]); | ||
test.done(); | ||
}, | ||
"Uppercase header keys": function(test){ | ||
@@ -62,0 +87,0 @@ var mc = new MailComposer(); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
187260
2861