diff --git a/http/import.go b/http/import.go index c2f3fab..68fd90c 100644 --- a/http/import.go +++ b/http/import.go @@ -444,8 +444,11 @@ func importMessages(ctx context.Context, log *mlog.Log, token string, acc *store err = tx.Insert(&mb) ximportcheckf(err, "inserting mailbox in database") - changes = append(changes, store.ChangeAddMailbox{Name: p}) - // todo: should we also subscribe to the mailbox? + err = tx.Insert(&store.Subscription{Name: p}) + if err != nil && !errors.Is(err, bstore.ErrUnique) { + ximportcheckf(err, "subscribing to imported mailbox") + } + changes = append(changes, store.ChangeAddMailbox{Name: p, Flags: []string{`\Subscribed`}}) } else if err != nil { ximportcheckf(err, "creating mailbox %s (aborting)", p) } diff --git a/imapserver/delete_test.go b/imapserver/delete_test.go index b655cb8..f2f9545 100644 --- a/imapserver/delete_test.go +++ b/imapserver/delete_test.go @@ -13,8 +13,12 @@ func TestDelete(t *testing.T) { tc2 := startNoSwitchboard(t) defer tc2.close() + tc3 := startNoSwitchboard(t) + defer tc3.close() + tc.client.Login("mjl@mox.example", "testtest") tc2.client.Login("mjl@mox.example", "testtest") + tc3.client.Login("mjl@mox.example", "testtest") tc.transactf("bad", "delete") // Missing mailbox. tc.transactf("no", "delete inbox") // Cannot delete inbox. @@ -26,14 +30,18 @@ func TestDelete(t *testing.T) { tc.client.Create("a/b") tc2.transactf("ok", "noop") // Drain changes. + tc3.transactf("ok", "noop") // ../rfc/9051:2000 tc.transactf("no", "delete a") // Still has child. tc.xcode("HASCHILDREN") + tc3.client.Enable("IMAP4rev2") // For \NonExistent support. tc.transactf("ok", "delete a/b") tc2.transactf("ok", "noop") - tc2.xuntagged(imapclient.UntaggedList{Flags: []string{`\NonExistent`}, Separator: '/', Mailbox: "a/b"}) + tc2.xuntagged() // No IMAP4rev2, no \NonExistent. + tc3.transactf("ok", "noop") + tc3.xuntagged(imapclient.UntaggedList{Flags: []string{`\NonExistent`}, Separator: '/', Mailbox: "a/b"}) tc.transactf("no", "delete a/b") // Already removed. tc.transactf("ok", "delete a") // Parent can now be removed. diff --git a/imapserver/server.go b/imapserver/server.go index 2582f0b..3178fdf 100644 --- a/imapserver/server.go +++ b/imapserver/server.go @@ -1237,7 +1237,12 @@ func (c *conn) applyChanges(changes []store.Change, initial bool) { c.bwritelinef("* %d FETCH (UID %d FLAGS %s)", seq, ch.UID, flaglist(ch.Flags).pack(c)) } case store.ChangeRemoveMailbox: - c.bwritelinef(`* LIST (\NonExistent) "/" %s`, astring(ch.Name).pack(c)) + // Only announce \NonExistent to modern clients, otherwise they may ignore the + // unrecognized \NonExistent and interpret this as a newly created mailbox, while + // the goal was to remove it... + if c.enabled[capIMAP4rev2] { + c.bwritelinef(`* LIST (\NonExistent) "/" %s`, astring(ch.Name).pack(c)) + } case store.ChangeAddMailbox: c.bwritelinef(`* LIST (%s) "/" %s`, strings.Join(ch.Flags, " "), astring(ch.Name).pack(c)) case store.ChangeRenameMailbox: