smtp: Support the SMTPUTF8 extension in the RCPT TO command

Note: The RCPT TO command isn't required to advertise to the server that
it contains UTF-8 characters, instead the server is told that a mail may
contain UTF-8 in any envelope command via the MAIL command.
This commit is contained in:
Steve Holme 2020-02-13 22:39:28 +00:00
parent aba1bf630f
commit 483edeb8dd
No known key found for this signature in database
GPG key ID: 4059CB85CA7E8F19
4 changed files with 91 additions and 6 deletions

View file

@ -871,16 +871,19 @@ sub RCPT_smtp {
sendcontrol "501 Unrecognized parameter\r\n";
}
else {
my $smtputf8 = grep /^SMTPUTF8$/, @capabilities;
my $to = $1;
# Validate the to address (only a valid email address inside <> is
# allowed, such as <user@example.com>)
if ($to !~
/^<([a-zA-Z0-9._%+-]+)\@(([a-zA-Z0-9-]+)\.)+([a-zA-Z]{2,4})>$/) {
sendcontrol "501 Invalid address\r\n";
if ((!$smtputf8 && $to =~
/^<([a-zA-Z0-9._%+-]+)\@(([a-zA-Z0-9-]+)\.)+([a-zA-Z]{2,4})>$/) ||
($smtputf8 && $to =~
/^<([a-zA-Z0-9\x{80}-\x{ff}._%+-]+)\@(([a-zA-Z0-9\x{80}-\x{ff}-]+)\.)+([a-zA-Z]{2,4})>$/)) {
sendcontrol "250 Recipient OK\r\n";
}
else {
sendcontrol "250 Recipient OK\r\n";
sendcontrol "501 Invalid address\r\n";
}
}