nodemailer-mailgun-transport
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -5,3 +5,3 @@ { | ||
"description": "A transport module to use with nodemailer to leverage Mailgun's REST API", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"repository": { | ||
@@ -11,2 +11,5 @@ "type": "git", | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"keywords": [ | ||
@@ -35,4 +38,14 @@ "email", | ||
"dependencies": { | ||
"lodash.pickby": "^4.3.0", | ||
"lodash.some": "^4.3.0", | ||
"lodash.startswith": "^4.0.1", | ||
"mailgun-js": "0.7.10" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"mocha": "^2.4.5", | ||
"mocha-sinon": "^1.1.5", | ||
"sinon": "^1.17.4", | ||
"sinon-chai": "^2.8.0" | ||
} | ||
} |
@@ -5,3 +5,31 @@ 'use strict'; | ||
var packageData = require('../package.json'); | ||
var pickBy = require('lodash.pickby'); | ||
var some = require('lodash.some'); | ||
var startsWith = require('lodash.startswith'); | ||
var whitelistExact = [ | ||
'from', | ||
'to', | ||
'cc', | ||
'bcc', | ||
'subject', | ||
'text', | ||
'html', | ||
'attachment', | ||
'o:tag', | ||
'o:campaign', | ||
'o:dkim', | ||
'o:deliverytime', | ||
'o:testmode', | ||
'o:tracking', | ||
'o:tracking-clicks', | ||
'o:tracking-opens', | ||
'o:require-tls', | ||
'o:skip-verification' | ||
]; | ||
var whitelistPrefix = [ | ||
'h:', | ||
'v:' | ||
]; | ||
module.exports = function (options) { | ||
@@ -20,2 +48,3 @@ return new MailgunTransport(options); | ||
}); | ||
this.messages = this.mailgun.messages(); | ||
} | ||
@@ -25,40 +54,29 @@ | ||
MailgunTransport.prototype.send = function send(mail, callback) { | ||
var self = this; | ||
var mailData = mail.data; | ||
// convert nodemailer attachments to mailgun-js attachements | ||
if(mailData.attachments){ | ||
var a, b, aa = []; | ||
for(var i in mailData.attachments){ | ||
a = mailData.attachments[i]; | ||
b = new this.mailgun.Attachment({ | ||
data : a.path || undefined, | ||
filename : a.filename || undefined, | ||
contentType : a.contentType || undefined, | ||
knownLength : a.knownLength || undefined | ||
if (mailData.attachments) { | ||
mailData.attachment = mailData.attachments.map(function (a) { | ||
return new self.mailgun.Attachment({ | ||
data: a.path || undefined, | ||
filename: a.filename || undefined, | ||
contentType: a.contentType || undefined, | ||
knownLength: a.knownLength || undefined | ||
}); | ||
}); | ||
} | ||
aa.push(b); | ||
var options = pickBy(mailData, function (value, key) { | ||
if (whitelistExact.indexOf(key) !== -1) { | ||
return true; | ||
} | ||
mailData.attachment = aa; | ||
} | ||
var options = { | ||
type : mailData.type, | ||
to : mailData.to, | ||
from : mailData.from, | ||
subject : mailData.subject, | ||
text : mailData.text, | ||
html : mailData.html, | ||
attachment : mailData.attachment | ||
} | ||
if( mailData.bcc ){ | ||
options.bcc = mailData.bcc | ||
} | ||
return some(whitelistPrefix, function (prefix) { | ||
return startsWith(key, prefix); | ||
}); | ||
}); | ||
this.mailgun.messages().send(options, function (err, data) { | ||
this.messages.send(options, function (err, data) { | ||
callback(err || null, data); | ||
}); | ||
}; | ||
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
10948
8
188
4
5
1
+ Addedlodash.pickby@^4.3.0
+ Addedlodash.some@^4.3.0
+ Addedlodash.startswith@^4.0.1
+ Addedlodash.pickby@4.6.0(transitive)
+ Addedlodash.some@4.6.0(transitive)
+ Addedlodash.startswith@4.2.1(transitive)