From cb3fabd3ef656df8ff416b5a7fe09a6ad9b0fb05 Mon Sep 17 00:00:00 2001 From: Leander Beernaert Date: Fri, 7 Jul 2023 13:47:21 +0200 Subject: [PATCH] fix(GODT-2776): Relax From & Sender validation checks They were too restrictive. From and Sender can have the same address. Closes: #380 --- rfc5322/validation.go | 6 +----- rfc5322/validation_test.go | 9 --------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/rfc5322/validation.go b/rfc5322/validation.go index 136b2d99..5e149af8 100644 --- a/rfc5322/validation.go +++ b/rfc5322/validation.go @@ -58,14 +58,10 @@ func ValidateMessageHeaderFields(literal []byte) error { return fmt.Errorf("%w: Required header field 'Sender' should not be empty", ErrInvalidMessage) } - senderAddr, err := ParseAddress(senderValue) + _, err := ParseAddress(senderValue) if err != nil { return fmt.Errorf("%w: failed to parse Sender header: %v", ErrInvalidMessage, err) } - - if len(senderAddr) == 1 && senderAddr[0].Address == addresses[0].Address { - return fmt.Errorf("%w: `Sender` should not be present if equal to `From`", ErrInvalidMessage) - } } } } diff --git a/rfc5322/validation_test.go b/rfc5322/validation_test.go index 453eccba..835fb899 100644 --- a/rfc5322/validation_test.go +++ b/rfc5322/validation_test.go @@ -28,15 +28,6 @@ func TestValidateMessageHeaderFields_ErrOnMissingDate(t *testing.T) { require.Error(t, ValidateMessageHeaderFields([]byte(literal))) } -func TestValidateMessageHeaderFields_ErrOnSingleFromAndSenderEqual(t *testing.T) { - const literal = `From: Foo@bar.com -Date: Mon, 7 Feb 1994 21:52:25 -0800 (PST) -Sender: Foo@bar.com -` - - require.Error(t, ValidateMessageHeaderFields([]byte(literal))) -} - func TestValidateMessageHeaderFields_AllowSingleFromWithDifferentSender(t *testing.T) { const literal = `From: Foo@bar.com Date: Mon, 7 Feb 1994 21:52:25 -0800 (PST)