[pmg-devel] [PATCH pmg-api v3 1/2] partially fix #2795: allow for '>' in smtp parameters
Stoiko Ivanov
s.ivanov at proxmox.com
Thu Nov 25 20:20:00 CET 2021
The regular expressions parsing the MAIL and RCPT commands do not
cover the case where a esmtp parameter may contain angle brackets
(e.g. the ENVID parameter for the delivery status notification
extension - RFC3464 [0]).
following section 4.1.2 of RFC5321 [1] the regex is changed to:
* consider everything up to the first '>' the mailbox
* consider everything afterwards (if it starts with a ' ') as
parameters
* since the parameter group might not match (in case no parameters are
set - e.g. after-queue filtering) - default to '' if it's not
defined
This is fairly robusts, only not parsing correctly if the local part
contains '>' (as quoted text) - but this did not work before anyways
(and causes problems in other places as well).
tested with:
```
cat test.eml | /usr/sbin/sendmail -N success,delay,failure \
-V '<someid at somehost>' \
-f '"local>part"@test.example' \
discard at test.example
```
[0] https://tools.ietf.org/html/rfc3464
[1] https://tools.ietf.org/html/rfc5321#section-4.1.2
Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
src/PMG/SMTP.pm | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/PMG/SMTP.pm b/src/PMG/SMTP.pm
index 68c833e..b3550d4 100644
--- a/src/PMG/SMTP.pm
+++ b/src/PMG/SMTP.pm
@@ -100,9 +100,9 @@ sub loop {
$self->reply ("250 2.5.0 OK");
next;
} elsif ($cmd eq 'mail') {
- if ($args =~ m/^from:\s*<([^\s\>]*)>([^>]*)$/i) {
+ if ($args =~ m/^from:\s*<([^\s\>]*?)>( .*)?$/i) {
delete $self->{to};
- my ($from, $opts) = ($1, $2);
+ my ($from, $opts) = ($1, $2 // '');
if ($opts =~ m/\sSMTPUTF8/) {
$self->{smtputf8} = 1;
$from = decode('UTF-8', $from);
@@ -115,7 +115,7 @@ sub loop {
next;
}
} elsif ($cmd eq 'rcpt') {
- if ($args =~ m/^to:\s*<([^\s\>]+)>[^>]*$/i) {
+ if ($args =~ m/^to:\s*<([^\s\>]+?)>( .*)?$/i) {
my $to = $self->{smtputf8} ? decode('UTF-8', $1) : $1;
push @{$self->{to}} , $to;
$self->reply ('250 2.5.0 OK');
--
2.30.2
More information about the pmg-devel
mailing list