From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH pmg-api v2 2/4] config: make smtputf8 configurable through the API
Date: Wed, 8 Mar 2023 15:52:32 +0100 [thread overview]
Message-ID: <20230308145235.37342-4-s.ivanov@proxmox.com> (raw)
In-Reply-To: <20230308145235.37342-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>
---
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
next prev parent reply other threads:[~2023-03-08 14:53 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-08 14:52 [pmg-devel] [PATCH pmg-api v2 0/4] improve local mail injection and add smtputf8 support Stoiko Ivanov
2023-03-08 14:52 ` [pmg-devel] [PATCH pmg-docs v2 1/1] doc-generator: add new option smtputf8 Stoiko Ivanov
2023-03-08 14:52 ` [pmg-devel] [PATCH pmg-api v2 1/4] smtputf8: keep smtputf8 from incoming postfix, detect for local mail Stoiko Ivanov
2023-03-08 14:52 ` Stoiko Ivanov [this message]
2023-03-08 14:52 ` [pmg-devel] [PATCH pmg-api v2 3/4] reinject mail: improve error logging Stoiko Ivanov
2023-03-08 14:52 ` [pmg-devel] [PATCH pmg-api v2 4/4] quarantine: use reinject_local_mail to deliver quarantined mail Stoiko Ivanov
2023-03-08 14:52 ` [pmg-devel] [PATCH pmg-gui v2 1/1] mail proxy options: add smtputf8 checkbox Stoiko Ivanov
2023-03-16 12:52 ` [pmg-devel] [PATCH pmg-api v2 0/4] improve local mail injection and add smtputf8 support Dominik Csapak
2023-03-16 12:58 ` Dominik Csapak
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=20230308145235.37342-4-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