More improvements, replace address in newly created email
This commit is contained in:
parent
c6935a04c4
commit
286f8aba6f
7
README.md
Normal file
7
README.md
Normal file
@ -0,0 +1,7 @@
|
||||
ORIGINAL RECEIVER PLUGIN:
|
||||
===
|
||||
|
||||
## Building the original receiver plugin from source:
|
||||
|
||||
### Compiling the plugin
|
||||
The plugin needs no compilation. Simply copy the folder to the webapp plugin folder.
|
0
js/origrcv-overrides.js
Normal file
0
js/origrcv-overrides.js
Normal file
144
js/origrcv.js
144
js/origrcv.js
@ -46,32 +46,25 @@ Zarafa.plugins.origrcv.OrigRcvPlugin = Ext.extend(Zarafa.core.Plugin, {
|
||||
label.hide();
|
||||
|
||||
if (record.opened) {
|
||||
var toRegex = /^To\s*:\s*(.*)$/igm; // parse "to" header
|
||||
var toRegex = /^To\s*:\s*((?:.*|(?:\r\n|\r|\n)[\t ]+)*)(?:\r\n|\r|\n)/igm; // parse "to" header
|
||||
var headers = record.get('transport_message_headers');
|
||||
var toMatches = toRegex.exec(headers);
|
||||
|
||||
if (toMatches != null && toMatches.length == 2 && toMatches[1] != "") {
|
||||
var addrListRegex = /\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}\b/ig; // split email address list
|
||||
var addrListRegex = /<?([^<>,\s]+@[^<>,\s]+\.[^<>,\s]+)>?\s*(?:,|(?:\r\n|\r|\n)|$)/g; // split email address list
|
||||
var toHeader = toMatches[1].replace(/(?:\r\n|\r|\n)/g,'')
|
||||
|
||||
var emailAddresses = [];
|
||||
var emailAddress;
|
||||
while ((emailAddress = addrListRegex.exec(toMatches[1])) != null) {
|
||||
if (emailAddresses.indexOf(emailAddress[0]) == -1) {
|
||||
emailAddresses.push(emailAddress[0]);
|
||||
while ((emailAddress = addrListRegex.exec(toHeader)) != null) {
|
||||
if (emailAddresses.indexOf(emailAddress[1]) == -1) {
|
||||
emailAddresses.push(emailAddress[1]);
|
||||
}
|
||||
}
|
||||
|
||||
// only display if receiver addresses differ
|
||||
if (emailAddresses.length == 1 && !(emailAddresses[0] == record.get('display_to') || emailAddresses[0] == record.get('received_by_email_address'))) {
|
||||
label.update("Original To: " + emailAddresses[0]);
|
||||
label.show();
|
||||
} else if (emailAddresses.length > 1) {
|
||||
var addressList = "";
|
||||
for (var i = 0; i < emailAddresses.length; i++) {
|
||||
if (i != 0) addressList += ", ";
|
||||
addressList += emailAddresses[i];
|
||||
}
|
||||
label.update("Original To: " + addressList);
|
||||
if(!emailAddresses.includes(record.get('received_by_email_address'))) {
|
||||
label.update("Original To: " + emailAddresses.join('; '));
|
||||
label.show();
|
||||
}
|
||||
}
|
||||
@ -87,3 +80,124 @@ Zarafa.onReady(function() {
|
||||
pluginConstructor: Zarafa.plugins.origrcv.OrigRcvPlugin
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
// OVERRIDE ORIGINGAL KOPANO IMPLEMENTATIONS
|
||||
Ext.override(Zarafa.mail.MailContextModel, {
|
||||
/**
|
||||
* Initialize the {@link Zarafa.core.data.IPMRecord record} with an updated
|
||||
* body. This will quote the previous body as plain-text or html depending
|
||||
* on the editors preferences.
|
||||
*
|
||||
* @param {Zarafa.core.data.IPMRecord} record The record to initialize
|
||||
* @param {Zarafa.core.data.IPMRecord} origRecord The original record
|
||||
* to which the respond is created
|
||||
* @param {Zarafa.mail.data.ActionTypes} actionType The actionType used
|
||||
* for this response.
|
||||
* @private
|
||||
*/
|
||||
initRecordBody: function(record, origRecord, actionType) {
|
||||
var signatureId = this.getSignatureId(actionType);
|
||||
|
||||
// Create a copy of the original data, the body has changed,
|
||||
// and we don't want to change the original record.
|
||||
var respondData = Ext.apply({}, origRecord.data);
|
||||
|
||||
/**
|
||||
* here we go through all the recipients in recipientStore and build the username <user@abc.com> format
|
||||
* recipient for to and cc fields, and add then in respondData display_to and display_cc field.
|
||||
* and we don't want to change original record,
|
||||
*/
|
||||
if(origRecord.isOpened()){
|
||||
var recipientStore = origRecord.getRecipientStore();
|
||||
var to = [];
|
||||
var cc = [];
|
||||
|
||||
if (recipientStore.getCount() > 0) {
|
||||
recipientStore.each(function(recipient) {
|
||||
switch(recipient.get('recipient_type')){
|
||||
case Zarafa.core.mapi.RecipientType.MAPI_TO :
|
||||
to.push(recipient.formatRecipient());
|
||||
break;
|
||||
case Zarafa.core.mapi.RecipientType.MAPI_CC :
|
||||
cc.push(recipient.formatRecipient());
|
||||
break;
|
||||
}
|
||||
},this);
|
||||
|
||||
respondData.display_to = to.join('; ');
|
||||
respondData.display_cc = cc.join('; ');
|
||||
}
|
||||
|
||||
// START CUSTOMIZATION
|
||||
var toRegex = /^To\s*:\s*((?:.*|(?:\r\n|\r|\n)[\t ]+)*)(?:\r\n|\r|\n)/igm; // parse "to" header
|
||||
var ccRegex = /^CC\s*:\s*((?:.*|(?:\r\n|\r|\n)[\t ]+)*)(?:\r\n|\r|\n)/igm; // parse "cc" header
|
||||
var addrListRegex = /<?([^<>,\s]+@[^<>,\s]+\.[^<>,\s]+)>?\s*(?:,|(?:\r\n|\r|\n)|$)/g; // split email address list
|
||||
var headers = origRecord.get('transport_message_headers');
|
||||
var toMatches = toRegex.exec(headers);
|
||||
var ccMatches = ccRegex.exec(headers);
|
||||
|
||||
if (toMatches != null && toMatches.length == 2 && toMatches[1] != "") {
|
||||
var toHeader = toMatches[1].replace(/(?:\r\n|\r|\n)/g,'');
|
||||
|
||||
var emailAddresses = [];
|
||||
var emailAddress;
|
||||
while ((emailAddress = addrListRegex.exec(toHeader)) != null) {
|
||||
if (emailAddresses.indexOf(emailAddress[1]) == -1) {
|
||||
emailAddresses.push(emailAddress[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if(!emailAddresses.includes(origRecord.get('received_by_email_address'))) {
|
||||
respondData.display_to = emailAddresses.join('; ');
|
||||
}
|
||||
}
|
||||
if (ccMatches != null && ccMatches.length == 2 && ccMatches[1] != "") {
|
||||
var ccHeader = ccMatches[1].replace(/(?:\r\n|\r|\n)/g,'');
|
||||
|
||||
var emailAddresses = [];
|
||||
var emailAddress;
|
||||
while ((emailAddress = addrListRegex.exec(ccHeader)) != null) {
|
||||
if (emailAddresses.indexOf(emailAddress[1]) == -1) {
|
||||
emailAddresses.push(emailAddress[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if(!emailAddresses.includes(origRecord.get('received_by_email_address'))) {
|
||||
respondData.display_cc = emailAddresses.join('; ');
|
||||
}
|
||||
}
|
||||
// END CUSTOMIZATION
|
||||
}
|
||||
|
||||
// Initialize HTML body
|
||||
respondData.body = origRecord.cleanupOutlookStyles(origRecord.getBody(true));
|
||||
respondData.signatureData = this.getSignatureData(true, signatureId);
|
||||
respondData.fontFamily = container.getSettingsModel().get('zarafa/v1/main/default_font');
|
||||
respondData.fontSize = Zarafa.common.ui.htmleditor.Fonts.getDefaultFontSize();
|
||||
|
||||
record.set('html_body', Zarafa.mail.data.Templates.htmlQuotedTemplate.apply(respondData));
|
||||
|
||||
// Initialize plain-text body
|
||||
respondData.body = origRecord.getBody(false);
|
||||
respondData.signatureData = this.getSignatureData(false, signatureId);
|
||||
|
||||
// Prefix each line with the '> ' sign to indicate
|
||||
// it is being quoted. Wrap the text around 72 chars.
|
||||
const text = respondData.body;
|
||||
let newText = "> ";
|
||||
let count = 0;
|
||||
for (let i=0; i < text.length; ++i) {
|
||||
if ((text[i] === " " && count > 72) || text[i] === "\n") {
|
||||
newText += "\n> ";
|
||||
count = 0;
|
||||
} else {
|
||||
newText += text[i];
|
||||
count++;
|
||||
}
|
||||
}
|
||||
respondData.body = newText;
|
||||
|
||||
record.set('body', Zarafa.mail.data.Templates.plaintextQuotedTemplate.apply(respondData));
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue
Block a user