From bdcd96f259c197a5aaf08b20f0a075fd687e0ab6 Mon Sep 17 00:00:00 2001 From: James Houlahan Date: Mon, 20 Feb 2023 10:57:28 +0100 Subject: [PATCH] fix(GODT-2379): Unsubscribed mailboxes should always be listed with LIST --- internal/state/state.go | 23 +++++++++++++---------- tests/unsubscribe_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/internal/state/state.go b/internal/state/state.go index e01c7ce1..59b310f3 100644 --- a/internal/state/state.go +++ b/internal/state/state.go @@ -78,7 +78,7 @@ func (state *State) db() *db.DB { return state.user.GetDB() } -func (state *State) List(ctx context.Context, ref, pattern string, subscribed bool, fn func(map[string]Match) error) error { +func (state *State) List(ctx context.Context, ref, pattern string, lsub bool, fn func(map[string]Match) error) error { return state.db().Read(ctx, func(ctx context.Context, client *ent.Client) error { mailboxes, err := db.GetAllMailboxes(ctx, client) if err != nil { @@ -117,7 +117,7 @@ func (state *State) List(ctx context.Context, ref, pattern string, subscribed bo var deletedSubscriptions map[imap.MailboxID]*ent.DeletedSubscription - if subscribed { + if lsub { deletedSubscriptions, err = db.GetDeletedSubscriptionSet(ctx, client) if err != nil { return err @@ -129,16 +129,19 @@ func (state *State) List(ctx context.Context, ref, pattern string, subscribed bo for _, mbox := range mailboxes { delete(deletedSubscriptions, mbox.RemoteID) - if mbox.Subscribed { - matchMailboxes = append(matchMailboxes, matchMailbox{ - Name: mbox.Name, - Subscribed: subscribed, - EntMBox: mbox, - }) + // Only include subscribed mailboxes when LSUB is used. + if lsub && !mbox.Subscribed { + continue } + + matchMailboxes = append(matchMailboxes, matchMailbox{ + Name: mbox.Name, + Subscribed: lsub, + EntMBox: mbox, + }) } - if subscribed { + if lsub { // Insert any remaining mailboxes that have been deleted but are still subscribed. for _, s := range deletedSubscriptions { if state.user.GetRemote().GetMailboxVisibility(ctx, s.RemoteID) != imap.Visible { @@ -153,7 +156,7 @@ func (state *State) List(ctx context.Context, ref, pattern string, subscribed bo } } - matches, err := getMatches(ctx, client, matchMailboxes, ref, pattern, state.delimiter, subscribed) + matches, err := getMatches(ctx, client, matchMailboxes, ref, pattern, state.delimiter, lsub) if err != nil { return err } diff --git a/tests/unsubscribe_test.go b/tests/unsubscribe_test.go index 73b4aa72..5a64db8b 100644 --- a/tests/unsubscribe_test.go +++ b/tests/unsubscribe_test.go @@ -51,3 +51,30 @@ func TestUnsubscribeAfterMailboxRenamedDeleted(t *testing.T) { c.S("A008 OK UNSUBSCRIBE") }) } + +func TestUnsubscribeList(t *testing.T) { + runOneToOneTestWithAuth(t, defaultServerOptions(t, withDelimiter(".")), func(c *testConnection, _ *testSession) { + c.C(`tag list "" "*"`) + c.S(`* LIST (\Unmarked) "." "INBOX"`) + c.OK(`tag`) + + c.C(`tag unsubscribe "INBOX"`).OK(`tag`) + + c.C(`tag list "" "*"`) + c.S(`* LIST (\Unmarked) "." "INBOX"`) + c.OK(`tag`) + + c.C(`tag lsub "" "*"`) + c.OK(`tag`) + + c.C(`tag subscribe "INBOX"`).OK(`tag`) + + c.C(`tag lsub "" "*"`) + c.S(`* LSUB (\Unmarked) "." "INBOX"`) + c.OK(`tag`) + + c.C(`tag list "" "*"`) + c.S(`* LIST (\Unmarked) "." "INBOX"`) + c.OK(`tag`) + }) +}