[pmg-devel] [PATCH pmg-gui 1/1] SpamQuarantine: fix download of large emails

Dominik Csapak d.csapak at proxmox.com
Wed Oct 23 09:36:35 CEST 2019


since datauri downloads are size limited (2MB in chrome), we have
to use another method, and instead of working around in the gui
(e.g. by using URL.createObjectURL) make use of the existing download
code in the api, which should have better compatibility
(and omits the whole raw -> json -> raw -> base64 conversion chain from
file to download)

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

diff --git a/js/SpamQuarantine.js b/js/SpamQuarantine.js
index 7141ecc..d1b32f0 100644
--- a/js/SpamQuarantine.js
+++ b/js/SpamQuarantine.js
@@ -164,39 +164,22 @@ Ext.define('PMG.SpamQuarantine', {
 		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);
-		    }
-		}
+	    var url = "/api2/json/quarantine/download?mailid=" +
+			encodeURIComponent(rec.data.id);
+	    var link = Ext.DomHelper.append(document.body, {
+		tag: 'a',
+		href: url,
+		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) {
-- 
2.20.1




More information about the pmg-devel mailing list