public inbox for pmg-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pmg-devel] [PATCH pmg-api] api/postfix: add 'decode-headers' to postfix queue read
@ 2022-02-03  8:29 Dominik Csapak
  2022-02-03  8:29 ` [pmg-devel] [PATCH pmg-gui] postfix queues: show decoded headers by default Dominik Csapak
  2022-02-03 11:33 ` [pmg-devel] applied: [PATCH pmg-api] api/postfix: add 'decode-headers' to postfix queue read Thomas Lamprecht
  0 siblings, 2 replies; 4+ messages in thread
From: Dominik Csapak @ 2022-02-03  8:29 UTC (permalink / raw)
  To: pmg-devel

often, the users want to show the *decoded* header, iow. they want
to see the readable subject,from,to, etc. not the quoted-printable
versions.

so add a new parameter that decodes the header lines as we read them
using MIME::WordDecoder's 'mime_to_perl_string'.

for backwards compatibility, this is not the default in the api

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/PMG/API2/Postfix.pm | 8 +++++++-
 src/PMG/Postfix.pm      | 6 +++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/PMG/API2/Postfix.pm b/src/PMG/API2/Postfix.pm
index ba22637..2dfcc11 100644
--- a/src/PMG/API2/Postfix.pm
+++ b/src/PMG/API2/Postfix.pm
@@ -239,6 +239,12 @@ __PACKAGE__->register_method ({
 		default => 0,
 		optional => 1,
 	    },
+	    'decode-header' => {
+		description => "Decodes the header fields.",
+		type => 'boolean',
+		default => 0,
+		optional => 1,
+	    },
 	},
     },
     returns => { type => 'string' },
