public inbox for pmg-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH pmg-api v3 2/5] config: make smtputf8 configurable through the API
Date: Fri, 17 Mar 2023 19:44:51 +0100	[thread overview]
Message-ID: <20230317184456.26465-3-s.ivanov@proxmox.com> (raw)
In-Reply-To: <20230317184456.26465-1-s.ivanov@proxmox.com>

the flag is simply a boolean which is used to:
* add smtputf8_enable = no to postfix' main.cf if it is disabled
  (the default is to enable it, and not adding it unconditionally,
  should cause the fewest surprises for users with modified templates)
* decide if locally generated mail should be scanned for utf8 headers
  and addresses (to set the parameter to the MAIL command)

This should match postfix own implementation w.r.t. smtputf8 behavior.

Additionally, since quite a few users need to disable it because
their downstream servers do not support it (Zimbra, OpenXchange,
MS Exchange), this should make for a better user experience.

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
 src/PMG/Config.pm        |  7 +++++++
 src/PMG/Utils.pm         | 29 +++++++++++++++++------------
 src/templates/main.cf.in |  4 ++++
 3 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/src/PMG/Config.pm b/src/PMG/Config.pm
index 699a622..f13bde9 100755
--- a/src/PMG/Config.pm
+++ b/src/PMG/Config.pm
@@ -682,6 +682,11 @@ sub properties {
 	    type => 'boolean',
 	    default => 0
 	},
+	smtputf8 => {
+	    description => "Enable SMTPUTF8 support in Postfix and detection for locally generated mail",
+	    type => 'boolean',
+	    default => 1
+	},
     };
 }
 
@@ -722,6 +727,7 @@ sub options {
 	dnsbl_threshold => { optional => 1 },
 	before_queue_filtering => { optional => 1 },
 	ndr_on_block => { optional => 1 },
+	smtputf8 => { optional => 1 },
     };
 }
 
@@ -1710,6 +1716,7 @@ my $pmg_service_params = {
     mail => {
 	hide_received => 1,
 	ndr_on_block => 1,
+	smtputf8 => 1,
     },
     admin => {
 	dkim_selector => 1,
diff --git a/src/PMG/Utils.pm b/src/PMG/Utils.pm
index 49939c4..37e76aa 100644
--- a/src/PMG/Utils.pm
+++ b/src/PMG/Utils.pm
@@ -221,27 +221,32 @@ sub subst_values_for_header {
     return $res;
 }
 
-# detects the need for setting smtputf8 based on addresses and headers
+# detects the need for setting smtputf8 based on pmg.conf, addresses and headers
 sub reinject_local_mail {
-    my ($entity, $sender, $targets, $xforward, $me, $params) = @_;
+    my ($entity, $sender, $targets, $xforward, $me) = @_;
+
+    my $cfg = PMG::Config->new();
 
-    my $needs_smtputf8 = 0;
+    my $params;
+    if ( $cfg->get('mail', 'smtputf8' )) {
+	my $needs_smtputf8 = 0;
 
-    $needs_smtputf8 = 1 if ($sender =~ /[^\p{PosixPrint}]/);
+	$needs_smtputf8 = 1 if ($sender =~ /[^\p{PosixPrint}]/);
+
+	foreach my $target (@$targets) {
+	    if ($target =~ /[^\p{PosixPrint}]/) {
+		$needs_smtputf8 = 1;
+		last;
+	    }
+	}
 
-    foreach my $target (@$targets) {
-	if ($target =~ /[^\p{PosixPrint}]/) {
+	if (!$needs_smtputf8 && $entity->head()->as_string() =~ /([^\p{PosixPrint}\n\r\t])/) {
 	    $needs_smtputf8 = 1;
-	    last;
 	}
-    }
 
-    if (!$needs_smtputf8 && $entity->head()->as_string() =~ /([^\p{PosixPrint}\n\r\t])/) {
-	$needs_smtputf8 = 1;
+	$params->{mail}->{smtputf8} = $needs_smtputf8;
     }
 
-    $params->{mail}->{smtputf8} = $needs_smtputf8;
-
     return reinject_mail($entity, $sender, $targets, $xforward, $me, $params);
 }
 
diff --git a/src/templates/main.cf.in b/src/templates/main.cf.in
index 190c913..46a5b6e 100644
--- a/src/templates/main.cf.in
+++ b/src/templates/main.cf.in
@@ -131,6 +131,10 @@ lmtp_tls_session_cache_database = btree:/var/lib/postfix/lmtp_tls_session_cache
 unverified_recipient_reject_reason = Recipient address lookup failed
 [% END %]
 
+[% IF ! pmg.mail.smtputf8 %]
+smtputf8_enable = no
+[% END %]
+
 
 default_destination_concurrency_limit = 40
 lmtp_destination_concurrency_limit = 20
-- 
2.30.2





  parent reply	other threads:[~2023-03-17 18:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-17 18:44 [pmg-devel] [PATCH pmg-api v3 0/5] improve local mail injection and add smtputf8 support Stoiko Ivanov
2023-03-17 18:44 ` [pmg-devel] [PATCH pmg-api v3 1/5] smtputf8: keep smtputf8 from incoming postfix, detect for local mail Stoiko Ivanov
2023-03-17 18:44 ` Stoiko Ivanov [this message]
2023-03-17 18:44 ` [pmg-devel] [PATCH pmg-api v3 3/5] reinject mail: improve error logging Stoiko Ivanov
2023-03-17 18:44 ` [pmg-devel] [PATCH pmg-api v3 4/5] quarantine: use reinject_local_mail to deliver quarantined mail Stoiko Ivanov
2023-03-17 18:44 ` [pmg-devel] [PATCH pmg-api v3 5/5] api: quarantine: decode addresses before delivery/userlisting Stoiko Ivanov
2023-03-17 18:44 ` [pmg-devel] [PATCH pmg-gui v3 1/1] mail proxy options: add smtputf8 checkbox Stoiko Ivanov
2023-03-17 18:44 ` [pmg-devel] [PATCH pmg-docs v3 1/1] doc-generator: add new option smtputf8 Stoiko Ivanov
2023-03-23 11:18 ` [pmg-devel] [PATCH pmg-api v3 0/5] improve local mail injection and add smtputf8 support Dominik Csapak
2023-03-27 10:33 ` [pmg-devel] applied-series: " Thomas Lamprecht

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=20230317184456.26465-3-s.ivanov@proxmox.com \
    --to=s.ivanov@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