Bugfixing.
This commit is contained in:
parent
86efa11994
commit
5670d21e76
31 changed files with 241 additions and 216 deletions
|
@ -27,9 +27,9 @@ class CampaignSender {
|
|||
}
|
||||
|
||||
async init(settings) {
|
||||
this.listsById = Map(); // listId -> list
|
||||
this.listsByCid = Map(); // listCid -> list
|
||||
this.listsFieldsGrouped = Map(); // listId -> fieldsGrouped
|
||||
this.listsById = new Map(); // listId -> list
|
||||
this.listsByCid = new Map(); // listCid -> list
|
||||
this.listsFieldsGrouped = new Map(); // listId -> fieldsGrouped
|
||||
this.attachments = [];
|
||||
|
||||
await knex.transaction(async tx => {
|
||||
|
@ -39,13 +39,15 @@ class CampaignSender {
|
|||
this.campaign = await campaigns.rawGetByTx(tx, 'id', settings.campaignId);
|
||||
}
|
||||
|
||||
this.sendConfiguration = await sendConfigurations.getByIdTx(tx, contextHelpers.getAdminContext(), campaign.send_configuration);
|
||||
const campaign = this.campaign;
|
||||
|
||||
this.sendConfiguration = await sendConfigurations.getByIdTx(tx, contextHelpers.getAdminContext(), campaign.send_configuration, false, true);
|
||||
|
||||
for (const listSpec of campaign.lists) {
|
||||
const list = await lists.getByIdTx(tx, contextHelpers.getAdminContext(), listSpec.list);
|
||||
this.listsById.set(list.id) = list;
|
||||
this.listsByCid.set(list.cid) = list;
|
||||
this.listsFieldsGrouped.set(list.id) = await fields.listGroupedTx(tx, list.id);
|
||||
this.listsById.set(list.id, list);
|
||||
this.listsByCid.set(list.cid, list);
|
||||
this.listsFieldsGrouped.set(list.id, await fields.listGroupedTx(tx, list.id));
|
||||
}
|
||||
|
||||
if (campaign.source === CampaignSource.TEMPLATE) {
|
||||
|
@ -63,7 +65,7 @@ class CampaignSender {
|
|||
});
|
||||
|
||||
this.useVerp = config.verp.enabled && sendConfiguration.verp_hostname;
|
||||
this.useVerpSenderHeader = useVerp && config.verp.disablesenderheader !== true;
|
||||
this.useVerpSenderHeader = this.useVerp && config.verp.disablesenderheader !== true;
|
||||
}
|
||||
|
||||
async _getMessage(campaign, list, subscriptionGrouped, mergeTags, replaceDataImgs) {
|
||||
|
@ -118,9 +120,9 @@ class CampaignSender {
|
|||
});
|
||||
}
|
||||
|
||||
const html = renderTags ? tools.formatMessage(campaign, list, subscriptionGrouped, mergeTags, html, false, true) : html;
|
||||
html = renderTags ? tools.formatMessage(campaign, list, subscriptionGrouped, mergeTags, html, false, true) : html;
|
||||
|
||||
const text = (text || '').trim()
|
||||
text = (text || '').trim()
|
||||
? (renderTags ? tools.formatMessage(campaign, list, subscriptionGrouped, mergeTags, text) : text)
|
||||
: htmlToText.fromString(html, {wordwrap: 130});
|
||||
|
||||
|
@ -136,7 +138,7 @@ class CampaignSender {
|
|||
const subscriptionGrouped = await subscriptions.getByCid(contextHelpers.getAdminContext(), list.id, subscriptionCid);
|
||||
const flds = this.listsFieldsGrouped.get(list.id);
|
||||
const campaign = this.campaign;
|
||||
const mergeTags = fields.forHbsWithFieldsGrouped(flds, subscriptionGrouped);
|
||||
const mergeTags = fields.getMergeTags(flds, subscriptionGrouped);
|
||||
|
||||
return await this._getMessage(campaign, list, subscriptionGrouped, mergeTags, false);
|
||||
}
|
||||
|
@ -150,7 +152,7 @@ class CampaignSender {
|
|||
const subscriptionGrouped = await subscriptions.getByEmail(contextHelpers.getAdminContext(), list.id, email);
|
||||
const flds = this.listsFieldsGrouped.get(listId);
|
||||
const campaign = this.campaign;
|
||||
const mergeTags = fields.forHbsWithFieldsGrouped(flds, subscriptionGrouped);
|
||||
const mergeTags = fields.getMergeTags(flds, subscriptionGrouped);
|
||||
|
||||
const encryptionKeys = [];
|
||||
for (const fld of flds) {
|
||||
|
|
12
lib/tools.js
12
lib/tools.js
|
@ -108,16 +108,16 @@ function validateEmailGetMessage(result, address) {
|
|||
function formatMessage(campaign, list, subscription, mergeTags, message, filter, isHTML) {
|
||||
filter = typeof filter === 'function' ? filter : (str => str);
|
||||
|
||||
let links = getMessageLinks(campaign, list, subscription);
|
||||
const links = getMessageLinks(campaign, list, subscription);
|
||||
|
||||
let getValue = key => {
|
||||
const getValue = key => {
|
||||
key = (key || '').toString().toUpperCase().trim();
|
||||
if (links.hasOwnProperty(key)) {
|
||||
return links[key];
|
||||
}
|
||||
if (mergeTags.hasOwnProperty(key)) {
|
||||
let value = (mergeTags[key] || '').toString();
|
||||
let containsHTML = /<[a-z][\s\S]*>/.test(value);
|
||||
const value = (mergeTags[key] || '').toString();
|
||||
const containsHTML = /<[a-z][\s\S]*>/.test(value);
|
||||
return isHTML ? he.encode((containsHTML ? value : value.replace(/(?:\r\n|\r|\n)/g, '<br/>')), {
|
||||
useNamedReferences: true,
|
||||
allowUnsafeSymbols: true
|
||||
|
@ -127,7 +127,6 @@ function formatMessage(campaign, list, subscription, mergeTags, message, filter,
|
|||
};
|
||||
|
||||
return message.replace(/\[([a-z0-9_]+)(?:\/([^\]]+))?\]/ig, (match, identifier, fallback) => {
|
||||
identifier = identifier.toUpperCase();
|
||||
let value = getValue(identifier);
|
||||
if (value === false) {
|
||||
return match;
|
||||
|
@ -189,6 +188,7 @@ module.exports = {
|
|||
mergeTemplateIntoLayout,
|
||||
getTemplate,
|
||||
prepareHtml,
|
||||
getMessageLinks
|
||||
getMessageLinks,
|
||||
formatMessage
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue