Update Nodemailer to v4

also filter out .jst files from email template dropdowns
This commit is contained in:
Peter Jaszkowiak
2017-08-30 14:26:41 -06:00
parent e8aa8c62f6
commit 23e7222dfa
6 changed files with 139 additions and 73 deletions

View File

@@ -1,9 +1,13 @@
'use strict';
var async = require('async');
var nconf = require('nconf');
var fs = require('fs');
var path = require('path');
var meta = require('../../meta');
var file = require('../../file');
var emailer = require('../../emailer');
var settingsController = module.exports;
@@ -22,44 +26,54 @@ settingsController.get = function (req, res, next) {
function renderEmail(req, res, next) {
var fs = require('fs');
var path = require('path');
var file = require('../../file');
var emailsPath = path.join(nconf.get('views_dir'), 'emails');
async.waterfall([
function (next) {
file.walk(emailsPath, next);
},
function (emails, next) {
async.map(emails, function (email, next) {
var path = email.replace(emailsPath, '').substr(1).replace('.tpl', '');
async.parallel({
emails: function (cb) {
async.waterfall([
function (next) {
file.walk(emailsPath, next);
},
function (emails, next) {
// exclude .jst files
emails = emails.filter(function (email) {
return !email.endsWith('.jst');
});
async.waterfall([
function (next) {
fs.readFile(email, next);
},
function (original, next) {
var text = meta.config['email:custom:' + path] ? meta.config['email:custom:' + path] : original.toString();
async.map(emails, function (email, next) {
var path = email.replace(emailsPath, '').substr(1).replace('.tpl', '');
next(null, {
path: path,
fullpath: email,
text: text,
original: original.toString(),
});
},
], next);
}, next);
async.waterfall([
function (next) {
fs.readFile(email, next);
},
function (original, next) {
var text = meta.config['email:custom:' + path] ? meta.config['email:custom:' + path] : original.toString();
next(null, {
path: path,
fullpath: email,
text: text,
original: original.toString(),
});
},
], next);
}, next);
},
], cb);
},
function (emails) {
res.render('admin/settings/email', {
emails: emails,
sendable: emails.filter(function (email) {
return email.path.indexOf('_plaintext') === -1 && email.path.indexOf('partials') === -1;
}),
});
},
], next);
services: emailer.listServices,
}, function (err, results) {
if (err) {
return next(err);
}
res.render('admin/settings/email', {
emails: results.emails,
sendable: results.emails.filter(function (email) {
return email.path.indexOf('_plaintext') === -1 && email.path.indexOf('partials') === -1;
}),
services: results.services,
});
});
}