[pmg-devel] [PATCH pmg-api v2 1/2] utils: allow specifying plain and/or html for finalize_report()

Stoiko Ivanov s.ivanov at proxmox.com
Mon Oct 7 18:11:28 CEST 2024


Thanks for the quick turn-around on this!

on a quick glance - I think I like the approach (and that you converted
all call-sites of finalize_report directly) - however one
pitfall/suggestion inline:

On Mon,  7 Oct 2024 12:32:11 +0200
Christoph Heiss <c.heiss at proxmox.com> wrote:

> To support both plain-text and HTML emails when sending reports,
> PMG::Utils::finalize_report() first needs a small adaption to allow
> specifying either only an HTML template or both.
> 
> Suggested-by: Stoiko Ivanov <s.ivanov at proxmox.com>
> Signed-off-by: Christoph Heiss <c.heiss at proxmox.com>
> ---
>  src/PMG/Backup.pm        |  2 +-
>  src/PMG/CLI/pmgqm.pm     |  5 ++++-
>  src/PMG/CLI/pmgreport.pm |  5 ++++-
>  src/PMG/Utils.pm         | 26 +++++++++++++++++++++-----
>  4 files changed, 30 insertions(+), 8 deletions(-)
> 
> diff --git a/src/PMG/Backup.pm b/src/PMG/Backup.pm
> index ab7e628..e9c116b 100644
> --- a/src/PMG/Backup.pm
> +++ b/src/PMG/Backup.pm
> @@ -418,7 +418,7 @@ sub send_backup_notification {
>      my $tt = PMG::Config::get_template_toolkit();
>  
>      my $mailfrom = "Proxmox Mail Gateway <postmaster>";
> -    PMG::Utils::finalize_report($tt, 'backup-notification.tt', $vars, $mailfrom, $email);
> +    PMG::Utils::finalize_report($tt, $vars, $mailfrom, $email, html => 'backup-notification.tt');
I think using a hashref here would help to cause less confusion in the
future:
PMG::Utils::finalize_report($tt, $vars, $mailfrom, $email, { html =>
'backup-notification.tt'} ); (but looking through our source am not 100%
sure if we have a strong rule for this)

your line above is  syntactically equivalent to:
PMG::Utils::finalize_report($tt, $vars, $mailfrom, $email, "html",
'backup-notification.tt'); see:
https://perldoc.perl.org/perlop#Comma-Operator which I find confusing
(especially if I touch this code in the future)

since finalize_report is called from quite a few places - I think having
those parameters in a hashref would be more robust, but maybe I'm
overlooking something?





More information about the pmg-devel mailing list