From a2ebe8f0f72afe8eede4a92303e48aba4b73892a Mon Sep 17 00:00:00 2001 From: witzig Date: Fri, 16 Jun 2017 02:13:21 +0200 Subject: [PATCH] Fixed mail-helper.js not calling back when disableConfirmations = true And some refactoring --- lib/subscription-mail-helpers.js | 40 +++++++++++++++----------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/lib/subscription-mail-helpers.js b/lib/subscription-mail-helpers.js index cfbac97e..16e6cdaa 100644 --- a/lib/subscription-mail-helpers.js +++ b/lib/subscription-mail-helpers.js @@ -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(); }); }); }