Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.
Merged

Devel #301

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions src/lib/mail.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,17 @@ function sendConceptEmail(resource, resourceType, site, user) {
const logo = siteConfig.getLogo();
const hostname = siteConfig.getCmsHostname();
const sitename = siteConfig.getTitle();

let inzendingPath = resourceConceptEmail.inzendingPath;
const inzendingURL = getInzendingURL(inzendingPath, url, resource, resourceType);

let fromAddress = resourceConceptEmail.from || config.email;
if (!fromAddress) return console.error('Email error: fromAddress not provided');
if (fromAddress.match(/^.+<(.+)>$/, '$1')) fromAddress = fromAddress.replace(/^.+<(.+)>$/, '$1');

let idRegex = new RegExp(`\\[\\[(?:${resourceType}|idea)?Id\\]\\]`, 'g');
inzendingPath = inzendingPath && inzendingPath.replace(idRegex, resource.id).replace(/\[\[resourceType\]\]/, resourceType) || "/";
const inzendingURL = url + inzendingPath;
const data = prepareEmailData(user, resource, hostname, sitename, inzendingURL, url, fromAddress, logo);


const template = resourceConceptEmail.template;
const html = prepareHtml(template, data);
const text = convertHtmlToText(html);
Expand All @@ -132,29 +132,29 @@ function sendConceptEmail(resource, resourceType, site, user) {
// send email to user that submitted a resource
function sendThankYouMail(resource, resourceType, site, user) {
const siteConfig = new MailConfig(site)

if (!resourceType) return console.error('sendThankYouMail error: resourceType not provided');

const url = siteConfig.getCmsUrl();
const hostname = siteConfig.getCmsHostname();
const sitename = siteConfig.getTitle();
let inzendingPath = siteConfig.getFeedbackEmailInzendingPath(resourceType);
const inzendingURL = getInzendingURL(inzendingPath, url, resource, resourceType);

let fromAddress = siteConfig.getFeedbackEmailFrom(resourceType) || config.email;
if (!fromAddress) return console.error('Email error: fromAddress not provided');
if (fromAddress.match(/^.+<(.+)>$/, '$1')) fromAddress = fromAddress.replace(/^.+<(.+)>$/, '$1');

// todo: als je dan toch met een siteConfig.get werkt, moet deze search-and-replace dan niet ook daar?
let idRegex = new RegExp(`\\[\\[(?:${resourceType}|idea)?Id\\]\\]`, 'g'); // 'idea' wegens backward compatible
const inzendingPath = (siteConfig.getFeedbackEmailInzendingPath(resourceType) && siteConfig.getFeedbackEmailInzendingPath(resourceType).replace(idRegex, resource.id).replace(/\[\[resourceType\]\]/, resourceType)) || "/";
const inzendingURL = url + inzendingPath;
const logo = siteConfig.getLogo();

const logo = siteConfig.getLogo();
const data = prepareEmailData(user, resource, hostname, sitename, inzendingURL, url, fromAddress, logo);

let template = siteConfig.getResourceFeedbackEmailTemplate(resourceType);
const html = prepareHtml(template, data);
const text = convertHtmlToText(html);
const attachments = siteConfig.getResourceFeedbackEmailAttachments(resourceType) || siteConfig.getDefaultEmailAttachments();


try {
sendMail(site, {
// in some cases the resource, like order or account has a different email from the submitted user, default to resource, otherwise send to owner of resource
Expand Down Expand Up @@ -321,6 +321,16 @@ function sendInactiveWarningEmail(site, user) {

}

function getInzendingURL(inzendingPath, url, resource, resourceType) {
let idRegex = new RegExp(`\\{(?:${resourceType}|idea)?Id\\}`, 'g');
let oldIdRegex = new RegExp(`\\[\\[(?:${resourceType}|idea)?Id\\]\\]`, 'g');

inzendingPath = inzendingPath && inzendingPath
.replace(idRegex, resource.id)
.replace(oldIdRegex, resource.id)
.replace(/\[\[resourceType\]\]/, resourceType) || "/";
return url + inzendingPath;
}

module.exports = {
sendMail,
Expand Down