Skip to content

Commit

Permalink
basic skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
killmenot committed May 2, 2016
1 parent d0beffd commit da8e3fa
Show file tree
Hide file tree
Showing 11 changed files with 615 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@ node_modules

# Optional REPL history
.node_repl_history

# Sublime Text
*.sublime-project
*.sublime-workspace

# Mac OS X
.DS_Store

18 changes: 18 additions & 0 deletions .jshintrc
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
}
20 changes: 20 additions & 0 deletions .travis.yml
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
21 changes: 21 additions & 0 deletions Gruntfile.js
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']);
};
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./lib/postmark-transport');
63 changes: 63 additions & 0 deletions lib/postmark-transport.js
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);
};
53 changes: 53 additions & 0 deletions lib/utils.js
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
};
39 changes: 39 additions & 0 deletions package.json
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"
}
}
Loading

0 comments on commit da8e3fa

Please sign in to comment.