Fixed mail-helper.js not calling back when disableConfirmations = true

And some refactoring
This commit is contained in:
witzig 2017-06-16 02:13:21 +02:00
parent 830ca4f17f
commit a2ebe8f0f7

View file

@ -96,7 +96,7 @@ function sendMail(list, email, template, subject, relativeUrls, mailOpts, subscr
}
if (!mailOpts.ignoreDisableConfirmations && configItems.disableConfirmations) {
return;
return callback();
}
const data = {
@ -110,7 +110,22 @@ function sendMail(list, email, template, subject, relativeUrls, mailOpts, subscr
data[relativeUrlKey] = urllib.resolve(configItems.serviceUrl, relativeUrls[relativeUrlKey]);
}
function sendMail(html, text) {
let text = {
template: 'subscription/mail-' + template + '-text.hbs'
};
let html = {
template: 'subscription/mail-' + template + '-html.mjml.hbs',
layout: 'subscription/layout.mjml.hbs',
type: 'mjml'
};
helpers.injectCustomFormTemplates(list.defaultForm, { text, html }, (err, tmpl) => {
if (!err && tmpl) {
text = tmpl.text || text;
html = tmpl.html || html;
}
mailer.sendMail({
from: {
name: configItems.defaultFrom,
@ -129,29 +144,12 @@ function sendMail(list, email, template, subject, relativeUrls, mailOpts, subscr
}, err => {
if (err) {
log.error('Subscription', err);
return callback(err);
}
callback();
});
}
let text = {
template: 'subscription/mail-' + template + '-text.hbs'
};
let html = {
template: 'subscription/mail-' + template + '-html.mjml.hbs',
layout: 'subscription/layout.mjml.hbs',
type: 'mjml'
};
helpers.injectCustomFormTemplates(list.defaultForm, { text, html }, (err, tmpl) => {
if (err) {
return sendMail(html, text);
}
sendMail(tmpl.html, tmpl.text);
});
return callback();
});
});
}