1package imapserver
2
3import (
4 "testing"
5
6 "github.com/mjl-/mox/imapclient"
7)
8
9func TestCreate(t *testing.T) {
10 tc := start(t)
11 defer tc.close()
12
13 tc2 := startNoSwitchboard(t)
14 defer tc2.close()
15
16 tc.client.Login("mjl@mox.example", "testtest")
17 tc2.client.Login("mjl@mox.example", "testtest")
18
19 tc.transactf("no", "create inbox") // Already exists and not allowed. ../rfc/9051:1913
20 tc.transactf("no", "create Inbox") // Idem.
21
22 // ../rfc/9051:1937
23 tc.transactf("ok", "create inbox/a/c")
24 tc.xuntagged(imapclient.UntaggedList{Flags: []string{`\Subscribed`}, Separator: '/', Mailbox: "Inbox/a"}, imapclient.UntaggedList{Flags: []string{`\Subscribed`}, Separator: '/', Mailbox: "Inbox/a/c"})
25
26 tc2.transactf("ok", "noop")
27 tc2.xuntagged(imapclient.UntaggedList{Flags: []string{`\Subscribed`}, Separator: '/', Mailbox: "Inbox/a"}, imapclient.UntaggedList{Flags: []string{`\Subscribed`}, Separator: '/', Mailbox: "Inbox/a/c"})
28
29 tc.transactf("no", "create inbox/a/c") // Exists.
30
31 tc.transactf("ok", "create inbox/a/x")
32 tc.xuntagged(imapclient.UntaggedList{Flags: []string{`\Subscribed`}, Separator: '/', Mailbox: "Inbox/a/x"})
33
34 tc2.transactf("ok", "noop")
35 tc2.xuntagged(imapclient.UntaggedList{Flags: []string{`\Subscribed`}, Separator: '/', Mailbox: "Inbox/a/x"})
36
37 // ../rfc/9051:1934
38 tc.transactf("ok", "create mailbox/")
39 tc.xuntagged(imapclient.UntaggedList{Flags: []string{`\Subscribed`}, Separator: '/', Mailbox: "mailbox", OldName: "mailbox/"})
40
41 tc2.transactf("ok", "noop")
42 tc2.xuntagged(imapclient.UntaggedList{Flags: []string{`\Subscribed`}, Separator: '/', Mailbox: "mailbox"})
43
44 // If we are already subscribed, create should still work, and we still want to see the subscribed flag.
45 tc.transactf("ok", "subscribe newbox")
46 tc2.transactf("ok", "noop")
47 tc2.xuntagged(imapclient.UntaggedList{Flags: []string{`\Subscribed`, `\NonExistent`}, Separator: '/', Mailbox: "newbox"})
48
49 tc.transactf("ok", "create newbox")
50 tc.xuntagged(imapclient.UntaggedList{Flags: []string{`\Subscribed`}, Separator: '/', Mailbox: "newbox"})
51 tc2.transactf("ok", "noop")
52 tc2.xuntagged(imapclient.UntaggedList{Flags: []string{`\Subscribed`}, Separator: '/', Mailbox: "newbox"})
53
54 // todo: test create+delete+create of a name results in a higher uidvalidity.
55
56 tc.transactf("no", "create /bad/root")
57 tc.transactf("no", "create bad//root") // Cannot have internal duplicate slashes.
58 tc.transactf("no", `create ""`) // Refuse empty mailbox name.
59 // We are not allowing special characters.
60 tc.transactf("bad", `create "\n"`)
61 tc.transactf("bad", `create "\x7f"`)
62 tc.transactf("bad", `create "\x9f"`)
63 tc.transactf("bad", `create "\u2028"`)
64 tc.transactf("bad", `create "\u2029"`)
65 tc.transactf("no", `create "%%"`)
66 tc.transactf("no", `create "*"`)
67 tc.transactf("no", `create "#"`)
68 tc.transactf("no", `create "&"`)
69}
70