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", password0)
17 tc2.client.Login("mjl@mox.example", password0)
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"})
40
41 // OldName is only set for IMAP4rev2 or NOTIFY.
42 tc.client.Enable("imap4rev2")
43 tc.transactf("ok", "create mailbox2/")
44 tc.xuntagged(imapclient.UntaggedList{Flags: []string{`\Subscribed`}, Separator: '/', Mailbox: "mailbox2", OldName: "mailbox2/"})
45
46 tc2.transactf("ok", "noop")
47 tc2.xuntagged(imapclient.UntaggedList{Flags: []string{`\Subscribed`}, Separator: '/', Mailbox: "mailbox"}, imapclient.UntaggedList{Flags: []string{`\Subscribed`}, Separator: '/', Mailbox: "mailbox2"})
48
49 // If we are already subscribed, create should still work, and we still want to see the subscribed flag.
50 tc.transactf("ok", "subscribe newbox")
51 tc2.transactf("ok", "noop")
52 tc2.xuntagged(imapclient.UntaggedList{Flags: []string{`\Subscribed`, `\NonExistent`}, Separator: '/', Mailbox: "newbox"})
53
54 tc.transactf("ok", "create newbox")
55 tc.xuntagged(imapclient.UntaggedList{Flags: []string{`\Subscribed`}, Separator: '/', Mailbox: "newbox"})
56 tc2.transactf("ok", "noop")
57 tc2.xuntagged(imapclient.UntaggedList{Flags: []string{`\Subscribed`}, Separator: '/', Mailbox: "newbox"})
58
59 // todo: test create+delete+create of a name results in a higher uidvalidity.
60
61 tc.transactf("no", "create /bad/root")
62 tc.transactf("no", "create bad//root") // Cannot have internal duplicate slashes.
63 tc.transactf("no", `create ""`) // Refuse empty mailbox name.
64 // We are not allowing special characters.
65 tc.transactf("bad", `create "\n"`)
66 tc.transactf("bad", `create "\x7f"`)
67 tc.transactf("bad", `create "\x9f"`)
68 tc.transactf("bad", `create "\u2028"`)
69 tc.transactf("bad", `create "\u2029"`)
70 tc.transactf("ok", `create "%%"`)
71 tc.transactf("ok", `create "*"`)
72 tc.transactf("no", `create "#"`) // Leading hash not allowed.
73 tc.transactf("ok", `create "test#"`)
74
75 // UTF-7 checks are only for IMAP4 before rev2 and without UTF8=ACCEPT.
76 tc.transactf("ok", `create "&"`) // Interpreted as UTF-8, no UTF-7.
77 tc2.transactf("bad", `create "&"`) // Bad UTF-7.
78 tc2.transactf("ok", `create "&Jjo-"`) // ☺, valid UTF-7.
79}
80