Skip to content

Commit

Permalink
fix(GODT-2776): Relax From & Sender validation checks
Browse files Browse the repository at this point in the history
They were too restrictive. From and Sender can have the same address.

Closes: #380
  • Loading branch information
LBeernaertProton committed Jul 7, 2023
1 parent e8f6a4e commit cb3fabd
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 14 deletions.
6 changes: 1 addition & 5 deletions rfc5322/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
Expand Down
9 changes: 0 additions & 9 deletions rfc5322/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cb3fabd

Please sign in to comment.