Skip to content

Commit

Permalink
fix(GODT-2418): Do not issue connector renames for inferiors
Browse files Browse the repository at this point in the history
When renaming a mailbox with inferiors, do not issue rename requests to
the connector for the inferiors. The connector should internally handle
this. We should only rename the mailboxes locally to avoid waiting on
the connector event.
  • Loading branch information
LBeernaertProton committed Mar 20, 2023
1 parent 9f7c827 commit 45de5f1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
9 changes: 7 additions & 2 deletions internal/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@ func (state *State) Rename(ctx context.Context, oldName, newName string) error {
return state.renameInbox(ctx, tx, mbox, newName)
}

if err := state.actionUpdateMailbox(ctx, tx, mbox.RemoteID, newName); err != nil {
return err
}

// Locally update all inferiors so we don't wait for update
mailboxes, err := db.GetAllMailboxes(ctx, tx.Client())
if err != nil {
return err
Expand All @@ -388,12 +393,12 @@ func (state *State) Rename(ctx context.Context, oldName, newName string) error {

newInferior := newName + strings.TrimPrefix(inferior, oldName)

if err := state.actionUpdateMailbox(ctx, tx, mbox.RemoteID, newInferior); err != nil {
if err := db.RenameMailboxWithRemoteID(ctx, tx, mbox.RemoteID, newInferior); err != nil {
return err
}
}

return state.actionUpdateMailbox(ctx, tx, mbox.RemoteID, newName)
return nil
})
}

Expand Down
12 changes: 12 additions & 0 deletions tests/rename_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ func TestRenameHierarchy(t *testing.T) {
})
}

func TestRenameHierarchyRoot(t *testing.T) {
runOneToOneTestClientWithAuth(t, defaultServerOptions(t), func(client *client.Client, _ *testSession) {
require.NoError(t, client.Create("foo/bar/zap"))

matchMailboxNamesClient(t, client, "", "*", []string{"INBOX", "foo", "foo/bar", "foo/bar/zap"})

require.NoError(t, client.Rename("foo", "baz"))

matchMailboxNamesClient(t, client, "", "*", []string{"INBOX", "baz", "baz/bar", "baz/bar/zap"})
})
}

func TestRenameAddHierarchy(t *testing.T) {
type renameTC struct {
src string
Expand Down

0 comments on commit 45de5f1

Please sign in to comment.