1package imapserver
2
3import (
4 "testing"
5
6 "github.com/mjl-/mox/imapclient"
7)
8
9func TestCopy(t *testing.T) {
10 testCopy(t, false)
11}
12
13func TestCopyUIDOnly(t *testing.T) {
14 testCopy(t, true)
15}
16
17func testCopy(t *testing.T, uidonly bool) {
18 defer mockUIDValidity()()
19 tc := start(t, uidonly)
20 defer tc.close()
21
22 tc2 := startNoSwitchboard(t, uidonly)
23 defer tc2.closeNoWait()
24
25 tc.login("mjl@mox.example", password0)
26 tc.client.Select("inbox")
27
28 tc2.login("mjl@mox.example", password0)
29 tc2.client.Select("Trash")
30
31 tc.transactf("bad", "copy") // Missing params.
32 tc.transactf("bad", "copy 1") // Missing params.
33 tc.transactf("bad", "copy 1 inbox ") // Leftover.
34
35 // Seqs 1,2 and UIDs 3,4.
36 tc.client.Append("inbox", makeAppend(exampleMsg))
37 tc.client.Append("inbox", makeAppend(exampleMsg))
38 tc.transactf("ok", `Uid Store 1:2 +Flags.Silent (\Deleted)`)
39 tc.client.Expunge()
40 tc.client.Append("inbox", makeAppend(exampleMsg))
41 tc.client.Append("inbox", makeAppend(exampleMsg))
42
43 if uidonly {
44 tc.transactf("ok", "uid copy 3:* Trash")
45 } else {
46 tc.transactf("no", "copy 1 nonexistent")
47 tc.xcodeWord("TRYCREATE")
48 tc.transactf("no", "copy 1 expungebox")
49 tc.xcodeWord("TRYCREATE")
50
51 tc.transactf("no", "copy 1 inbox") // Cannot copy to same mailbox.
52
53 tc2.transactf("ok", "noop") // Drain.
54
55 tc.transactf("ok", "copy 1:* Trash")
56 tc.xcode(mustParseCode("COPYUID 1 3:4 1:2"))
57 }
58 tc2.transactf("ok", "noop")
59 tc2.xuntagged(
60 imapclient.UntaggedExists(2),
61 tc2.untaggedFetch(1, 1, imapclient.FetchFlags(nil)),
62 tc2.untaggedFetch(2, 2, imapclient.FetchFlags(nil)),
63 )
64
65 tc.transactf("no", "uid copy 1,2 Trash") // No match.
66 tc.transactf("ok", "uid copy 4,3 Trash")
67 tc.xcode(mustParseCode("COPYUID 1 3:4 3:4"))
68 tc2.transactf("ok", "noop")
69 tc2.xuntagged(
70 imapclient.UntaggedExists(4),
71 tc2.untaggedFetch(3, 3, imapclient.FetchFlags(nil)),
72 tc2.untaggedFetch(4, 4, imapclient.FetchFlags(nil)),
73 )
74
75 tclimit := startArgs(t, uidonly, false, false, true, true, "limit")
76 defer tclimit.close()
77 tclimit.login("limit@mox.example", password0)
78 tclimit.client.Select("inbox")
79 // First message of 1 byte is within limits.
80 tclimit.transactf("ok", "append inbox (\\Seen Label1 $label2) \" 1-Jan-2022 10:10:00 +0100\" {1+}\r\nx")
81 tclimit.xuntagged(imapclient.UntaggedExists(1))
82 // Second message would take account past limit.
83 tclimit.transactf("no", "uid copy 1:* Trash")
84 tclimit.xcodeWord("OVERQUOTA")
85}
86