Skip to content

Commit

Permalink
fix: fixed v5 vs v6 breaking issue with subject line not allowing ove…
Browse files Browse the repository at this point in the history
…rride from message object
  • Loading branch information
niftylettuce committed Dec 19, 2019
1 parent 397a71c commit f6c3826
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,24 +221,28 @@ class Email {
return html;
}

// eslint-disable-next-line complexity
async renderAll(template, locals = {}, nodemailerMessage = {}) {
const message = { ...nodemailerMessage };

if (template) {
if (template && (!message.subject || !message.html || !message.text)) {
const [subject, html, text] = await Promise.all(
['subject', 'html', 'text'].map(type =>
this.checkAndRender(type, template, locals)
)
);

if (subject) message.subject = subject.trim();
if (html) message.html = html;
if (text) message.text = text;
if (subject && !message.subject) message.subject = subject;
if (html && !message.html) message.html = html;
if (text && !message.text) message.text = text;
}

if (message.subject && this.config.subjectPrefix)
message.subject = this.config.subjectPrefix + message.subject;

// trim subject
if (message.subject) message.subject = message.subject.trim();

if (this.config.htmlToText && message.html && !message.text)
// we'd use nodemailer-html-to-text plugin
// but we really don't need to support cid
Expand Down

0 comments on commit f6c3826

Please sign in to comment.