]> git.proxmox.com Git - pmg-api.git/commitdiff
api/postfix: add 'decode-headers' to postfix queue read
authorDominik Csapak <d.csapak@proxmox.com>
Thu, 3 Feb 2022 08:29:23 +0000 (09:29 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 3 Feb 2022 09:12:18 +0000 (10:12 +0100)
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
src/PMG/Postfix.pm

index ba226373804e0160baf38c8a945caf60f1124a09..2dfcc11a47bfd9ef20f0b969b49fd6c10a4c0dc1 100644 (file)
@@ -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 ({
index d6ad9d7d5d164262648206fa7c39da63ffbd5c7f..20f980e7fe60eb330fe5055883a071639b854802 100644 (file)
@@ -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;
     }