From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 8F0848D243 for ; Mon, 7 Nov 2022 15:36:53 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 6CCFE2CB8E for ; Mon, 7 Nov 2022 15:36:23 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Mon, 7 Nov 2022 15:36:21 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id A635341957 for ; Mon, 7 Nov 2022 15:36:21 +0100 (CET) From: Dominik Csapak To: pmg-devel@lists.proxmox.com Date: Mon, 7 Nov 2022 15:36:20 +0100 Message-Id: <20221107143620.1898890-4-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221107143620.1898890-1-d.csapak@proxmox.com> References: <20221107143620.1898890-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.066 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pmg-devel] [PATCH pmg-gui 2/2] AttachmentGrid: filter attachment with content-disposition by default X-BeenThere: pmg-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Nov 2022 14:36:53 -0000 normally, attachments are given the 'content-disposition: attachment' mime attribute, so we use that to filter the attachements but since we're dealing with spam & virus mails here, and that field is client controlled, give the user a way to toggle the remaining parts of the mail too. added the checkbox in the header part, but that made it necessary to manually implement the expand/collapse toggle (since the tools are on the wrong side of the default toggle) Signed-off-by: Dominik Csapak --- js/AttachmentGrid.js | 61 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/js/AttachmentGrid.js b/js/AttachmentGrid.js index 3187a58..b6d8b4a 100644 --- a/js/AttachmentGrid.js +++ b/js/AttachmentGrid.js @@ -11,16 +11,52 @@ Ext.define('PMG.grid.AttachmentGrid', { minHeight: 50, maxHeight: 250, scrollable: true, + collapsed: true, - collapsible: true, - titleCollapse: true, + tools: [ + { + xtype: 'checkbox', + boxLabel: gettext('show all parts'), + boxLabelAlgign: 'before', + listeners: { + change: function(cb, value) { + let grid = this.up('pmgAttachmentGrid'); + let store = grid.getStore(); + store.clearFilter(); + if (!value) { + store.filter({ + property: 'content-disposition', + value: 'attachment', + }); + } + }, + }, + }, + { + type: 'down', + handler: function() { + let me = this; + let type = me.type === 'up' ? 'down' : 'up'; + me.up('pmgAttachmentGrid').toggleCollapse(); + me.setType(type); + }, + }, + ], + + header: { + padding: '6 10 6 10', // make same height as normal panel + }, store: { autoDestroy: true, - fields: ['name', 'content-type', 'size'], + fields: ['name', 'content-type', 'size', 'content-disposition'], proxy: { type: 'proxmox', }, + filters: { + property: 'content-disposition', + value: 'attachment', + }, }, controller: { @@ -35,8 +71,15 @@ Ext.define('PMG.grid.AttachmentGrid', { view.updateTitleStats(-1); return; } - let totalSize = records.reduce((sum, { data }) => sum + data.size, 0); - view.updateTitleStats(records.length, totalSize); + let count = 0; + let totalSize = records.reduce((sum, { data }) => { + if (data['content-disposition'] === 'attachment') { + count++; + return sum + data.size; + } + return sum; + }, 0); + view.updateTitleStats(count, totalSize); }, }, @@ -46,14 +89,10 @@ Ext.define('PMG.grid.AttachmentGrid', { if (count > 0) { title = Ext.String.format(gettext('{0} Attachments'), count); title += ` (${Proxmox.Utils.format_size(totalSize)})`; - if (me.collapsible) { - me.expand(); - } + me.expand(); } else { title = gettext('No Attachments'); - if (me.collapsible) { - me.collapse(); - } + me.collapse(); } me.setTitle(title); }, -- 2.30.2