From cdf612f0c53180ca6a892e33f936fe47dd12cdaa Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Tue, 4 Apr 2017 15:28:10 +0200 Subject: [PATCH] Initial commit --- js/origrcv.js | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++ manifest.xml | 24 ++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 js/origrcv.js create mode 100644 manifest.xml diff --git a/js/origrcv.js b/js/origrcv.js new file mode 100644 index 0000000..58ff8d7 --- /dev/null +++ b/js/origrcv.js @@ -0,0 +1,86 @@ +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 + })); +}); diff --git a/manifest.xml b/manifest.xml new file mode 100644 index 0000000..73673a0 --- /dev/null +++ b/manifest.xml @@ -0,0 +1,24 @@ + + + + + 0.0.1 + origrcv + Original Receiver Plugin + Christoph Haas + http://www.sprinternet.at + Display original receiver address + + + + + + js/origrcv.js + js/origrcv.js + + js/origrcv.js + + + + +