[pmg-devel] [PATCH pmg-api v2 1/2] add support for sending NDRs on Block

Stoiko Ivanov s.ivanov at proxmox.com
Thu Nov 14 17:35:06 CET 2019


This patch adds a flag to the mail-section of pmg.conf - 'ndr_on_block',
defaulting to false.

If enabled pmg-smtp-filter replies with 554 (permanent fail) for the recipient
who blocked the mail.

Since pmg-smtp-filter is currently called with LMTP it can respond with a
separate code for each recipient. Postfix records the answers and generates
and sends the NDR to the sender.

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 src/PMG/Config.pm | 6 ++++++
 src/PMG/SMTP.pm   | 8 +++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/PMG/Config.pm b/src/PMG/Config.pm
index 4cbc520..e1a9cd4 100755
--- a/src/PMG/Config.pm
+++ b/src/PMG/Config.pm
@@ -627,6 +627,11 @@ sub properties {
 	    minimum => 0,
 	    default => 1
 	},
+	ndr_on_block => {
+	    description => "Send out NDR when mail gets blocked",
+	    type => 'boolean',
+	    default => 0
+	},
     };
 }
 
@@ -661,6 +666,7 @@ sub options {
 	verifyreceivers => { optional => 1 },
 	dnsbl_sites => { optional => 1 },
 	dnsbl_threshold => { optional => 1 },
+	ndr_on_block => { optional => 1 },
     };
 }
 
diff --git a/src/PMG/SMTP.pm b/src/PMG/SMTP.pm
index a404ef0..00a448e 100644
--- a/src/PMG/SMTP.pm
+++ b/src/PMG/SMTP.pm
@@ -132,12 +132,18 @@ sub loop {
 		    syslog ('err', $err);
 		}
 
+		my $cfg = $data->{pmg_cfg};
+
 		if ($self->{lmtp}) {
 		    foreach $a (@{$self->{to}}) {
 			if ($self->{queue}->{status}->{$a} eq 'delivered') {
 			    $self->reply ("250 2.5.0 OK ($self->{queue}->{logid})");
 			} elsif ($self->{queue}->{status}->{$a} eq 'blocked') {
-			    $self->reply ("250 2.7.0 BLOCKED ($self->{queue}->{logid})");
+			    if ($cfg->get('mail', 'ndr_on_block')) {
+				$self->reply ("554 5.7.1 Rejected for policy reasons ($self->{queue}->{logid})");
+			    } else {
+				$self->reply ("250 2.7.0 BLOCKED ($self->{queue}->{logid})");
+			    }
 			} elsif ($self->{queue}->{status}->{$a} eq 'error') {
 			    my $code = $self->{queue}->{status_code}->{$a};
 			    my $resp = substr($code, 0, 1);
-- 
2.20.1




More information about the pmg-devel mailing list