From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id AB2DF9312 for ; Wed, 8 Mar 2023 15:53:19 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 89D4B21B92 for ; Wed, 8 Mar 2023 15:52:49 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 8 Mar 2023 15:52:47 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 8FBA046125 for ; Wed, 8 Mar 2023 15:52:47 +0100 (CET) From: Stoiko Ivanov To: pmg-devel@lists.proxmox.com Date: Wed, 8 Mar 2023 15:52:32 +0100 Message-Id: <20230308145235.37342-4-s.ivanov@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230308145235.37342-1-s.ivanov@proxmox.com> References: <20230308145235.37342-1-s.ivanov@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.144 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [main.cf, config.pm, cf.in, utils.pm] Subject: [pmg-devel] [PATCH pmg-api v2 2/4] config: make smtputf8 configurable through the API X-BeenThere: pmg-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Mar 2023 14:53:19 -0000 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 --- best viewed with `git diff -w` 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 a0b1866..3ae68c1 100755 --- a/src/PMG/Config.pm +++ b/src/PMG/Config.pm @@ -676,6 +676,11 @@ sub properties { type => 'boolean', default => 0 }, + smtputf8 => { + description => "Enable SMTPUTF8 support in Postfix and detection for locally generated mail", + type => 'boolean', + default => 1 + }, }; } @@ -716,6 +721,7 @@ sub options { dnsbl_threshold => { optional => 1 }, before_queue_filtering => { optional => 1 }, ndr_on_block => { optional => 1 }, + smtputf8 => { optional => 1 }, }; } @@ -1698,6 +1704,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