public inbox for pmg-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pmg-devel] [PATCH pmg-api] utils: fix mailflow if smtputf8 is disabled
@ 2022-12-13 17:01 Stoiko Ivanov
  2022-12-15 11:17 ` Dominik Csapak
  0 siblings, 1 reply; 2+ messages in thread
From: Stoiko Ivanov @ 2022-12-13 17:01 UTC (permalink / raw)
  To: pmg-devel

with the recent addition of smtputf8 support for the rulesystem setups
explicitly disabling smtputf8 in postfix got broken.

This is mostly noticeable for the spamreports (the receivers are taken
from the database and potentially decoded from utf-8, which sets the
'is_utf8' flag, and then tries to use the smtputf8 extension when
reinjecting the mail, which fails (since smtputf8 is disabled)

Instead of checking for the internal flag explicitly check if the
address contains only ascii printable characters (everything excluding
controlcharacters - '[\x20-\x7E]') - see
https://perldoc.perl.org/perlunifaq#What-is-%22the-UTF8-flag%22?
and
https://perldoc.perl.org/perlrecharclass#POSIX-Character-Classes

reported in our community forum:
https://forum.proxmox.com/threads/.119387/

issue is reproducible by setting
`smtputf8_enable = no` in postfix main.cf
and sending a spamreport using `pmgqm`

regular mailflow should not be affected in those setups (as no utf-8
addresses would come into the system)

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
 src/PMG/Utils.pm | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/PMG/Utils.pm b/src/PMG/Utils.pm
index 10193f6..b0a3c52 100644
--- a/src/PMG/Utils.pm
+++ b/src/PMG/Utils.pm
@@ -247,7 +247,7 @@ sub reinject_mail {
 
 	my $has_utf8_targets = 0;
 	foreach my $target (@$targets) {
-	    if (utf8::is_utf8($target)) {
+	    if ($target =~ /[^\p{PosixPrint}]/) {
 		$has_utf8_targets = 1;
 		last;
 	    }
@@ -255,7 +255,7 @@ sub reinject_mail {
 
 	my $mail_opts = " BODY=8BITMIME";
 	my $sender_addr;
-	if (utf8::is_utf8($sender)) {
+	if ($sender =~ /[^\p{PosixPrint}]/) {
 	    $sender_addr = encode('UTF-8', $smtp->_addr($sender));
 	    $mail_opts .= " SMTPUTF8";
 	} else {
@@ -285,7 +285,7 @@ sub reinject_mail {
 		}
 	    }
 
-	    if (utf8::is_utf8($target)) {
+	    if ($sender =~ /[^\p{PosixPrint}]/) {
 		$rcpt_addr = encode('UTF-8', $smtp->_addr($target));
 	    } else {
 		$rcpt_addr = $smtp->_addr($target);
-- 
2.30.2





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [pmg-devel] [PATCH pmg-api] utils: fix mailflow if smtputf8 is disabled
  2022-12-13 17:01 [pmg-devel] [PATCH pmg-api] utils: fix mailflow if smtputf8 is disabled Stoiko Ivanov
@ 2022-12-15 11:17 ` Dominik Csapak
  0 siblings, 0 replies; 2+ messages in thread
From: Dominik Csapak @ 2022-12-15 11:17 UTC (permalink / raw)
  To: pmg-devel

the approach seems sensible, but theoretically it can lose the
SMTPUTF8 information if neither sender nor recipients
contain any non ascii characters and then it's not allowed
to send utf8 headers according to rfc6531 section 3.2[0]:

---
If the SMTPUTF8 SMTP extension is not offered by the SMTP server, the
    SMTPUTF8-aware SMTP client MUST NOT transmit an internationalized
    email address and MUST NOT transmit a mail message containing
    internationalized mail headers as described in RFC 6532 [RFC6532] at
    any level within its MIME structure [RFC2045].
---

also one comment inline

0: https://www.rfc-editor.org/rfc/rfc6531#section-3.2

On 12/13/22 18:01, Stoiko Ivanov wrote:
> with the recent addition of smtputf8 support for the rulesystem setups
> explicitly disabling smtputf8 in postfix got broken.
> 
> This is mostly noticeable for the spamreports (the receivers are taken
> from the database and potentially decoded from utf-8, which sets the
> 'is_utf8' flag, and then tries to use the smtputf8 extension when
> reinjecting the mail, which fails (since smtputf8 is disabled)
> 
> Instead of checking for the internal flag explicitly check if the
> address contains only ascii printable characters (everything excluding
> controlcharacters - '[\x20-\x7E]') - see
> https://perldoc.perl.org/perlunifaq#What-is-%22the-UTF8-flag%22?
> and
> https://perldoc.perl.org/perlrecharclass#POSIX-Character-Classes
> 
> reported in our community forum:
> https://forum.proxmox.com/threads/.119387/
> 
> issue is reproducible by setting
> `smtputf8_enable = no` in postfix main.cf
> and sending a spamreport using `pmgqm`
> 
> regular mailflow should not be affected in those setups (as no utf-8
> addresses would come into the system)
> 
> Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
> ---
>   src/PMG/Utils.pm | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/src/PMG/Utils.pm b/src/PMG/Utils.pm
> index 10193f6..b0a3c52 100644
> --- a/src/PMG/Utils.pm
> +++ b/src/PMG/Utils.pm
> @@ -247,7 +247,7 @@ sub reinject_mail {
>   
>   	my $has_utf8_targets = 0;
>   	foreach my $target (@$targets) {
> -	    if (utf8::is_utf8($target)) {
> +	    if ($target =~ /[^\p{PosixPrint}]/) {
>   		$has_utf8_targets = 1;
>   		last;
>   	    }
> @@ -255,7 +255,7 @@ sub reinject_mail {
>   
>   	my $mail_opts = " BODY=8BITMIME";
>   	my $sender_addr;
> -	if (utf8::is_utf8($sender)) {
> +	if ($sender =~ /[^\p{PosixPrint}]/) {
>   	    $sender_addr = encode('UTF-8', $smtp->_addr($sender));
>   	    $mail_opts .= " SMTPUTF8";
>   	} else {
> @@ -285,7 +285,7 @@ sub reinject_mail {
>   		}
>   	    }
>   
> -	    if (utf8::is_utf8($target)) {
> +	    if ($sender =~ /[^\p{PosixPrint}]/) {
>   		$rcpt_addr = encode('UTF-8', $smtp->_addr($target));

probably c&p error, is_utf8($target) becomes $sender =~

>   	    } else {
>   		$rcpt_addr = $smtp->_addr($target);





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-15 11:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-13 17:01 [pmg-devel] [PATCH pmg-api] utils: fix mailflow if smtputf8 is disabled Stoiko Ivanov
2022-12-15 11:17 ` Dominik Csapak

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