Skip to content

Commit

Permalink
fix(GODT-2379): Unsubscribed mailboxes should always be listed with LIST
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshoulahan committed Feb 20, 2023
1 parent c6aa359 commit bdcd96f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
23 changes: 13 additions & 10 deletions internal/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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
}
Expand Down
27 changes: 27 additions & 0 deletions tests/unsubscribe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
})
}

0 comments on commit bdcd96f

Please sign in to comment.