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 46C739155B for ; Fri, 17 Mar 2023 19:45:48 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 264711D0F0 for ; Fri, 17 Mar 2023 19:45:18 +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) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Fri, 17 Mar 2023 19:45:16 +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 839914521A for ; Fri, 17 Mar 2023 19:45:16 +0100 (CET) From: Stoiko Ivanov To: pmg-devel@lists.proxmox.com Date: Fri, 17 Mar 2023 19:44:51 +0100 Message-Id: <20230317184456.26465-3-s.ivanov@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230317184456.26465-1-s.ivanov@proxmox.com> References: <20230317184456.26465-1-s.ivanov@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.143 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. [config.pm, utils.pm, cf.in, main.cf] Subject: [pmg-devel] [PATCH pmg-api v3 2/5] 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: Fri, 17 Mar 2023 18:45:48 -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 --- 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