public inbox for pmg-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH pmg-gui 2/2] AttachmentGrid: filter attachment with content-disposition by default
Date: Mon,  7 Nov 2022 15:36:20 +0100	[thread overview]
Message-ID: <20221107143620.1898890-4-d.csapak@proxmox.com> (raw)
In-Reply-To: <20221107143620.1898890-1-d.csapak@proxmox.com>

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 <d.csapak@proxmox.com>
---
 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





  parent reply	other threads:[~2022-11-07 14:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-07 14:36 [pmg-devel] [PATCH pmg-api/pmg-gui] filter attachments in quarantines Dominik Csapak
2022-11-07 14:36 ` [pmg-devel] [PATCH pmg-api 1/1] api: quarantine: add 'content-disposition' field to listattachments Dominik Csapak
2022-11-07 15:57   ` [pmg-devel] applied: " Thomas Lamprecht
2022-11-07 14:36 ` [pmg-devel] [PATCH pmg-gui 1/2] AttachmentGrid: fix typo Dominik Csapak
2022-11-07 15:54   ` [pmg-devel] applied: " Thomas Lamprecht
2022-11-07 14:36 ` Dominik Csapak [this message]
2022-11-11 17:59   ` [pmg-devel] applied: [PATCH pmg-gui 2/2] AttachmentGrid: filter attachment with content-disposition by default Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221107143620.1898890-4-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pmg-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal