2017-04-04 15:28:10 +02:00
|
|
|
Ext.namespace('Zarafa.plugins.origrcv');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class Zarafa.plugins.origrcv.OrigRcvPlugin
|
|
|
|
* @extends Zarafa.core.Plugin
|
|
|
|
*/
|
|
|
|
Zarafa.plugins.origrcv.OrigRcvPlugin = Ext.extend(Zarafa.core.Plugin, {
|
|
|
|
/*
|
|
|
|
* Called after constructor.
|
|
|
|
* Registers insertion points.
|
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
initPlugin: function() {
|
|
|
|
Zarafa.plugins.origrcv.OrigRcvPlugin.superclass.initPlugin.apply(this, arguments);
|
|
|
|
|
|
|
|
// Insertion point which shows the original to header
|
|
|
|
this.registerInsertionPoint('previewpanel.toolbar.detaillinks', this.showOriginalReceiver, this);
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Displays Original To: header information in the previewpanel
|
|
|
|
*
|
|
|
|
* @return {Object} a box which on record update displays to header
|
|
|
|
*/
|
|
|
|
showOriginalReceiver: function() {
|
|
|
|
return {
|
2017-04-04 15:36:53 +02:00
|
|
|
xtype: 'container',
|
|
|
|
autoEl: 'div',
|
|
|
|
style: 'margin-top: 6px;',
|
|
|
|
cls: 'preview-header-recipientbox',
|
2017-04-04 15:28:10 +02:00
|
|
|
plugins: ['zarafa.recordcomponentupdaterplugin'],
|
|
|
|
scope: this,
|
|
|
|
update: this.onMailDataOpen,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function which displays information in the previewpanel.
|
|
|
|
*
|
|
|
|
* @param {Zarafa.core.data.IPMRecord} record record which is displayed
|
|
|
|
* @param {Boolean} contentReset force the component to perform a full update of the data.
|
|
|
|
*/
|
|
|
|
onMailDataOpen: function(record, resetContent) {
|
2017-04-04 15:36:53 +02:00
|
|
|
var label = this.getEl();
|
2017-04-04 15:28:10 +02:00
|
|
|
// Set label to empty value by default, to override previous S/MIME message text
|
2017-04-04 15:36:53 +02:00
|
|
|
label.update(""); // empty div
|
|
|
|
label.hide();
|
2017-04-04 15:28:10 +02:00
|
|
|
|
|
|
|
if (record.opened) {
|
2020-03-31 19:08:30 +02:00
|
|
|
var toRegex = /^To\s*:\s*((?:.*|(?:\r\n|\r|\n)[\t ]+)*)(?:\r\n|\r|\n)/igm; // parse "to" header
|
2017-04-04 15:28:10 +02:00
|
|
|
var headers = record.get('transport_message_headers');
|
|
|
|
var toMatches = toRegex.exec(headers);
|
|
|
|
|
2020-02-23 18:36:27 +01:00
|
|
|
if (toMatches != null && toMatches.length == 2 && toMatches[1] != "") {
|
2020-03-31 19:08:30 +02:00
|
|
|
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,'')
|
2017-04-04 15:28:10 +02:00
|
|
|
|
|
|
|
var emailAddresses = [];
|
|
|
|
var emailAddress;
|
2020-03-31 19:08:30 +02:00
|
|
|
while ((emailAddress = addrListRegex.exec(toHeader)) != null) {
|
|
|
|
if (emailAddresses.indexOf(emailAddress[1]) == -1) {
|
|
|
|
emailAddresses.push(emailAddress[1]);
|
2017-04-04 15:28:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// only display if receiver addresses differ
|
2020-03-31 19:08:30 +02:00
|
|
|
if(!emailAddresses.includes(record.get('received_by_email_address'))) {
|
|
|
|
label.update("Original To: " + emailAddresses.join('; '));
|
2017-04-04 15:36:53 +02:00
|
|
|
label.show();
|
2017-04-04 15:28:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// PLUGIN ENTRY POINT
|
|
|
|
Zarafa.onReady(function() {
|
|
|
|
container.registerPlugin(new Zarafa.core.PluginMetaData({
|
|
|
|
name: 'origrcv',
|
|
|
|
displayName: _('Original Receiver Plugin'),
|
|
|
|
pluginConstructor: Zarafa.plugins.origrcv.OrigRcvPlugin
|
|
|
|
}));
|
|
|
|
});
|
2020-03-31 19:08:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
// 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));
|
|
|
|
}
|
|
|
|
});
|