origrcv/js/origrcv.js

87 lines
3.2 KiB
JavaScript

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 {
xtype: 'label',
style: 'width: 99%;',
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) {
// Set label to empty value by default, to override previous S/MIME message text
this.setText("");
this.hide();
if (record.opened) {
var toRegex = /^To\s*:\s*(.*)$/igm; // parse "to" header
var headers = record.get('transport_message_headers');
var toMatches = toRegex.exec(headers);
if (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 emailAddresses = [];
var emailAddress;
while ((emailAddress = addrListRegex.exec(toMatches[1])) != null) {
if (emailAddresses.indexOf(emailAddress[0]) == -1) {
emailAddresses.push(emailAddress[0]);
}
}
// only display if receiver addresses differ
if (emailAddresses.length == 1 && !(emailAddresses[0] == record.get('display_to') || emailAddresses[0] == record.get('received_by_email_address'))) {
this.setText("Original To: " + emailAddresses[0]);
this.show();
} else if (emailAddresses.length > 1) {
var addressList = "";
for (var i = 0; i < emailAddresses.length; i++) {
if (i != 0) addressList += ", ";
addressList += emailAddresses[i];
}
this.setText("Original To: " + addressList);
this.show();
}
}
}
},
});
// PLUGIN ENTRY POINT
Zarafa.onReady(function() {
container.registerPlugin(new Zarafa.core.PluginMetaData({
name: 'origrcv',
displayName: _('Original Receiver Plugin'),
pluginConstructor: Zarafa.plugins.origrcv.OrigRcvPlugin
}));
});