Skip to content

Commit

Permalink
fix(GODT-2758): Fix panic in SetFlagsOnMessages
Browse files Browse the repository at this point in the history
Check that the flagset is not empty before proceeding with the database
modifications.
  • Loading branch information
LBeernaertProton committed Jul 5, 2023
1 parent d901d16 commit 9a33650
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/state/updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,11 @@ func (state *State) applyMessageFlagsSet(ctx context.Context,
return nil, err
}

if err := tx.SetFlagsOnMessages(ctx, messageIDs, setFlags.Remove(imap.FlagDeleted)); err != nil {
return nil, err
remainingFlags := setFlags.Remove(imap.FlagDeleted)
if remainingFlags.Len() != 0 {
if err := tx.SetFlagsOnMessages(ctx, messageIDs, remainingFlags); err != nil {
return nil, err
}
}

return []Update{NewMessageFlagsSetStateUpdate(setFlags, state.snap.mboxID, messageIDs, state.StateID)}, nil
Expand Down
16 changes: 16 additions & 0 deletions tests/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ func TestStore(t *testing.T) {
})
}

func TestSetStoreDeletedDoesNotCrash(t *testing.T) {
runOneToOneTestWithAuth(t, defaultServerOptions(t), func(c *testConnection, _ *testSession) {
c.C("b001 CREATE saved-messages")
c.S("b001 OK CREATE")

c.doAppend(`saved-messages`, buildRFC5322TestLiteral(`To: 1@pm.me`)).expect("OK")

c.C(`A002 SELECT saved-messages`)
c.Se(`A002 OK [READ-WRITE] SELECT`)

c.C(`A002 STORE 1 FLAGS (\Deleted)`)
c.S(`* 1 FETCH (FLAGS (\Deleted \Recent))`)
c.OK(`A002`)
})
}

func TestStoreSilent(t *testing.T) {
runManyToOneTestWithAuth(t, defaultServerOptions(t), []int{1, 2}, func(c map[int]*testConnection, s *testSession) {
// one message in INBOX
Expand Down

0 comments on commit 9a33650

Please sign in to comment.