1package imapserver
2
3import (
4 "testing"
5
6 "github.com/mjl-/mox/imapclient"
7)
8
9func TestDelete(t *testing.T) {
10 tc := start(t)
11 defer tc.close()
12
13 tc2 := startNoSwitchboard(t)
14 defer tc2.close()
15
16 tc3 := startNoSwitchboard(t)
17 defer tc3.close()
18
19 tc.client.Login("mjl@mox.example", password0)
20 tc2.client.Login("mjl@mox.example", password0)
21 tc3.client.Login("mjl@mox.example", password0)
22
23 tc.transactf("bad", "delete") // Missing mailbox.
24 tc.transactf("no", "delete inbox") // Cannot delete inbox.
25 tc.transactf("no", "delete nonexistent") // Cannot delete mailbox that does not exist.
26 tc.transactf("no", `delete "nonexistent"`) // Again, with quoted string syntax.
27
28 tc.client.Subscribe("x")
29 tc.transactf("no", "delete x") // Subscription does not mean there is a mailbox that can be deleted.
30
31 tc.client.Create("a/b")
32 tc2.transactf("ok", "noop") // Drain changes.
33 tc3.transactf("ok", "noop")
34
35 // ../rfc/9051:2000
36 tc.transactf("no", "delete a") // Still has child.
37 tc.xcode("HASCHILDREN")
38
39 tc3.client.Enable("IMAP4rev2") // For \NonExistent support.
40 tc.transactf("ok", "delete a/b")
41 tc2.transactf("ok", "noop")
42 tc2.xuntagged() // No IMAP4rev2, no \NonExistent.
43 tc3.transactf("ok", "noop")
44 tc3.xuntagged(imapclient.UntaggedList{Flags: []string{`\NonExistent`}, Separator: '/', Mailbox: "a/b"})
45
46 tc.transactf("no", "delete a/b") // Already removed.
47 tc.transactf("ok", "delete a") // Parent can now be removed.
48 tc.transactf("ok", `list (subscribed) "" (a/b a) return (subscribed)`)
49 // Subscriptions still exist.
50 tc.xuntagged(
51 imapclient.UntaggedList{Flags: []string{`\Subscribed`, `\NonExistent`}, Separator: '/', Mailbox: "a"},
52 imapclient.UntaggedList{Flags: []string{`\Subscribed`, `\NonExistent`}, Separator: '/', Mailbox: "a/b"},
53 )
54
55 // Let's try again with a message present.
56 tc.client.Create("msgs")
57 tc.client.Append("msgs", nil, nil, []byte(exampleMsg))
58 tc.transactf("ok", "delete msgs")
59
60 // Delete for inbox/* is allowed.
61 tc.client.Create("inbox/a")
62 tc.transactf("ok", "delete inbox/a")
63
64}
65