6 "github.com/mjl-/mox/imapclient"
9func TestCreate(t *testing.T) {
13 tc2 := startNoSwitchboard(t)
16 tc.client.Login("mjl@mox.example", password0)
17 tc2.client.Login("mjl@mox.example", password0)
20 tc.transactf("no", "create Inbox") // Idem.
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"})
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"})
29 tc.transactf("no", "create inbox/a/c") // Exists.
31 tc.transactf("ok", "create inbox/a/x")
32 tc.xuntagged(imapclient.UntaggedList{Flags: []string{`\Subscribed`}, Separator: '/', Mailbox: "Inbox/a/x"})
34 tc2.transactf("ok", "noop")
35 tc2.xuntagged(imapclient.UntaggedList{Flags: []string{`\Subscribed`}, Separator: '/', Mailbox: "Inbox/a/x"})
38 tc.transactf("ok", "create mailbox/")
39 tc.xuntagged(imapclient.UntaggedList{Flags: []string{`\Subscribed`}, Separator: '/', Mailbox: "mailbox"})
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/"})
46 tc2.transactf("ok", "noop")
47 tc2.xuntagged(imapclient.UntaggedList{Flags: []string{`\Subscribed`}, Separator: '/', Mailbox: "mailbox"}, imapclient.UntaggedList{Flags: []string{`\Subscribed`}, Separator: '/', Mailbox: "mailbox2"})
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"})
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"})
59 // todo: test create+delete+create of a name results in a higher uidvalidity.
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#"`)
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.