@@ -247,7 +253,7 @@ __PACKAGE__->register_method ({
 
 	$param->{header} //= 1;
 
-	return PMG::Postfix::postcat($param->{queue_id}, $param->{header}, $param->{body});
+	return PMG::Postfix::postcat($param->{queue_id}, $param->{header}, $param->{body}, $param->{'decode-header'});
     }});
 
 __PACKAGE__->register_method ({
diff --git a/src/PMG/Postfix.pm b/src/PMG/Postfix.pm
index d6ad9d7..20f980e 100644
--- a/src/PMG/Postfix.pm
+++ b/src/PMG/Postfix.pm
@@ -5,6 +5,7 @@ use warnings;
 use Data::Dumper;
 use File::Find;
 use JSON;
+use MIME::WordDecoder qw(mime_to_perl_string);
 
 use PVE::Tools;
 
@@ -162,7 +163,7 @@ sub mailq {
 }
 
 sub postcat {
-    my ($queue_id, $header, $body) = @_;
+    my ($queue_id, $header, $body, $decode) = @_;
 
     die "no option specified (select header or body or both)"
 	if !($header || $body);
@@ -178,6 +179,9 @@ sub postcat {
 
     my $res = '';
     while (defined(my $line = <$fh>)) {
+	if ($decode) {
+	    $line = mime_to_perl_string($line);
+	}
 	$res .= $line;
     }
 
-- 
2.30.2





^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pmg-devel] [PATCH pmg-gui] postfix queues: show decoded headers by default
  2022-02-03  8:29 [pmg-devel] [PATCH pmg-api] api/postfix: add 'decode-headers' to postfix queue read Dominik Csapak
@ 2022-02-03  8:29 ` Dominik Csapak
  2022-02-03 11:32   ` [pmg-devel] applied: " Thomas Lamprecht
  2022-02-03 11:33 ` [pmg-devel] applied: [PATCH pmg-api] api/postfix: add 'decode-headers' to postfix queue read Thomas Lamprecht
  1 sibling, 1 reply; 4+ messages in thread
From: Dominik Csapak @ 2022-02-03  8:29 UTC (permalink / raw)
  To: pmg-devel

and add a toggle button to show the raw headers

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 js/ViewMailHeaders.js | 67 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 50 insertions(+), 17 deletions(-)

diff --git a/js/ViewMailHeaders.js b/js/ViewMailHeaders.js
index 0ee369b..c56f965 100644
--- a/js/ViewMailHeaders.js
+++ b/js/ViewMailHeaders.js
@@ -21,27 +21,43 @@ Ext.define('PMG.ViewMailHeaders', {
 
 	xclass: 'Ext.app.ViewController',
 
-	init: function(view) {
-	    var panel = view.lookupReference('contentPanel');
+	toggleRaw: function(btn) {
+	    let me = this;
+	    let view = me.getView();
+	    view.raw = !view.raw;
+	    me.loadData(view.url);
+	},
+
+	setData: function(data) {
+	    let view = this.getView();
+	    let panel = view.lookupReference('contentPanel');
+	    let from = data.match(/^FROM:\s*(.*\S)\s*$/mi);
+	    if (from) {
+		view.lookupReference('fromField').setValue(from[1]);
+	    }
+	    let to = data.match(/^TO:\s*(.*\S)\s*$/mi);
+	    if (to) {
+		view.lookupReference('toField').setValue(to[1]);
+	    }
+	    let subject = data.match(/^SUBJECT:\s*(.*\S)\s*$/mi);
+	    if (subject) {
+		view.lookupReference('subjectField').setValue(subject[1]);
+	    }
+	    panel.update(Ext.String.htmlEncode(data));
+	},
+
+	loadData: function(url) {
+	    let me = this;
+	    let view = me.getView();
+	    if (!view.raw) {
+		url += "?decode-header=1";
+	    }
 	    Proxmox.Utils.API2Request({
-		url: view.url,
+		url,
 		waitMsgTarget: view,
 		method: 'GET',
 		success: function(response, opts) {
-		    var data = response.result.data;
-		    var from = data.match(/^FROM:\s*(.*\S)\s*$/mi);
-		    if (from) {
-			view.lookupReference('fromField').setValue(from[1]);
-		    }
-		    var to = data.match(/^TO:\s*(.*\S)\s*$/mi);
-		    if (to) {
-			view.lookupReference('toField').setValue(to[1]);
-		    }
-		    var subject = data.match(/^SUBJECT:\s*(.*\S)\s*$/mi);
-		    if (subject) {
-			view.lookupReference('subjectField').setValue(subject[1]);
-		    }
-		    panel.update(Ext.String.htmlEncode(data));
+		    me.setData(response.result.data);
 		},
 		failure: function(response, opts) {
 		    view.destroy();
@@ -49,8 +65,25 @@ Ext.define('PMG.ViewMailHeaders', {
 		},
 	    });
 	},
+
+	init: function(view) {
+	    let me = this;
+	    me.loadData(view.url);
+	},
     },
 
+    buttons: [
+	{
+	    xtype: 'button',
+	    reference: 'raw',
+	    text: gettext('Toggle Raw'),
+	    enableToggle: true,
+	    iconCls: 'fa fa-file-code-o',
+	    handler: 'toggleRaw',
+	},
+	'->',
+    ],
+
     items: [
 	{
 	    xtype: 'textfield',
-- 
2.30.2





^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pmg-devel] applied: [PATCH pmg-gui] postfix queues: show decoded headers by default
  2022-02-03  8:29 ` [pmg-devel] [PATCH pmg-gui] postfix queues: show decoded headers by default Dominik Csapak
@ 2022-02-03 11:32   ` Thomas Lamprecht
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Lamprecht @ 2022-02-03 11:32 UTC (permalink / raw)
  To: Dominik Csapak, pmg-devel

On 03.02.22 09:29, Dominik Csapak wrote:
> and add a toggle button to show the raw headers
> 
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
>  js/ViewMailHeaders.js | 67 ++++++++++++++++++++++++++++++++-----------
>  1 file changed, 50 insertions(+), 17 deletions(-)
> 
>

applied, but changed the "toggle" button to a checkbox right beside the header display
field, saves space and allows the user to tell what the current state is, thanks!




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pmg-devel] applied: [PATCH pmg-api] api/postfix: add 'decode-headers' to postfix queue read
  2022-02-03  8:29 [pmg-devel] [PATCH pmg-api] api/postfix: add 'decode-headers' to postfix queue read Dominik Csapak
  2022-02-03  8:29 ` [pmg-devel] [PATCH pmg-gui] postfix queues: show decoded headers by default Dominik Csapak
@ 2022-02-03 11:33 ` Thomas Lamprecht
  1 sibling, 0 replies; 4+ messages in thread
From: Thomas Lamprecht @ 2022-02-03 11:33 UTC (permalink / raw)
  To: Dominik Csapak, pmg-devel

On 03.02.22 09:29, Dominik Csapak wrote:
> often, the users want to show the *decoded* header, iow. they want
> to see the readable subject,from,to, etc. not the quoted-printable
> versions.
> 
> so add a new parameter that decodes the header lines as we read them
> using MIME::WordDecoder's 'mime_to_perl_string'.
> 
> for backwards compatibility, this is not the default in the api
> 
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
>  src/PMG/API2/Postfix.pm | 8 +++++++-
>  src/PMG/Postfix.pm      | 6 +++++-
>  2 files changed, 12 insertions(+), 2 deletions(-)
> 
>

applied, made a small followup for line length and doing an useless but
cheap optimization, thanks!




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-02-03 11:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-03  8:29 [pmg-devel] [PATCH pmg-api] api/postfix: add 'decode-headers' to postfix queue read Dominik Csapak
2022-02-03  8:29 ` [pmg-devel] [PATCH pmg-gui] postfix queues: show decoded headers by default Dominik Csapak
2022-02-03 11:32   ` [pmg-devel] applied: " Thomas Lamprecht
2022-02-03 11:33 ` [pmg-devel] applied: [PATCH pmg-api] api/postfix: add 'decode-headers' to postfix queue read Thomas Lamprecht

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