[pmg-devel] [PATCH pmg-gui 1/1] add download button to spam quarantine preview

Dominik Csapak d.csapak at proxmox.com
Mon Feb 25 10:52:23 CET 2019


so that users can download the file directly

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 js/SpamQuarantine.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/js/SpamQuarantine.js b/js/SpamQuarantine.js
index 8e8a8f5..7141ecc 100644
--- a/js/SpamQuarantine.js
+++ b/js/SpamQuarantine.js
@@ -65,6 +65,7 @@ Ext.define('PMG.SpamQuarantine', {
 	    preview.setDisabled(false);
 	    this.lookupReference('raw').setDisabled(false);
 	    this.lookupReference('spam').setDisabled(false);
+	    this.lookupReference('download').setDisabled(false);
 	    preview.update("<iframe frameborder=0 width=100% height=100% sandbox='allow-same-origin' src='" + url +"'></iframe>");
 	},
 
@@ -73,6 +74,7 @@ Ext.define('PMG.SpamQuarantine', {
 	    var raw = this.lookupReference('raw');
 	    var spam = this.lookupReference('spam');
 	    var spaminfo = this.lookupReference('spaminfo');
+	    var download = this.lookupReference('download');
 
 	    preview.setDisabled(false);
 	    preview.update('<h3>' + gettext('Multiple E-Mails selected') + '</h3>');
@@ -80,6 +82,7 @@ Ext.define('PMG.SpamQuarantine', {
 	    spam.setDisabled(true);
 	    spam.setPressed(false);
 	    spaminfo.setVisible(false);
+	    download.setDisabled(true);
 	},
 
 	toggleRaw: function(button) {
@@ -153,6 +156,49 @@ Ext.define('PMG.SpamQuarantine', {
 	    grid.setVisible(!grid.isVisible());
 	},
 
+	downloadEmail: function(btn) {
+	    var me = this;
+	    var list = this.lookupReference('list');
+	    var selection = list.selModel.getSelection();
+	    if (selection.length != 1) {
+		return; // multi download is not implemented
+	    }
+	    var rec = selection[0];
+	    var url = '/api2/extjs/quarantine/content';
+	    Proxmox.Utils.API2Request({
+		url: url,
+		params: {
+		    id: rec.data.id,
+		    raw: 1
+		},
+		method: 'GET',
+		failure: function(response, opts) {
+		    Ext.Msg.alert('Error', response.htmlStatus);
+		},
+		success: function(response, opts) {
+		    var data = response.result.data;
+		    var raw = data.header;
+		    raw += '\n';
+		    raw += data.content;
+
+		    var link = Ext.DomHelper.append(document.body, {
+			tag: 'a',
+			href: 'data:message/rfc822,' + encodeURIComponent(raw),
+			css: 'display:none;visibility:hidden;height: 0px;',
+			download: rec.data.id + '.eml'
+		    });
+
+		    if (link.fireEvent) {
+			link.fireEvent('onclick');
+		    } else {
+			var evt = document.createEvent("MouseEvents");
+			evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
+			link.dispatchEvent(evt);
+		    }
+		}
+	    });
+	},
+
 	openContextMenu: function(table, record, tr, index, event) {
 	    event.stopEvent();
 	    var me = this;
@@ -206,6 +252,9 @@ Ext.define('PMG.SpamQuarantine', {
 	    'button[reference=spam]': {
 		click: 'toggleSpamInfo'
 	    },
+	    'button[reference=download]': {
+		click: 'downloadEmail'
+	    },
 	    'pmgQuarantineList': {
 		selectionChange: 'onSelectMail',
 		itemkeypress: 'keyPress',
@@ -296,6 +345,13 @@ Ext.define('PMG.SpamQuarantine', {
 			},
 			'->',
 			{
+			    xtype: 'button',
+			    reference: 'download',
+			    text: gettext('Download'),
+			    iconCls: 'fa fa-download'
+			},
+			'-',
+			{
 			    reference: 'whitelist',
 			    text: gettext('Whitelist'),
 			    iconCls: 'fa fa-check',
-- 
2.11.0




More information about the pmg-devel mailing list