Newer
Older
Martin Groppe
committed
import("JditoFilter_lib");
import("CommunicationBlacklist_lib");
import("EmailFilterHandling_lib");
import("system.logging");
import("system.entities");
Martin Groppe
committed
import("system.fileIO");
import("system.project");
import("system.translate");
import("ActivityTask_lib");
import("system.util");
import("Contact_lib");
import("system.datetime");
import("system.neon");
import("Employee_lib");
import("system.vars");
import("KeywordRegistry_basic");
import("Sql_lib");
import("system.db");
import("DocumentTemplate_lib");
import("Communication_lib");
import("Email_lib");
import("system.process");
import("system.notification");
Martin Groppe
committed
import("system.db");
Martin Groppe
committed
import("system.workflow");
* Functions for bulk mails.
*/
function BulkMailUtils () {}
/**
* Executes a process to send bulk mails on the server and creates a notification when finished.
*
* @param {String} pBulkMailId <p>
* Id of the bulk mail.<br>
Martin Groppe
committed
* @param {Bool} pTestRun (optional) <p>
* True indicates a Testrun<br>
* @param {String} pUser=currentUser (optional) <p>
* User that will get the notification, <br>
* if null (not undefined!), no notification<br>
* will be created.<br>
Martin Groppe
committed
BulkMailUtils.sendBulkMailOnServer = function (pBulkMailId, pTestRun, pUser)
{
if (pUser === undefined)
pUser = EmployeeUtils.getCurrentUserId();
var processConfig = process.createStartAsyncConfig()
.setName("sendBulkMail_serverProcess")
.setLocalVariables({
Martin Groppe
committed
testRun : pTestRun,
Martin Groppe
committed
.setUser(pUser||"mailbridge")
}
/**
* Sends a bulk mail. You should only call this function on the server because it
* can take some time to execute, use BulkMailUtils.sendBulkMailOnServer instead.
*
* @param {String} pBulkMailId <p>
* Id of the bulk mail.<br>
Martin Groppe
committed
* True indicates a Testrun<br>
* @param {Bool} pUser (optional) <p>
* If there are no test recipients or no recipients marked for a test replacement in a test run
* we send an email to this user instead<br>
* @return {Object} <p>
* Count of sucessful and failed mails.<br>
BulkMailUtils.sendBulkMail = function (pBulkMailId, pIsTestRun, pUser)
if (pIsTestRun == undefined)
{
pIsTestRun = false;
}
Martin Groppe
committed
var sendUserTitle = project.getPreferenceValue("custom.bulkmail.user");
var [templateId, subject, emailSender, createActivity, bulkMailName, useTemplateAttachments, mosaicoTemplateId] =
newSelect("DOCUMENTTEMPLATE_ID, SUBJECT, SENDER_EMAIL_ADDRESS, CREATEACTIVITIES, NAME, USE_TEMPLATE_ATTACHMENTS, MOSAICOTEMPLATE_ID")
.from("BULKMAIL")
.where("BULKMAIL.BULKMAILID", pBulkMailId)
.arrayRow();
useTemplateAttachments = Utils.toBoolean(useTemplateAttachments);

Andreas Fräder
committed
var template = BulkMailUtils.getBulkMailTemplate(pBulkMailId, templateId, true, false, useTemplateAttachments, mosaicoTemplateId);
Martin Groppe
committed
var testRecipientData;
var recipientLoadConfig = entities.createConfigForLoadingRows()
.fields(["BULKMAILRECIPIENTID", "CONTACT_ID", "EMAIL_ADDRESS", "PERSON_ID", "ORGANISATION_ID"])
.provider("RecipientsToBeMailed")
.addParameter("BulkMailId_param", pBulkMailId)
.addParameter("IsTestMail_param", pIsTestRun);
recipientData = entities.getRows(recipientLoadConfig);
var blacklist = new CommunicationBlacklist().loadBlacklistRecipients(pBulkMailId);
Martin Groppe
committed
testRecipientData = newSelect("BULKMAILTESTRECIPIENT.CONTACT_ID, BULKMAILTESTRECIPIENT.EMAIL_ADDRESS")
.from("BULKMAILTESTRECIPIENT")
.where("BULKMAILTESTRECIPIENT.BULKMAIL_ID", pBulkMailId)
Martin Groppe
committed
.table();
if (testRecipientData.length == 0 || recipientData.length == 0 && pUser)
{
var userData = tools.getUserByAttribute(tools.NAME,pUser,tools.PROFILE_DEFAULT);
if (userData)
{
testRecipientData = [userData[tools.PARAMS][tools.CONTACTID],userData[tools.PARAMS][tools.EMAIL]];
recipientData = [{"CONTACT_ID":userData[tools.PARAMS][tools.CONTACTID],"EMAIL":userData[tools.PARAMS][tools.EMAIL]}];
}
}
Martin Groppe
committed
var mailrunId = util.getNewUUID();
new SqlBuilder()
.tableName("MAIL_RUN")
.insertFields({
"MAIL_RUNID": mailrunId,
"OBJECT_ROWID": pBulkMailId,
"OBJECT_TYPE": "Bulkmail",
"DATE_RUN_START": vars.get("$sys.date"),
"STATUS": $KeywordRegistry.bulkMailStatus$beingSent(),
"TESTRUN": pIsTestRun ? 1 : 0
});
Martin Groppe
committed
var mailLogIds = new Map();
var contactIds = recipientData.map(function (recipient)
{
var contactId = recipient["CONTACT_ID"];
mailLogIds.set(contactId, util.getNewUUID());
return contactId;
});
Martin Groppe
committed
var baseUrl = project.getInstanceConfigValue("custom.bulkmail.baseReplacementURL", vars.get("$sys.origin")) + "/services/rest/redirect_rest?";
var linkPlaceholders = newSelect(["PLACEHOLDER", "WEBLINKID", "URL", "ISREDIRECT"])
.from("WEBLINK")
.table()
.map(function ([placeholder, weblinkId, url, isRedirect])
{
if (Utils.toBoolean(isRedirect))
{
Martin Groppe
committed
var linkFn = function (pContactId)
{
return baseUrl + "link=" + weblinkId + "&log=" + mailLogIds.get(pContactId);
}
return new Placeholder(placeholder, Placeholder.types.CALLBACKFUNCTION, linkFn);
}
return new Placeholder(placeholder, Placeholder.types.FIXEDVALUE, url);
});
Martin Groppe
committed
Martin Groppe
committed
var webviewFn = function(pContactId)
{
return vars.get("$sys.origin")+"/services/rest/webview_rest?" + "log=" + mailLogIds.get(pContactId);
}
var webviewPlaceholder = new Placeholder("webview", Placeholder.types.CALLBACKFUNCTION, webviewFn);
var additionalPlaceholders = [webviewPlaceholder].concat(linkPlaceholders);
var bouncedSoftIds = [];
var bouncedHardIds = [];
Martin Groppe
committed
var mails = template.getReplacedEmailsByContactIds(contactIds, additionalPlaceholders);
var subjectTemplate = new DocumentTemplate(subject, DocumentTemplate.types.PLAIN);
var subjects = subjectTemplate.getReplacedContentByContactIds(contactIds);
var bulkMailLink = [["BulkMail", pBulkMailId]];
var activitySubject = translate.withArguments("Bulk mail \"%0\" sent", [bulkMailName]);
var emailFilterProcessor = new IncomingEmailFilterProcessor().loadFilters();
if (!pIsTestRun)
{
recipientData.forEach(function (recipient)
{
let isSuccess = false;
Martin Groppe
committed
var errorMessage = "";
let recipientId = recipient["BULKMAILRECIPIENTID"];
let contactId = recipient["CONTACT_ID"];
let emailAddress = recipient["EMAIL_ADDRESS"];
let personId = recipient["PERSON_ID"];
let organisationId = recipient["ORGANISATION_ID"];
let email = mails[contactId];
Martin Groppe
committed
let recipientStatus = $KeywordRegistry.bulkMailRecipientStatus$failed();
if (email !== undefined && emailAddress && !blacklist.hasContactId(contactId))
Martin Groppe
committed
{
Martin Groppe
committed
try
{
email.toRecipients = [emailAddress];
email.sender = emailSender;
email.subject = subjects[contactId];
BulkMailUtils.storeEmlFile(pBulkMailId, mailrunId, mailLogId,email.getEML());
isSuccess = email.send(sendUserTitle);
if (!isSuccess)
{
errorMessage = logging.toLogString(email.getMailError(), true);
var filterType = emailFilterProcessor.processError(errorMessage, contactId, emailAddress);
if (filterType == $KeywordRegistry.emailFilterType$bounceHard())
bouncedStatus = $KeywordRegistry.bulkMailRecipientStatus$hardBounce();
else if (filterType == $KeywordRegistry.emailFilterType$bounceSoft())
bouncedStatus = $KeywordRegistry.bulkMailRecipientStatus$softBounce();
Martin Groppe
committed
recipientStatus = bouncedStatus || $KeywordRegistry.bulkMailRecipientStatus$failed();
}
else
{
recipientStatus = $KeywordRegistry.bulkMailRecipientStatus$sent();
}
}
catch (ex)
Martin Groppe
committed
errorMessage = logging.toLogString(ex, true);
//set the recipient status to 'sent' or 'failed'
new SqlBuilder()
.tableName("MAIL_LOG")
.insertFields({
"MAIL_LOGID": mailLogId,
"MAIL_RUN_ID": mailrunId,
"CONTACT_ID": contactId,
Martin Groppe
committed
"ERRORMESSAGE": errorMessage,
"SENDER_EMAIL": emailSender,
"RECIPIENT_EMAIL": emailAddress,
"MAILING_SUBJECT": subjects[contactId],
"DATE_SEND": vars.get("$sys.date")
});
Martin Groppe
committed
//TODO: Klären was von alter Logik noch bleiben soll. Status macht nur Sinn wenn jede Bulkmail nur einmal gesendet wird. Bleiben Activitys?
successIds.push(recipientId);
}
else if (bouncedStatus == $KeywordRegistry.bulkMailRecipientStatus$softBounce())
{
bouncedSoftIds.push(recipientId);
}
else if (bouncedStatus == $KeywordRegistry.bulkMailRecipientStatus$hardBounce())
{
bouncedHardIds.push(recipientId);
}
else
{
failedIds.push(recipientId);
}
if (isSuccess && createActivity == "1")
{
let activityData = {
categoryKeywordId : $KeywordRegistry.activityCategory$mail(),
directionKeywordId : $KeywordRegistry.activityDirection$outgoing(),
subject : activitySubject,
content : email.body
};
let contactLink = [[ContactUtils.getContextByPersOrg(personId, organisationId), contactId]];
ActivityUtils.insertNewActivity(activityData, bulkMailLink.concat(contactLink));
}
});
Martin Groppe
committed
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
var updates = [];
updates = updates.concat(successIds.map(function (sucessId)
{
return newWhere("BULKMAILRECIPIENT.BULKMAILRECIPIENTID",successId)
.buildUpdateStatement({
"STATUS": $KeywordRegistry.bulkMailRecipientStatus$sent(),
"SENTDATE": sentDate
});
}));
updates = updates.concat(failedIds.map(function (failedId)
{
return newWhere("BULKMAILRECIPIENT.BULKMAILRECIPIENTID",failedId)
.buildUpdateStatement({
"STATUS": $KeywordRegistry.bulkMailRecipientStatus$failed(),
"SENTDATE": sentDate
});
}));
updates = updates.concat(bouncedSoftIds.map(function (bouncedSoftId)
{
return newWhere("BULKMAILRECIPIENT.BULKMAILRECIPIENTID",bouncedSoftId)
.buildUpdateStatement({
"STATUS": $KeywordRegistry.bulkMailRecipientStatus$softBounce(),
"SENTDATE": sentDate
});
}));
updates = updates.concat(bouncedHardIds.map(function (bouncedHardId)
{
return newWhere("BULKMAILRECIPIENT.BULKMAILRECIPIENTID",bouncedHardId)
.buildUpdateStatement({
"STATUS": $KeywordRegistry.bulkMailRecipientStatus$hardBounce(),
"SENTDATE": sentDate
});
}));
db.updates(updates);
newWhere("MAIL_RUN.MAIL_RUNID", mailrunId)
.updateFields({
"STATUS": $KeywordRegistry.bulkMailStatus$sent(),
"DATE_RUN_FINISHED": vars.get("$sys.date")
});
newWhere("BULKMAIL.BULKMAILID", pBulkMailId)
.updateFields({
"STATUS": $KeywordRegistry.bulkMailStatus$sent()
});
}
else
{
for (let i = 0, l = recipientData.length; i < l; i++)
{
let isSuccess = false;
Martin Groppe
committed
let errorMessage = "";
let contactId = recipientData[i]["CONTACT_ID"];
Martin Groppe
committed
let currentMailLogId = mailLogIds.get(contactId);
if (email !== undefined)
{
email.sender = emailSender;
email.subject = "Test: "+subjects[contactId];
for (let j =0; j<testRecipientData.length;j++)
{
if(testRecipientData[j][1])
{
Martin Groppe
committed
let nextMailLogId = util.getNewUUID();
Martin Groppe
committed
try
{
email.toRecipients = [testRecipientData[j][1]];
email.body = StringUtils.replaceAll(email.body,currentMailLogId,nextMailLogId);
currentMailLogId = nextMailLogId;
this.storeEmlFile(pBulkMailId, mailrunId, nextMailLogId,email.getEML());
isSuccess = email.send(sendUserTitle);
}
catch(ex)
{
errorMessage = logging.toLogString(ex, true);
}
Array.prototype.push.call(isSuccess ? successIds : failedIds, recipientData[i]["BULKMAILRECIPIENTID"]);
Martin Groppe
committed
new SqlBuilder()
.tableName("MAIL_LOG")
.insertFields({
"MAIL_LOGID":nextMailLogId,
"MAIL_RUN_ID":mailrunId,
"CONTACT_ID":testRecipientData[j][0],
Martin Groppe
committed
"ERRORMESSAGE": errorMessage || logging.toLogString(email.getMailError(), true) || "",
Martin Groppe
committed
"STATUS":(isSuccess ?$KeywordRegistry.bulkMailRecipientStatus$sent(): $KeywordRegistry.bulkMailRecipientStatus$failed()),
"SENDER_EMAIL":emailSender,
"RECIPIENT_EMAIL":testRecipientData[j][1],
"MAILING_SUBJECT":email.subject,
"DATE_SEND":vars.get("$sys.date")
Martin Groppe
committed
});
Martin Groppe
committed
}
}
Martin Groppe
committed
}
newWhere("MAIL_RUN.MAIL_RUNID",mailrunId)
.updateData(true,"MAIL_RUN",["STATUS","DATE_RUN_FINISHED"],null,[$KeywordRegistry.bulkMailStatus$sent(),vars.get("$sys.date")]);
}
return {
sucessful : successIds.length,
failed : failedIds.length
};
}
/**
* Opens a context to select a bulk mail to add recipients to.<br>
* @param {String} pContext the context of the contacts (Person or Organisation)
Martin Groppe
committed
* @param {String[]} pIds Ids that should be added.<br>
* @param {String|Object} pFilter the filter for the contacts that should be used if no Ids are selected
* @param {String|Object} pParameters the relevant parameters that are needed to get the Ids from entities.loadrows in the form:{parametername:parametervalue}
Martin Groppe
committed
BulkMailUtils.openAddRecipientView = function (pContext, pIds, pFilter, pParameters)
Martin Groppe
committed
if (!Utils.isString(pParameters))
pParameters = JSON.stringify(pParameters);
if (!Utils.isString(pIds))
pIds = JSON.stringify(pIds);
if (Utils.isString(pFilter))
pFilter = JSON.parse(pFilter);
Martin Groppe
committed
if(Utils.isNullOrEmpty(pFilter.filter))
pFilter.filter= JSON.parse(JditoFilterUtils.getEmptyFilter()).filter;
pFilter= JSON.stringify(pFilter);
neon.openContext("BulkMailAddRecipients", "BulkMailAddRecipientsEdit_view", null, neon.OPERATINGSTATE_VIEW, {
"ObjectType_param": pContext,
Martin Groppe
committed
"Ids_param": pIds,
"Filter_param": pFilter,
"Parameters_param": pParameters
* Deletes all bulk mail recipients that have a commrestriction for emails.<br>
* @param {String} pBulkMailId <p>
* The mail id.<br>
*/
BulkMailUtils.removeCommRestrictionRecipients = function (pBulkMailId)
{
var recipientIds = newSelect("BULKMAILRECIPIENTID")
.join("CONTACT", "BULKMAILRECIPIENT.CONTACT_ID = CONTACT.CONTACTID")
.where("BULKMAILRECIPIENT.BULKMAIL_ID", pBulkMailId)
.and(new CommunicationSettingsCondition()
.emails("BULKMAILRECIPIENT.EMAIL_ADDRESS")
.rejected()
.existSettings()
.buildCondition())
newWhereIfSet("BULKMAILRECIPIENT.BULKMAILRECIPIENTID", recipientIds, SqlBuilder.IN())
* Adds recipients to a bulkmail.<br>
* @param {String} pBulkMailId <p>
* Bulk mail id.<br>
* @param {String[]} pContactIds <p>
* Contact ids of the recipients.<br>
*/
BulkMailUtils.addRecipients = function (pBulkMailId, pContactIds)
{
if (pContactIds.length > 0)

Sebastian Pongratz
committed
var contactData = newSelect(["CONTACTID", "(" + CommUtil.getStandardSubSqlMail(newWhere("COMMUNICATION.OBJECT_ROWID = CONTACTID").and("COMMUNICATION.OBJECT_TYPE", "Contact")) + ")"])
.from("CONTACT")
.where("CONTACT.CONTACTID", pContactIds, SqlBuilder.IN())
.table();
var sqlBuilder = new SqlBuilder();
var inserts = contactData.map(function([contactId, standardMail])
return sqlBuilder.buildInsertStatement({
"BULKMAIL_ID": pBulkMailId,
"CONTACT_ID": contactId,

Andreas Fräder
committed
"STATUS": $KeywordRegistry.bulkMailRecipientStatus$added(),
"IS_TEST_RECIPIENT" : 0,
"EMAIL_ADDRESS": standardMail
}, "BULKMAILRECIPIENT", "BULKMAILRECIPIENTID");
});
db.inserts(inserts);
* Loads the document template of a bulk mail. If the bulk mail
* itself has a template, it is preferred over the documentTemplate-id.
* @param {String} pBulkMailId <p>
* The id of the bulk mail.<br>
* @param {String} pDocumentTemplateId <p>
* The id of the document template.<br>
* @param {Boolean} pResolveSubtemplates=true (optional) <p>
* If true subtemplates are resolved (if the type is html)
* @param {Boolean} pUseTemplateAttachments=false <p>
* If true the attachments from the document template is always used
* @param {FileUpload} pUpload (optional) <p>
* The upload value if a custom template is used.<br>
* @param {String} pMosaicoTemplateId (optional) <p>
* The id of the mosaico template.<br>
* @return {DocumentTemplate} <p>
* The document template, null if no content was found.<br>
BulkMailUtils.getBulkMailTemplate = function (pBulkMailId, pDocumentTemplateId, pResolveSubtemplates, pUseTemplateAttachments, pUpload, pMosaicoTemplateId)
if (pUpload && pUpload.isFilled() && BulkMailUtils.isValidMimeType(pUpload.mimeType))
{
return DocumentTemplate.fromUpload(pUpload);
}
var bulkTemplate = DocumentTemplate.loadTemplate(pBulkMailId, "BULKMAIL", pResolveSubtemplates);
var documentTemplate = DocumentTemplate.loadTemplate(pDocumentTemplateId, undefined, pResolveSubtemplates);
var mosaicoTemplate = DocumentTemplate.loadTemplate(pMosaicoTemplateId, "MOSAICOTEMPLATE", pResolveSubtemplates);
if (pMosaicoTemplateId)
{
return mosaicoTemplate;
}
else
{
return documentTemplate;
}
if (pUseTemplateAttachments)
{
bulkTemplate.setAttachments(documentTemplate.getAttachments());
}
* Checks if a contact is a recipient of a bulk mail.<br>
* @param {String} pBulkMailId <p>
* The id of the bulk mail.<br>
* @param {String} pContactId <p>
* The contact id.<br>
* @param {String} pRecipientId <p>
* The contact id of the contact where,<br>
* the bulk mail shall sent to.<br>
* @return {boolean} <p>
* True, if the contact is a recipient.<br>
*/
BulkMailUtils.isRecipient = function (pBulkMailId, pContactId, pRecipientId)
{
return newSelect("count(*)")
.from("BULKMAILRECIPIENT")
.where("BULKMAILRECIPIENT.CONTACT_ID", pContactId)
.and("BULKMAILRECIPIENT.BULKMAIL_ID", pBulkMailId)
.andIfSet("BULKMAILRECIPIENT.BULKMAILRECIPIENTID", pRecipientId, SqlBuilder.NOT_EQUAL())
.cell() != "0"; //TODO: is there a way exists could be used?
* Opens the BulkMail context in new mode.<br>
* @param {String[]} pRecipients (optional) <p>
* Recipients that should be added after creation.<br>
Martin Groppe
committed
* @param {String} pContext (optional) <p>
* Context the filter is coming from.<br>
* @param {Object} pFilter (optional) <p>
* sys.filter of selection that should be added to new bulkmail<br>
Martin Groppe
committed
BulkMailUtils.newBulkMail = function (pRecipients, pContext, pFilter)
Martin Groppe
committed
"PresetRecipients_param" : pRecipients?JSON.stringify(pRecipients):null,
"PresetRecipientsContext_param": pContext,
"PresetRecipientsFilter_param": pFilter?JSON.stringify(pFilter):null
neon.openContext("BulkMail", "BulkMailEdit_view", null, neon.OPERATINGSTATE_NEW, params);
}
/**
* Filters the given contactIds if they can be added as new recipients.
* Checks if a contact is already a recipient or if there is a advertising ban.
*
* @param {String} pBulkMailId id of the bulk mail the contacts should be added to
* @param {String[]} pContactIds contacts to filter
* @return {String[]} contacts that can be added as recipients
*/
BulkMailUtils.filterNewRecipients = function (pBulkMailId, pContactIds)
{
return newSelect("CONTACTID")
.from("CONTACT")
.whereIfSet("CONTACT.CONTACTID", pContactIds, SqlBuilder.IN())
// only add contacts that aren't already recipients
.and(null, newSelect("BULKMAILRECIPIENTID")
.from("BULKMAILRECIPIENT")
.where("BULKMAILRECIPIENT.CONTACT_ID = CONTACT.CONTACTID")
.and("BULKMAILRECIPIENT.BULKMAIL_ID", pBulkMailId)
, SqlBuilder.NOT_EXISTS())
// check if there's a commrestriction
.and(new CommunicationSettingsCondition()
.emails(CommUtil.getStandardSubSqlMail())
.rejected()
.existNoSettings()
.buildCondition())
Martin Groppe
committed
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
/**
* Filters the given contactIds if they can be added as new recipients.
* Checks if a contact is already a recipient or if there is a advertising ban.
*
* @param {String} pBulkMailId id of the bulk mail the contacts should be added to
* @param {String} pCondition Condition part of sys.filter
* @param {String} pContext Context that belongs to the filtercondition
* @return {String[]} contacts that can be added as recipients
*/
BulkMailUtils.filterNewRecipientsByCondition = function (pBulkMailId, pCondition, pContext)
{
var condition = newSelect("CONTACTID")
.from("CONTACT")
.whereIfSet(pCondition)
// only add contacts that aren't already recipients
.and(null, newSelect("BULKMAILRECIPIENTID")
.from("BULKMAILRECIPIENT")
.where("BULKMAILRECIPIENT.CONTACT_ID = CONTACT.CONTACTID")
.and("BULKMAILRECIPIENT.BULKMAIL_ID", pBulkMailId)
, SqlBuilder.NOT_EXISTS())
// check if there's a commrestriction
.and(new CommunicationSettingsCondition()
.emails(CommUtil.getStandardSubSqlMail())
.rejected()
.existNoSettings()
.buildCondition());
if (pContext == "Person")
{
condition.and("CONTACT.PERSON_ID is not null");
}
if (pContext == "Organistaion")
{
condition.and("CONTACT.PERSON_ID is null");
}
if (pContext == "CampaignParticipant")
{
condition.join("CAMPAIGNPARTICIPANT","CAMPAIGNPARTICIPANT.CONTACT_ID = CONTACT.CONTACTID");
}
if (pContext == "CampaignStep")
{
condition.join("CAMPAIGNPARTICIPANT","CAMPAIGNPARTICIPANT.CONTACT_ID = CONTACT.CONTACTID")
.join("CAMPAIGNSTEP","CAMPAIGNSTEP.CAMPAIGNSTEPID = CAMPAIGNPARTICIPANT.CAMPAIGNSTEP_ID");
}
return condition.arrayColumn();
}
* Opens the given bulk mail.
*
* @param {String} pBulkMailId <p>
* The id of the bulk mail.<br>
*/
BulkMailUtils.openBulkMail = function (pBulkMailId)
{
neon.openContext("BulkMail", "BulkMailMain_view", [pBulkMailId], neon.OPERATINGSTATE_VIEW, null);
* Checks is the given mime type can be used for a bulk mail.<br>
* @param {String} pMimeType <p>
* The mime type.<br>
* @return {Boolean} <p>
* Whether the type is usable or not.<br>
*/
BulkMailUtils.isValidMimeType = function (pMimeType)
{
var templateType = DocumentTemplate.types.fromMimeType(pMimeType);
return BulkMailUtils.isValidTemplateType(templateType)
}
/**
* Checks is the given template type can be used for a bulk mail.<br>
* @param {String} pTemplateType <p>
* Template type.<br>
* @return {Boolean} <p>
* Whether the type is usable or not.<br>
*/
BulkMailUtils.isValidTemplateType = function (pTemplateType)
{
switch (pTemplateType)
{
case DocumentTemplate.types.EML:
case DocumentTemplate.types.HTML:
case DocumentTemplate.types.TXT:
return true;
default:
return false;
}
}
* Checks whether the given status id matches,<br>
* to the status of a bulk mail which is sent or<br>
* not.
*
* @param {String} pStatus <p>
* The key id of the current status.<br>
* @return {Boolean} <p>
* True if the status is "sent" or "sending".<br>
*/
BulkMailUtils.isStatusSendingOrSent = function (pStatus)
{
return pStatus == $KeywordRegistry.bulkMailStatus$sent() || pStatus == $KeywordRegistry.bulkMailStatus$beingSent()
}
/**
* Opens BulkMail context in new mode, with the given bulk mail id.<br>
*
* @param {String} pBulkMailId <p>
* The id of the bulk mail.<br>
*/
BulkMailUtils.copy = function(pBulkMailId)
{
var params = {
"CopyBulkMailId_param" : pBulkMailId
};
neon.openContext("BulkMail", null, null, neon.OPERATINGSTATE_NEW, params);
/**
* Opens BulkMail context in new mode, with the given template from MosaicoTemplate id.<br>
*
* @param {String} pMosaicoTemplateId <p>
* The id of the bulk mail.<br>
*/
BulkMailUtils.createFromMosaicoTemplate = function(pMosaicoTemplateId)
{
var params = {
"CreateFromMosaicoTemplateId_param" : pMosaicoTemplateId
};
neon.openContext("BulkMail", null, null, neon.OPERATINGSTATE_NEW, params);
}
Martin Groppe
committed
/*
*Stores the Eml file for a bulkmailrecipient in the Filesystem
*
* @param {String} pBulkMailId <p>
* The id of the bulk mail.<br>
* @param {String} pMailRunId <p>
* The id of the bulk mail run.<br>
* @param {String} pMailLogId <p>
* The id of the corresponding mail log entry.<br>
* @param {String} pFile
Martin Groppe
committed
**/
BulkMailUtils.storeEmlFile = function (pBulkMailId, pMailRunId, pMailLogId, pFile)
var locationoption = project.getPreferenceValue("bulkmail.fileStorage", "/bulkMailFiles/");
var path = vars.get("$sys.serverdata") + locationoption + pBulkMailId + "/" + pMailRunId + "/";
var filename = pMailLogId + ".eml"
Martin Groppe
committed
var fullPath = path + filename;
fileIO.storeData(fullPath, pFile, util.DATA_BINARY, false);
}
/*
* Stores the eml file of a bounce in the filesystem
*
* @param {String} pBounceId <p>
* The id of the bounce.<br>
* @param {String} pFile
**/
BulkMailUtils.storeBounceEmlFile = function (pBounceId, pFile)
{
var locationoption = project.getPreferenceValue("bulkmail.fileStorage", "/bulkMailFiles/");
var path = vars.get("$sys.serverdata") + locationoption + "Bounces/";
var filename = pBounceId + ".eml"
var fullPath = path + filename;
fileIO.storeData(fullPath, pFile, util.DATA_TEXT, false);
}
Martin Groppe
committed
/*
*Loads the Eml file for a bulkmailrecipient from the Filesystem
*
* @param {String} pBulkMailId <p>
* The id of the bulk mail.<br>
* @param {String} pMailRunId <p>
* The id of the bulk mail run.<br>
* @param {String} pMailLogId <p>
* The id of the corresponding mail log entry.<br>
* @return {String} <p>
* The file as base64 String<br>
**/
BulkMailUtils.getEmlFile = function(pBulkMailId,pMailRunId, pMailLogId)
{
Martin Groppe
committed
var locationoption = project.getPreferenceValue("bulkmail.fileStorage","/bulkMailFiles/");
var path = vars.get("$sys.serverdata")+locationoption +pBulkMailId+"/"+pMailRunId+"/";
var filename = pMailLogId+".eml"
var fullPath = path + filename;
return (fileIO.getData(fullPath,util.DATA_BINARY));
}
Martin Groppe
committed
/*
*Gets the redirecturl for a link in a bulkmail
*
* @param {String} pLinkId <p>
* The id of the link.<br>
*
* @return {String} <p>
* The url<br>
**/
BulkMailUtils.getRedirectLink = function(pLinkId)
{
if (pLinkId)
{
return newSelect("WEBLINK.URL").from("WEBLINK").where("WEBLINK.WEBLINKID", pLinkId).cell();
Martin Groppe
committed
}
Martin Groppe
committed
}
/*
*Inserts the Redirect into the link_click table.
*
*If its the first Click the Id gets put as opener in mail_log
*
* @param {String} pMailLogId (required)<p>
* The id of the mail log.<br>
* @param {String} pIpAddress <p>
* the ip address of the client.<br>
* @param {String} pLinkId <p>
* The id of link.<br>
* @param {String} pBrowsername <p>
* The browser that was used to open the link.<br>
* @param {String} pOperatingSystemName <p>
* The Operating System that was used to open the link.<br>
* @param {String} pDeviceType <p>
* The device type that was used to open the link.<br>
**/
BulkMailUtils.insertClick = function (pMailLogId,pIpAddress,pLinkId,pBrowsername,pOperatingSystemName,pDeviceType)
Martin Groppe
committed
}
var linkClickId = util.getNewUUID();
new SqlBuilder()
.tableName("WEBLINK_CLICK")
.insertFields({
"WEBLINK_CLICKID": linkClickId,
"WEBLINK_ID": pLinkId,
"DEVICE_TYPE": pDeviceType || "desktop",
"OPERATING_SYSTEM": pOperatingSystemName,
"BROWSER": pBrowsername,
"IP_ADDRESS": pIpAddress,
"MAIL_LOG_ID": pMailLogId,
"DATE_OPENED": vars.get("$sys.date")
});
Martin Groppe
committed
newWhere("MAIL_LOG.MAIL_LOGID", pMailLogId)
.and("MAIL_LOG.OPENER_LINK_CLICK_ID is null")
.updateFields({"OPENER_LINK_CLICK_ID": linkClickId});
Martin Groppe
committed
}
Martin Groppe
committed
/* Gets the Ip Address out of the http header
*
* @param {Object} pHttpHeader the http header object
Martin Groppe
committed
*
Martin Groppe
committed
* @return {String} the original ip address of the recipient
Martin Groppe
committed
**/
BulkMailUtils.getIpAddressFromHeader = function(pHttpHeader)
{
return pHttpHeader["X-forwarded-for"].split(",")[0];
Martin Groppe
committed
}
BulkMailUtils.startBulkmailWorkFlow = function(pMailLogId, pLinkId)
Martin Groppe
committed
return
}
var [linkActionType, workflowKey, signalName] = newSelect(["ACTION_TYPE", "WORKFLOWPROCESSDEFINITION_KEY", "WORKFLOWSIGNAL_NAME"])
.from("WEBLINK")
.where("WEBLINK.WEBLINKID", pLinkId)
.arrayRow();
var contactId = newSelect("CONTACT_ID")
.from("MAIL_LOG")
.where("MAIL_LOG.MAIL_LOGID", pMailLogId)
.cell();
"linkId": pLinkId,
"contactId": contactId
if (linkActionType == $KeywordRegistry.weblinkActionType$startWorkflow() && workflowKey)
workflow.startProcessByKey(workflowKey, processVariables);
else if (linkActionType == $KeywordRegistry.weblinkActionType$sendWorkflowSignal() && signalName)
workflow.signalEventReceived(signalName, processVariables);
Martin Groppe
committed
}
}
* Adds recipients to a serial letter.<br>
* @param {String} pSerialLetterId <p>
* The id of the serial letter.<br>
* @param {String[]} pContactIds <p>
* Contact ids of the recipients.<br>
*/
SerialLetterUtils.addRecipients = function (pSerialLetterId, pContactIds)
{
var columns = [
"LETTERRECIPIENTID",
"SERIALLETTER_ID",
"CONTACT_ID"
];
var inserts = [];
for (let i = 0, l = pContactIds.length; i < l; i++)
{
inserts.push(["LETTERRECIPIENT", columns, null, [util.getNewUUID(), pSerialLetterId, pContactIds[i]]]);
}
db.inserts(inserts);
}
/**
* Opens a context to select a serial letter to add recipients to.<br>
* @param {String} pContext the context of the contacts (Person or Organisation)
* @param {String[]} pContactIds Recipients that should be added.<br>
* @param {String|Object} pFilter the filter for the contacts that should be used if no contact is selected
SerialLetterUtils.openAddRecipientView = function (pContext, pContactIds, pFilter)
if (!Utils.isString(pContactIds))
pContactIds = JSON.stringify(pContactIds);
if (!Utils.isString(pFilter))
pFilter = JSON.stringify(pFilter);
neon.openContext("SerialLetterAddRecipients", "SerialLetterAddRecipientsEdit_view", null, neon.OPERATINGSTATE_VIEW, {
"ObjectType_param": pContext,
"ContactIds_param": pContactIds,
"ContactFilter_param": pFilter
* Executes a server process that builds a serial letter.<br>
* @param {String} pSerialLetterId <p>
* The id of the serial letter.<br>
* @param {String[]} pRecipientIds (optional) <p>
* Letter recipient ids of that should be used.<br>
* If omitted, all recipients of the letter will be used.<br>
SerialLetterUtils.buildSerialLetterOnServer = function (pSerialLetterId, pRecipientIds)
var processConfig = process.createStartAsyncConfig()
.setName("buildSerialLetter_serverProcess")
.setLocalVariables({
"serialLetterId" : pSerialLetterId,
"recipientIds" : JSON.stringify(pRecipientIds),
"user" : user
})
.setUser(vars.get("$sys.user"));
process.startAsync(processConfig);
* Executes a server process that builds a serial letter.<br>
* @param {String} pSerialLetterId <p>
* Serial letter id.<br>
* @param {String[]} pRecipientIds <p>
* Letter recipient ids of that should be used.<br>
* If omitted, all recipients of the letter will be used.<br>
*/
SerialLetterUtils.buildSerialLetter = function (pSerialLetterId, pRecipientIds)
{
var [templateId, title] = newSelect("DOCUMENTTEMPLATE_ID, TITLE")
.from("SERIALLETTER")
.where("SERIALLETTER.SERIALLETTERID", pSerialLetterId)
.arrayRow(true);
var template = SerialLetterUtils.getSerialLetterTemplate(pSerialLetterId, templateId);
var contactIdsSelect = newSelect("CONTACT_ID")
.from("LETTERRECIPIENT")
.join("CONTACT", newWhere("LETTERRECIPIENT.CONTACT_ID = CONTACT.CONTACTID"))
.where("LETTERRECIPIENT.SERIALLETTER_ID", pSerialLetterId)
.andIfSet(new CommunicationSettingsCondition()