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)
var successIds = [];
var failedIds = [];
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 subjects = subjectTemplate.getReplacedContentByContactIds(contactIds);
......
......@@ -279,8 +279,9 @@ DocumentTemplate.getSelectedTemplate = function (pTemplateId, pDocumentUpload, p
* replace function for the type.
*
* @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)
* @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
*/
......
......@@ -69,14 +69,16 @@ EmailWritingUtils.getMailbridgeAddress = function ()
/**
* object for handling emails
*
* @param {String} [pBody=null] if given, the body is set to this text
* @class
*/
function Email()
function Email(pBody)
{
if (pBody == undefined) pBody = null;
this.sender = null;
this.subject = null;
this.body = null;
this.body = pBody;
this.toRecipients = [];
this.ccRecipients = [];
this.bccRecipients = [];
......@@ -94,9 +96,8 @@ Email.fromRFC = function (pBase64RFC)
{
var decoded = util.decodeBase64String(pBase64RFC);
var mailData = mail.parseRFC(decoded);
var newMail = new Email();
var newMail = new Email(mailData[mail.MAIL_HTMLTEXT]);
newMail.subject = mailData[mail.MAIL_SUBJECT];
newMail.body = mailData[mail.MAIL_HTMLTEXT];
newMail.emlFile = decoded;
return newMail;
}
......@@ -114,16 +115,39 @@ Email.fromTemplate = function (pTemplateId, pContactId, pBindata)
else
template = DocumentTemplate.loadTemplate(pTemplateId);
if (template.type == DocumentTemplate.types.EML)
{
return Email.fromRFC(template.getReplacedContentByContactIds([pContactId], true)[pContactId]);
}
else
return Email.getReplacedBulkEmails(template, [pContactId])[pContactId];
}
/**
* 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();
email.body = template.getReplacedContentByContactIds([pContactId], false)[pContactId]
return email;
if (isEML)
{
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