smtp: Support the SMTPUTF8 extension in the MAIL command

Support the SMTPUTF8 extension when sending mailbox information in the
MAIL command (FROM and AUTH parameters). Non-ASCII domain names will
be ACE encoded, if IDN is supported, whilst non-ASCII characters in
the local address part are passed to the server.

Reported-by: ygthien on github
Fixes #4828
This commit is contained in:
Steve Holme 2020-02-13 20:59:36 +00:00
parent 4754c55cd7
commit aba1bf630f
No known key found for this signature in database
GPG key ID: 4059CB85CA7E8F19
4 changed files with 111 additions and 19 deletions

View file

@ -813,6 +813,7 @@ sub MAIL_smtp {
else {
my $from;
my $size;
my $smtputf8 = grep /^SMTPUTF8$/, @capabilities;
my @elements = split(/ /, $args);
# Get the FROM and SIZE parameters
@ -827,11 +828,11 @@ sub MAIL_smtp {
# Validate the from address (only <> and a valid email address inside
# <> are allowed, such as <user@example.com>)
if ((!$from) || (($from ne "<>") && ($from !~
/^<([a-zA-Z0-9._%+-]+)\@(([a-zA-Z0-9-]+)\.)+([a-zA-Z]{2,4})>$/))) {
sendcontrol "501 Invalid address\r\n";
}
else {
if (($from eq "<>") ||
(!$smtputf8 && $from =~
/^<([a-zA-Z0-9._%+-]+)\@(([a-zA-Z0-9-]+)\.)+([a-zA-Z]{2,4})>$/) ||
($smtputf8 && $from =~
/^<([a-zA-Z0-9\x{80}-\x{ff}._%+-]+)\@(([a-zA-Z0-9\x{80}-\x{ff}-]+)\.)+([a-zA-Z]{2,4})>$/)) {
my @found;
my $valid = 1;
@ -852,6 +853,9 @@ sub MAIL_smtp {
sendcontrol "250 Sender OK\r\n";
}
}
else {
sendcontrol "501 Invalid address\r\n";
}
}
return 0;