public inbox for pmg-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christoph Heiss <c.heiss@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH pmg-api v3 2/3] fix #4211: convert quarantine link mail to template
Date: Tue,  8 Oct 2024 13:17:52 +0200	[thread overview]
Message-ID: <20241008111753.831405-3-c.heiss@proxmox.com> (raw)
In-Reply-To: <20241008111753.831405-1-c.heiss@proxmox.com>

Fixes #4211 [0] by converting the currently hardcoded text for the
quarantine link mail to a proper template, enabling users to write their
own versions.

Pretty straight-forward change. The overall content/wording is kept
pretty much for the plain-text version, the HTML variant is adapted from
that as needed.

[0] https://bugzilla.proxmox.com/show_bug.cgi?id=4211

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
Changes v1 -> v2:
  * adapted to new finalize_report() changes
  * added plain-text template

Changes v2 -> v3:
  * adapted to finalize_report() changes

 src/Makefile                           |  2 ++
 src/PMG/API2/Quarantine.pm             | 22 ++++++++++------------
 src/templates/quarantine-link.html.tt  | 13 +++++++++++++
 src/templates/quarantine-link.plain.tt |  5 +++++
 4 files changed, 30 insertions(+), 12 deletions(-)
 create mode 100644 src/templates/quarantine-link.html.tt
 create mode 100644 src/templates/quarantine-link.plain.tt

diff --git a/src/Makefile b/src/Makefile
index 8e49a10..c602378 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -44,6 +44,8 @@ TEMPLATES =				\
 	postgresql.conf.in		\
 	pg_hba.conf.in			\
 	backup-notification.tt		\
+	quarantine-link.html.tt         \
+	quarantine-link.plain.tt        \
 
 TEMPLATES_FILES = $(addprefix templates/, ${TEMPLATES})
 
diff --git a/src/PMG/API2/Quarantine.pm b/src/PMG/API2/Quarantine.pm
index 9301da9..058180c 100644
--- a/src/PMG/API2/Quarantine.pm
+++ b/src/PMG/API2/Quarantine.pm
@@ -1235,18 +1235,16 @@ my sub send_link_mail {
     my $esc_ticket = uri_escape($ticket);
     my $link = "$protocol_fqdn_port/quarantine?ticket=${esc_ticket}";
 
-    my $text = "Here is your Link for the Spam Quarantine on $fqdn:\n\n$link\n";
-
-    my $mail = MIME::Entity->build(
-	Type    => "text/plain",
-	To      => $receiver,
-	From    => $mailfrom,
-	Subject => "Proxmox Mail Gateway - Quarantine Link",
-	Data    => $text,
-    );
-
-    # we use an empty envelope sender (we don't want to receive NDRs)
-    PMG::Utils::reinject_local_mail ($mail, '', [$receiver], undef, $fqdn);
+    my $tt = PMG::Config::get_template_toolkit();
+    my $vars = {
+	fqdn => $fqdn,
+	link => $link,
+    };
+
+    PMG::Utils::finalize_report($tt, $vars, $mailfrom, $receiver, {
+	html => 'quarantine-link.html.tt',
+	plain => 'quarantine-link.plain.tt',
+    });
 }
 
 __PACKAGE__->register_method ({
diff --git a/src/templates/quarantine-link.html.tt b/src/templates/quarantine-link.html.tt
new file mode 100644
index 0000000..d6fd17e
--- /dev/null
+++ b/src/templates/quarantine-link.html.tt
@@ -0,0 +1,13 @@
+[%- SET title = "Proxmox Mail Gateway - Quarantine Link" -%]
+<html>
+  <head>
+    <title>[% title %]</title>
+  </head>
+  <body>
+    <p>
+      Here is your link for the spam quarantine on <code>[% fqdn %]</code>: <a href='[% link | url %]'>Spam quarantine</a>
+    </p>
+
+    <p>Powered by <a target=_blank href='http://www.proxmox.com'>Proxmox</a>.</p>
+  </body>
+</html>
diff --git a/src/templates/quarantine-link.plain.tt b/src/templates/quarantine-link.plain.tt
new file mode 100644
index 0000000..98517a3
--- /dev/null
+++ b/src/templates/quarantine-link.plain.tt
@@ -0,0 +1,5 @@
+Here is your link for the spam quarantine on [% fqdn %]:
+
+[% link %]
+
+Powered by http://www.proxmox.com
-- 
2.46.0



_______________________________________________
pmg-devel mailing list
pmg-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel


  parent reply	other threads:[~2024-10-08 11:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-08 11:17 [pmg-devel] [PATCH pmg-api v3 0/3] " Christoph Heiss
2024-10-08 11:17 ` [pmg-devel] [PATCH pmg-api v3 1/3] utils: allow specifying plain and/or html for finalize_report() Christoph Heiss
2024-10-08 11:17 ` Christoph Heiss [this message]
2024-10-08 11:17 ` [pmg-devel] [PATCH pmg-docs v3 3/3] pmgconfig: document support for html and plain-text email templates Christoph Heiss

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241008111753.831405-3-c.heiss@proxmox.com \
    --to=c.heiss@proxmox.com \
    --cc=pmg-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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