forked from killmenot/nodemailer-postmark-transport
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
615 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
|
||
[*.{js,json}] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"node": true, | ||
"bitwise": true, | ||
"camelcase": true, | ||
"curly": true, | ||
"forin": true, | ||
"immed": true, | ||
"latedef": true, | ||
"newcap": true, | ||
"noarg": true, | ||
"noempty": true, | ||
"nonew": true, | ||
"quotmark": "single", | ||
"undef": true, | ||
"unused": true, | ||
"trailing": true, | ||
"laxcomma": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
sudo: false | ||
language: node_js | ||
branches: | ||
except: | ||
- gh-pages | ||
node_js: | ||
- '5' | ||
- '5.1' | ||
- '4' | ||
- '4.2' | ||
- '4.1' | ||
- '4.0' | ||
- '0.12' | ||
- '0.11' | ||
- '0.10' | ||
- '0.8' | ||
- '0.6' | ||
- 'iojs' | ||
before_script: | ||
- npm install grunt-cli -g |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module.exports = function (grunt) { | ||
require('load-grunt-tasks')(grunt); | ||
|
||
grunt.initConfig({ | ||
jshint: { | ||
files: { | ||
src: [ | ||
'lib/**/*.js', | ||
'test/**/*.js', | ||
'indexjs', | ||
'Gruntfile.js' | ||
] | ||
}, | ||
options: { | ||
jshintrc: '.jshintrc' | ||
} | ||
} | ||
}); | ||
|
||
grunt.registerTask('default', ['jshint']); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./lib/postmark-transport'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
'use strict'; | ||
|
||
var extend = require('extend'), | ||
postmark = require('postmark'), | ||
pkg = require('../package.json'), | ||
addressFormatter = require('./utils').addressFormatter, | ||
addressParser = require('./utils').addressParser, | ||
headersParser = require('./utils').headersParser; | ||
|
||
function PostmarkTransport(options) { | ||
this.name = 'Postmark'; | ||
this.version = pkg.version; | ||
|
||
options = options || {}; | ||
|
||
var auth = options.auth || {}; | ||
this.client = new postmark.Client(auth.apiKey); | ||
} | ||
|
||
PostmarkTransport.prototype.send = function (mail, callback) { | ||
var data = mail.data || {}; | ||
|
||
var fromAddr = addressParser(data.from)[0] || {}; | ||
var toAddrs = addressParser(data.to) || []; | ||
var ccAddrs = addressParser(data.cc) || []; | ||
var bccAddrs = addressParser(data.bcc) || []; | ||
var headers = headersParser(data.headers || []); | ||
var postmarkOptions = data.postmarkOptions || {}; | ||
|
||
var message = extend(true, { | ||
'From': addressFormatter(fromAddr) || '', | ||
'To': toAddrs.map(addressFormatter).join(','), | ||
'Cc': ccAddrs.map(addressFormatter).join(','), | ||
'Bcc': bccAddrs.map(addressFormatter).join(','), | ||
'Subject': data.subject || '', | ||
'TextBody': data.text || '', | ||
'HtmlBody': data.html || '', | ||
'Headers': headers | ||
}, postmarkOptions); | ||
|
||
this.client.sendEmail(message, function (err, res) { | ||
if (err) { return callback(err); } | ||
|
||
var accepted = []; | ||
var rejected = []; | ||
|
||
if (res.ErrorCode === 0) { | ||
accepted.push(res); | ||
} else { | ||
rejected.push(res); | ||
} | ||
|
||
return callback(null, { | ||
messageId: res.MessageID, | ||
accepted: accepted, | ||
rejected: rejected | ||
}); | ||
}); | ||
}; | ||
|
||
module.exports = function (options) { | ||
return new PostmarkTransport(options); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
var util = require('util'), | ||
addressparser = require('addressparser'); | ||
|
||
function addressFormatter(addr) { | ||
if (addr.address && addr.name) { | ||
return util.format('"%s" <%s>', addr.name, addr.address); | ||
} | ||
|
||
return addr.address; | ||
} | ||
|
||
function addressParser(addrs) { | ||
if (!Array.isArray(addrs)) { | ||
addrs = [addrs]; | ||
} | ||
|
||
return addrs | ||
.map(function (addr) { | ||
if (typeof addr === 'object') { | ||
return [addr]; | ||
} | ||
|
||
return addressparser(addr); | ||
}) | ||
.reduce(function (previous, current) { | ||
return previous.concat(current); | ||
}); | ||
} | ||
|
||
function headersParser(headers) { | ||
if (!Array.isArray(headers)) { | ||
headers = Object.keys(headers).map(function (name) { | ||
return { | ||
key: name, | ||
value: headers[name] | ||
}; | ||
}); | ||
} | ||
|
||
return headers | ||
.map(function (header) { | ||
return { | ||
'Name': header.key, | ||
'Value': header.value | ||
}; | ||
}); | ||
} | ||
|
||
module.exports = { | ||
addressFormatter: addressFormatter, | ||
addressParser: addressParser, | ||
headersParser: headersParser | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "nodemailer-postmark-transport", | ||
"version": "1.0.0", | ||
"description": "Postmark transport for Nodemailer", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "grunt && mocha" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "[email protected]:killmenot/nodemailer-postmark-transport.git" | ||
}, | ||
"keywords": [ | ||
"nodemailer", | ||
"postmark" | ||
], | ||
"author": { | ||
"name": "Alexey Kucherenko", | ||
"url": "https://github.com/killmenot" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/killmenot/nodemailer-postmark-transport/issues" | ||
}, | ||
"homepage": "https://github.com/RebelMail/nodemailer-postmark-transport", | ||
"dependencies": { | ||
"addressparser": "^1.0.1", | ||
"extend": "^3.0.0", | ||
"postmark": "^1.2.1" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"grunt": "^1.0.1", | ||
"grunt-contrib-jshint": "^1.0.0", | ||
"load-grunt-tasks": "^3.5.0", | ||
"mocha": "^2.4.5", | ||
"sinon": "^1.17.3" | ||
} | ||
} |
Oops, something went wrong.