6 "github.com/mjl-/mox/imapclient"
9func TestCopy(t *testing.T) {
10 defer mockUIDValidity()()
14 tc2 := startNoSwitchboard(t)
17 tc.client.Login("mjl@mox.example", password0)
18 tc.client.Select("inbox")
20 tc2.client.Login("mjl@mox.example", password0)
21 tc2.client.Select("Trash")
23 tc.transactf("bad", "copy") // Missing params.
24 tc.transactf("bad", "copy 1") // Missing params.
25 tc.transactf("bad", "copy 1 inbox ") // Leftover.
27 // Seqs 1,2 and UIDs 3,4.
28 tc.client.Append("inbox", nil, nil, []byte(exampleMsg))
29 tc.client.Append("inbox", nil, nil, []byte(exampleMsg))
30 tc.client.StoreFlagsSet("1:2", true, `\Deleted`)
32 tc.client.Append("inbox", nil, nil, []byte(exampleMsg))
33 tc.client.Append("inbox", nil, nil, []byte(exampleMsg))
35 tc.transactf("no", "copy 1 nonexistent")
38 tc.transactf("no", "copy 1 inbox") // Cannot copy to same mailbox.
40 tc2.transactf("ok", "noop") // Drain.
42 tc.transactf("ok", "copy 1:* Trash")
43 ptr := func(v uint32) *uint32 { return &v }
44 tc.xcodeArg(imapclient.CodeCopyUID{DestUIDValidity: 1, From: []imapclient.NumRange{{First: 3, Last: ptr(4)}}, To: []imapclient.NumRange{{First: 1, Last: ptr(2)}}})
45 tc2.transactf("ok", "noop")
47 imapclient.UntaggedExists(2),
48 imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(1), imapclient.FetchFlags(nil)}},
49 imapclient.UntaggedFetch{Seq: 2, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(2), imapclient.FetchFlags(nil)}},
52 tc.transactf("no", "uid copy 1,2 Trash") // No match.
53 tc.transactf("ok", "uid copy 4,3 Trash")
54 tc.xcodeArg(imapclient.CodeCopyUID{DestUIDValidity: 1, From: []imapclient.NumRange{{First: 3, Last: ptr(4)}}, To: []imapclient.NumRange{{First: 3, Last: ptr(4)}}})
55 tc2.transactf("ok", "noop")
57 imapclient.UntaggedExists(4),
58 imapclient.UntaggedFetch{Seq: 3, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(3), imapclient.FetchFlags(nil)}},
59 imapclient.UntaggedFetch{Seq: 4, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(4), imapclient.FetchFlags(nil)}},
62 tclimit := startArgs(t, false, false, true, true, "limit")
64 tclimit.client.Login("limit@mox.example", password0)
65 tclimit.client.Select("inbox")
66 // First message of 1 byte is within limits.
67 tclimit.transactf("ok", "append inbox (\\Seen Label1 $label2) \" 1-Jan-2022 10:10:00 +0100\" {1+}\r\nx")
68 tclimit.xuntagged(imapclient.UntaggedExists(1))
69 // Second message would take account past limit.
70 tclimit.transactf("no", "copy 1:* Trash")
71 tclimit.xcode("OVERQUOTA")