Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const render = (template, data) => {
let text;
data.imageNotSvg = data.collective && data.collective.image && !data.collective.image.endsWith('.svg');
data = merge({}, data);
delete data.config;
data.config = { host: config.host };
// sets paypalEmail for purpose of email templates
if (data.user) {
data.user.paypalEmail = data.user.paypalEmail || data.user.email;
}
if (templates[`${template}.text`]) {
text = templates[`${template}.text`](data);
}
const html = juice(he.decode(templates[template](data)));
// When in development mode, we log the data used to compile the template
// (useful to get login token without sending an email)
debugLib('data')(`Rendering ${template} with data`, data);
return { text, html };
};
send(email, callback) {
// template data
let html = templates[email.template](email.data)
// inline styles
html = juice(html)
// determine if the main is from a specific sender
// or the generic email address
let user = (email && email.from) ? email.from : config.notifications.email.user
let from = user + '@' + config.notifications.email.url
// configure mail options
var mailOptions = {
from: from,
to: email.to,
subject: email.subject,
html: html,
}
// send email
transporter.sendMail(mailOptions, callback)
send(email, callback) {
// template data
let html = templates[email.template](email.data)
// inline styles
html = juice(html)
// configure mail options
var mailOptions = {
from: config.notifications.email.user,
to: email.to,
subject: email.subject,
html: html,
}
// send email
transporter.sendMail(mailOptions, callback)
},
}
renderBody(mailData) {
const { isCollapsed } = this.state;
if (isCollapsed) {
return null;
}
// all style inlined
const mailContent = juice(mailData.body || '');
const innerHTML = { __html: this.cleanHtml(mailContent) };
return (
<>
<content>
{this.renderReplyButton()}
{this.renderAttachments(mailData)}
);
}
</content>
export default (handlebarsMarkup, context, options) => {
if (handlebarsMarkup && context) {
const template = handlebars.compile(handlebarsMarkup);
const content = template(context);
const {
productName, twitterUsername, facebookUsername, productAddress,
} = Meteor.settings.public;
if (options && options.noBaseTemplate) {
// Use juice to inline CSS <style></style> styles from unless disabled.
return options && !options.inlineCss ? content : juice(content);
}
const base = handlebars.compile(getPrivateFile('email-templates/base.html'));
const baseContext = {
...context,
content,
productName,
twitterUsername,
facebookUsername,
productAddress,
};
return options && !options.inlineCss ? base(baseContext) : juice(base(baseContext));
}
renderDetails(mailData) {
const [from] = mailData.from || [{}];
const { body = '' } = mailData;
return (
<details>
<strong>{from.email || ''}</strong>
{this.renderAddress('To:', mailData.to, juice(body))}
{this.renderAddress('Cc:', mailData.cc, juice(body))}
{this.renderAddress('Bcc:', mailData.bcc, juice(body))}
</details>
);
}
getHtml() {
let contents;
if (this.props.sourceType === CodeEditorSourceType.MJML) {
try {
const res = mjml2html(this.state.source);
contents = res.html;
} catch (err) {
contents = '';
}
} else if (this.props.sourceType === CodeEditorSourceType.HTML) {
contents = juice(this.state.source);
}
return contents;
}
return new Promise((resolve) => {
const inlinedBody = juice(campaign.body);
resolve(omitEmpty({
userId: campaign.userId,
userPlan: this.userPlan,
appendFooter: this.appendFooter,
currentUserState: this.currentState,
campaign: {
id: campaign.id,
subject: campaign.subject,
name: campaign.name,
body: inlinedBody,
senderId: campaign.senderId,
precompiled: false,
listIds: campaign.listIds,
segmentId: campaign.segmentId,
attachments: campaign.attachments,
metadata: campaignMetadata,
export default async function generate(identifier, bindings) {
const page = await Page.findOne({identifier}).lean()
if (!page || page.disabled) return
let attachments = []
const body = transformBody(page.body, bindings, attachments)
const subject = transformSubject(page.subject, bindings)
const text = transformText(body)
const html = template.replace(/\{content\}/, body)
.replace(/\{subject\}/g, subject)
return {
html: juice(html),
text,
subject,
attachments: uniq(attachments)
}
}