Skip to content

Commit

Permalink
fix(GODT-2619): Ensure mailbox deletions from connector unsubscribe
Browse files Browse the repository at this point in the history
When a mailbox is deleted from the connector, make sure it is also
removed from the subscription list.
  • Loading branch information
LBeernaertProton committed May 12, 2023
1 parent e4f4a84 commit 861a509
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
8 changes: 6 additions & 2 deletions internal/backend/connector_updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (user *user) applyMailboxDeleted(ctx context.Context, update *imap.MailboxD
}

stateUpdate, err := db.WriteResult(ctx, user.db, func(ctx context.Context, tx *ent.Tx) (state.Update, error) {
internalMailboxID, err := db.GetMailboxIDFromRemoteID(ctx, tx.Client(), update.MailboxID)
mailbox, err := db.GetMailboxByRemoteID(ctx, tx.Client(), update.MailboxID)
if err != nil {
if ent.IsNotFound(err) {
return nil, nil
Expand All @@ -139,7 +139,11 @@ func (user *user) applyMailboxDeleted(ctx context.Context, update *imap.MailboxD
return nil, err
}

return state.NewMailboxDeletedStateUpdate(internalMailboxID), nil
if _, err := db.RemoveDeletedSubscriptionWithName(ctx, tx, mailbox.Name); err != nil {
return nil, err
}

return state.NewMailboxDeletedStateUpdate(mailbox.ID), nil
})
if err != nil {
return err
Expand Down
15 changes: 15 additions & 0 deletions tests/updates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,3 +427,18 @@ func TestUpdatedMessageFetchSucceedsOnSecondTry(t *testing.T) {
c.OK("A005")
})
}

func TestDeleteMailboxFromConnectorAlsoRemoveSubscriptionStatus(t *testing.T) {
runOneToOneTestWithAuth(t, defaultServerOptions(t), func(c *testConnection, s *testSession) {
mailboxID := s.mailboxCreated("user", []string{"mbox1"})
s.flush("user")
s.mailboxDeleted("user", mailboxID)
s.flush("user")

c.C(`S001 LSUB "" "*"`)
c.S(
`* LSUB (\Unmarked) "/" "INBOX"`,
)
c.S("S001 OK LSUB")
})
}

0 comments on commit 861a509

Please sign in to comment.