[pmg-devel] [PATCH pmg-api 1/1] Quarantine API: extend download call to download whole mails

Stoiko Ivanov s.ivanov at proxmox.com
Thu Oct 24 17:43:50 CEST 2019


just an optional suggestion - maybe mention explicitly 
that the permission check (a quser only being able to get their own 
mails/attachments) happens in get_and_check_mail in the commit message..

helps with people like me who get quite carried away at the change in the 
'permissions' property

but as said - really optional and no need for a v2 on that account


On Wed, 23 Oct 2019 09:36:34 +0200
Dominik Csapak <d.csapak at proxmox.com> wrote:

> this makes the attachmentid parameter optional and if it is not given,
> open the whole mail for download
> 
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
>  src/PMG/API2/Quarantine.pm | 27 ++++++++++++++++++++-------
>  1 file changed, 20 insertions(+), 7 deletions(-)
> 
> diff --git a/src/PMG/API2/Quarantine.pm b/src/PMG/API2/Quarantine.pm
> index 1869093..5cb0f8e 100644
> --- a/src/PMG/API2/Quarantine.pm
> +++ b/src/PMG/API2/Quarantine.pm
> @@ -1053,8 +1053,8 @@ __PACKAGE__->register_method ({
>      name => 'download',
>      path => 'download',
>      method => 'GET',
> -    permissions => { check => [ 'admin', 'qmanager', 'audit'] },
> -    description => "Download Attachment for E-Mail in Quarantine.",
> +    permissions => { check => [ 'admin', 'qmanager', 'audit', 'quser'] },
> +    description => "Download E-Mail or Attachment from Quarantine.",
>      download => 1,
>      parameters => {
>  	additionalProperties => 0,
> @@ -1068,6 +1068,7 @@ __PACKAGE__->register_method ({
>  	    attachmentid => {
>  		description => "The Attachment ID for the mail.",
>  		type => 'integer',
> +		optional => 1,
>  	    },
>  	},
>      },
> @@ -1081,17 +1082,29 @@ __PACKAGE__->register_method ({
>  	my $attachmentid = $param->{attachmentid};
>  
>  	my $dumpdir = "/run/pmgproxy/pmg-$mailid-$$/";
> -	my $attachments = $get_attachments->($mailid, $dumpdir, 1);
> +	my $res;
>  
> -	my $res = $attachments->[$attachmentid];
> -	if (!$res) {
> -	    raise_param_exc({ attachmentid => "Invalid Attachment ID for Mail."});
> +	if ($attachmentid) {
> +	    my $attachments = $get_attachments->($mailid, $dumpdir, 1);
> +	    $res = $attachments->[$attachmentid];
> +	    if (!$res) {
> +		raise_param_exc({ attachmentid => "Invalid Attachment ID for Mail."});
> +	    }
> +	} else {
> +	    my $rpcenv = PMG::RESTEnvironment->get();
> +	    my $ref = $get_and_check_mail->($mailid, $rpcenv);
> +	    my $spooldir = $PMG::MailQueue::spooldir;
> +
> +	    $res = {
> +		'content-type' => 'message/rfc822',
> +		path => "$spooldir/$ref->{file}",
> +	    };
>  	}
>  
>  	$res->{fh} = IO::File->new($res->{path}, '<') ||
>  	    die "unable to open file '$res->{path}' - $!\n";
>  
> -	rmtree $dumpdir;
> +	rmtree $dumpdir if -e $dumpdir;
>  
>  	return $res;
>  




More information about the pmg-devel mailing list