[pmg-devel] applied: [PATCH pmg-gui 2/2] AttachmentGrid: filter attachment with content-disposition by default

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Nov 11 18:59:25 CET 2022


s/AttachmentGrid/attachment grid/ in the subject gives a slightly better
searchable tag.

Am 07/11/2022 um 15:36 schrieb Dominik Csapak:
> 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 at proxmox.com>
> ---
>  js/AttachmentGrid.js | 61 ++++++++++++++++++++++++++++++++++++--------
>  1 file changed, 50 insertions(+), 11 deletions(-)
> 
>

applied, thanks! I moved the checkbox into the tbar, as I don't think it is
something often wanted/used, as while yes, the content-disposition is user
controllable, most (all?) MUAs only show it if set so even spammers/attackers
have it in their interest to set it if they actually want to make it useable/
downloadable.

That then allows to turn back on the native titleCollapse, which I find a bit
more ergonomic. Slight drawback is tohave 1.5 rows "wasted" due to the tbar,
but one can still see 6 attachments just fine and IMO not really a concern
(tbh. I'd just drop that checkbox if it really is deemed to use to much space
in the tbar).

> @@ -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);

for such thing's it IMO simpler to use a .filter first, i.e., I reworked it to:

let attachments = records.filter(({ data }) => data['content-disposition'] === 'attachment');
let totalSize = attachments.reduce((sum, { data }) => sum + data.size, 0);
view.updateTitleStats(attachments.length, totalSize);

> +	    view.updateTitleStats(count, totalSize);
>  	},
>      },
>  




More information about the pmg-devel mailing list