Skip to content

Commit

Permalink
fix(GODT-2683): Only validate messages if mailbox is not Drafts
Browse files Browse the repository at this point in the history
  • Loading branch information
LBeernaertProton committed Jun 7, 2023
1 parent 8b9b7ac commit ef9959a
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 30 deletions.
4 changes: 0 additions & 4 deletions internal/session/handle_append.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ func (s *Session) handleAppend(ctx context.Context, tag string, cmd *command.App
if err := rfc5322.ValidateMessageHeaderFields(cmd.Literal); err != nil {
return response.Bad(tag).WithError(err)
}
} else {
if err := rfc5322.ValidateMessageHeaderFieldsDrafts(cmd.Literal); err != nil {
return response.Bad(tag).WithError(err)
}
}

messageUID, err := mailbox.Append(ctx, cmd.Literal, flags, cmd.DateTime)
Expand Down
24 changes: 0 additions & 24 deletions rfc5322/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,3 @@ func ValidateMessageHeaderFields(literal []byte) error {

return nil
}

// ValidateMessageHeaderFieldsDrafts checks the headers of message to verify that at least a valid From header is
// present.
func ValidateMessageHeaderFieldsDrafts(literal []byte) error {
headerBytes, _ := rfc822.Split(literal)

header, err := rfc822.NewHeader(headerBytes)
if err != nil {
return err
}

// Check for from.
value := header.Get("From")
if len(value) == 0 {
return fmt.Errorf("%w: Required header field 'From' not found or empty", ErrInvalidMessage)
}

// Check if From is a multi address. If so, a sender filed must be present and non-empty.
if _, err := ParseAddressList(value); err != nil {
return fmt.Errorf("%w: failed to parse From header: %v", ErrInvalidMessage, err)
}

return nil
}
4 changes: 2 additions & 2 deletions tests/append_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,14 +467,14 @@ Date: Wed, 26 Apr 2023 08:25:16 +0200
{
require.NoError(t, doAppendWithClient(client, "Drafts", literalWithFrom, time.Now()))
require.NoError(t, doAppendWithClient(client, "INBOX", literalValid, time.Now()))
require.Error(t, doAppendWithClient(client, "Drafts", literalWithoutFrom, time.Now()))
require.NoError(t, doAppendWithClient(client, "Drafts", literalWithoutFrom, time.Now()))
require.Error(t, doAppendWithClient(client, "INBOX", literalWithoutFrom, time.Now()))
}

{
status, err := client.Status("Drafts", []goimap.StatusItem{goimap.StatusMessages})
require.NoError(t, err)
require.Equal(t, uint32(1), status.Messages, "Expected message count does not match")
require.Equal(t, uint32(2), status.Messages, "Expected message count does not match")
}
{
status, err := client.Status("INBOX", []goimap.StatusItem{goimap.StatusMessages})
Expand Down

0 comments on commit ef9959a

Please sign in to comment.