From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 16C1081C3D for ; Thu, 25 Nov 2021 20:20:21 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 11B2111B25 for ; Thu, 25 Nov 2021 20:20:21 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id C3FB911B16 for ; Thu, 25 Nov 2021 20:20:16 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 9EF1146A88 for ; Thu, 25 Nov 2021 20:20:16 +0100 (CET) From: Stoiko Ivanov To: pmg-devel@lists.proxmox.com Date: Thu, 25 Nov 2021 20:20:00 +0100 Message-Id: <20211125192001.150932-2-s.ivanov@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211125192001.150932-1-s.ivanov@proxmox.com> References: <20211125192001.150932-1-s.ivanov@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.299 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [ietf.org, smtp.pm] Subject: [pmg-devel] [PATCH pmg-api v3 1/2] partially fix #2795: allow for '>' in smtp parameters X-BeenThere: pmg-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Nov 2021 19:20:21 -0000 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 '' \ -f '"local>part"@test.example' \ discard@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 --- 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