Skip to content
Snippets Groups Projects
Commit 5309a5d5 authored by Johannes Hörmann's avatar Johannes Hörmann
Browse files

move bulkmail via template generation from DocumentTemplate to Email

parent cde5f878
No related branches found
No related tags found
No related merge requests found
...@@ -83,7 +83,7 @@ BulkMailUtils.sendBulkMail = function (pBulkMailId, pTestRecipients) ...@@ -83,7 +83,7 @@ BulkMailUtils.sendBulkMail = function (pBulkMailId, pTestRecipients)
var successIds = []; var successIds = [];
var failedIds = []; var failedIds = [];
var sentDate = vars.get("$sys.date"); var sentDate = vars.get("$sys.date");
var mails = template.getReplacedEmailsByContactIds(contactIds); var mails = Email.getReplacedBulkEmails(template, contactIds);
var subjectTemplate = new DocumentTemplate(subject, DocumentTemplate.types.PLAIN); var subjectTemplate = new DocumentTemplate(subject, DocumentTemplate.types.PLAIN);
var subjects = subjectTemplate.getReplacedContentByContactIds(contactIds); var subjects = subjectTemplate.getReplacedContentByContactIds(contactIds);
......
...@@ -279,8 +279,9 @@ DocumentTemplate.getSelectedTemplate = function (pTemplateId, pDocumentUpload, p ...@@ -279,8 +279,9 @@ DocumentTemplate.getSelectedTemplate = function (pTemplateId, pDocumentUpload, p
* replace function for the type. * replace function for the type.
* *
* @param {Object} pReplacements map, the structure is {placeholder : value} * @param {Object} pReplacements map, the structure is {placeholder : value}
* @param {boolean} pEncoded if the replaced content should be base64 encoded * @param {Boolean} pEncoded if the replaced content should be base64 encoded
* (doesn't affect odt/docx) * (doesn't affect odt/docx)
* @param {Boolean} {pEmlOnlyBody=false} if true for eml's only the body is parsed (e.g. for previews. Note that eml-bodies are not editable!)
* *
* @return {String} the replaced content * @return {String} the replaced content
*/ */
......
...@@ -69,14 +69,16 @@ EmailWritingUtils.getMailbridgeAddress = function () ...@@ -69,14 +69,16 @@ EmailWritingUtils.getMailbridgeAddress = function ()
/** /**
* object for handling emails * object for handling emails
* * @param {String} [pBody=null] if given, the body is set to this text
* @class * @class
*/ */
function Email() function Email(pBody)
{ {
if (pBody == undefined) pBody = null;
this.sender = null; this.sender = null;
this.subject = null; this.subject = null;
this.body = null; this.body = pBody;
this.toRecipients = []; this.toRecipients = [];
this.ccRecipients = []; this.ccRecipients = [];
this.bccRecipients = []; this.bccRecipients = [];
...@@ -94,9 +96,8 @@ Email.fromRFC = function (pBase64RFC) ...@@ -94,9 +96,8 @@ Email.fromRFC = function (pBase64RFC)
{ {
var decoded = util.decodeBase64String(pBase64RFC); var decoded = util.decodeBase64String(pBase64RFC);
var mailData = mail.parseRFC(decoded); var mailData = mail.parseRFC(decoded);
var newMail = new Email(); var newMail = new Email(mailData[mail.MAIL_HTMLTEXT]);
newMail.subject = mailData[mail.MAIL_SUBJECT]; newMail.subject = mailData[mail.MAIL_SUBJECT];
newMail.body = mailData[mail.MAIL_HTMLTEXT];
newMail.emlFile = decoded; newMail.emlFile = decoded;
return newMail; return newMail;
} }
...@@ -114,16 +115,39 @@ Email.fromTemplate = function (pTemplateId, pContactId, pBindata) ...@@ -114,16 +115,39 @@ Email.fromTemplate = function (pTemplateId, pContactId, pBindata)
else else
template = DocumentTemplate.loadTemplate(pTemplateId); template = DocumentTemplate.loadTemplate(pTemplateId);
if (template.type == DocumentTemplate.types.EML) return Email.getReplacedBulkEmails(template, [pContactId])[pContactId];
{ }
return Email.fromRFC(template.getReplacedContentByContactIds([pContactId], true)[pContactId]);
} /**
else * Replaces the placeholders with data from the contacts and returns the resulting Emails.
* @param {DocumentTemplate} pTemplate a document template which is used for all mails
* @param {Array} pContactIds Contact ids of all recipients
*
* @return {Object} Object containing the contact ids as keys and the corresponding Email
* objects as values
*/
Email.getReplacedBulkEmails = function(pTemplate, pContactIds)
{
var emailObjects = {};
var isEML = pTemplate.type == DocumentTemplate.types.EML;
var emailContents = pTemplate.getReplacedContentByContactIds(pContactIds, isEML);
for (contactId in emailContents)
{ {
var email = new Email(); if (isEML)
email.body = template.getReplacedContentByContactIds([pContactId], false)[pContactId] {
return email; emailObjects[contactId] = Email.fromRFC(emailContents[contactId]);
}
else
{
// convert to HTML if needed
if (pTemplate.type == DocumentTemplate.types.TXT || pTemplate.type == DocumentTemplate.types.PLAIN)
emailContents[contactId] = text.text2html(emailContents[contactId], false);
emailObjects[contactId] = new Email(emailContents[contactId]);
}
} }
return emailObjects;
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment