[pmg-devel] [PATCH pmg-api 2/2] fix #6126: do not deliver/delete quarantined mails multiple times

Stoiko Ivanov s.ivanov at proxmox.com
Thu Jan 30 12:21:40 CET 2025


This was reported through our enterprise support and was easy to
reproduce.

When clicking on the action-links in the spamreport multiple times the
action was equally done multiple times, which was surprising
especially when you deliver a quarantined mail more than once.

As quarantined mail-files are not deleted upon deliver/delete (mails
can have multiple recipients), but asynchronously after the quarantine
lifetime they are only marked with status 'D'.

Use this information to prevent multiple deliveries and superfluous
database updates.

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 src/PMG/Quarantine.pm | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/PMG/Quarantine.pm b/src/PMG/Quarantine.pm
index 28138ba..77f64a0 100644
--- a/src/PMG/Quarantine.pm
+++ b/src/PMG/Quarantine.pm
@@ -95,6 +95,12 @@ sub deliver_quarantined_mail {
 
     my $id = 'C' . $ref->{cid} . 'R' . $ref->{rid} . 'T' . $ref->{ticketid};;
 
+    if ($ref->{status} eq 'D') {
+	syslog('info', "quarantined mail '$id' ($path) has already been delivered or marked as " .
+	    "deleted for $receiver!");
+	return 1;
+    }
+
     my $parser = PMG::MIMEUtils::new_mime_parser({
 	nested => 1,
 	decode_bodies => 0,
@@ -148,6 +154,12 @@ sub delete_quarantined_mail {
 
     my $id = 'C' . $ref->{cid} . 'R' . $ref->{rid} . 'T' . $ref->{ticketid};;
 
+    if ($ref->{status} eq 'D') {
+	syslog('info', "quarantined mail '$id' ($path) has already been delivered or marked as " .
+	    "deleted for $pmail");
+	return 1;
+    }
+
     eval {
 	my $sth = $dbh->prepare(
 	    "UPDATE CMSReceivers SET Status='D', MTime = ? WHERE " .
-- 
2.39.5





More information about the pmg-devel mailing list