From 547a12ffcae4985ffecc301a2316862e9ec0fd78 Mon Sep 17 00:00:00 2001 From: James Hillyerd Date: Sat, 3 Sep 2022 14:03:55 -0700 Subject: [PATCH] smtp: Adjust fromRegex to handle AUTH=<> in middle of args (#291) Signed-off-by: James Hillyerd --- pkg/server/smtp/handler.go | 4 ++-- pkg/server/smtp/handler_test.go | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/server/smtp/handler.go b/pkg/server/smtp/handler.go index cc1c20a..98e08da 100644 --- a/pkg/server/smtp/handler.go +++ b/pkg/server/smtp/handler.go @@ -57,7 +57,7 @@ const ( // as quoted pair and in double quoted strings (?i) makes the regex case insensitive, (?:) is // non-grouping sub-match. Accepts empty angle bracket value in options for 'AUTH=<>'. var fromRegex = regexp.MustCompile( - `(?i)^FROM:\s*<((?:(?:\\>|[^>])+|"[^"]+"@[^>])+)?>( [\w= ]+(?:=<>)?)?$`) + `(?i)^FROM:\s*<((?:(?:\\>|[^>])+|"[^"]+"@[^>])+)?>( ([\w= ]|=<>)+)?$`) func (s State) String() string { switch s { @@ -618,7 +618,7 @@ func (s *Session) parseCmd(line string) (cmd string, arg string, ok bool) { // The leading space is mandatory. func (s *Session) parseArgs(arg string) (args map[string]string, ok bool) { args = make(map[string]string) - re := regexp.MustCompile(` (\w+)=(\w+)`) + re := regexp.MustCompile(` (\w+)=(\w+|<>)`) pm := re.FindAllStringSubmatch(arg, -1) if pm == nil { s.logger.Warn().Msgf("Failed to parse arg string: %q", arg) diff --git a/pkg/server/smtp/handler_test.go b/pkg/server/smtp/handler_test.go index caf2968..22c574c 100644 --- a/pkg/server/smtp/handler_test.go +++ b/pkg/server/smtp/handler_test.go @@ -172,6 +172,7 @@ func TestReadyStateValidCommands(t *testing.T) { {"MAIL FROM: SIZE=1024", 250}, {"MAIL FROM: SIZE=1024 BODY=8BITMIME", 250}, {"MAIL FROM: SIZE=4096 AUTH=<>", 250}, + {"MAIL FROM: SIZE=4096 AUTH=<> BODY=7BIT", 250}, {"MAIL FROM:", 250}, {"MAIL FROM:<\"first last\"@space.com>", 250}, {"MAIL FROM:", 250},