[pmg-devel] [PATCH pmg-api v3 2/5] config: make smtputf8 configurable through the API
Stoiko Ivanov
s.ivanov at proxmox.com
Fri Mar 17 19:44:51 CET 2023
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 at 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
More information about the pmg-devel
mailing list