1package imapserver
2
3import (
4 "testing"
5
6 "github.com/mjl-/mox/imapclient"
7)
8
9func TestCopy(t *testing.T) {
10 defer mockUIDValidity()()
11 tc := start(t)
12 defer tc.close()
13
14 tc2 := startNoSwitchboard(t)
15 defer tc2.close()
16
17 tc.client.Login("mjl@mox.example", password0)
18 tc.client.Select("inbox")
19
20 tc2.client.Login("mjl@mox.example", password0)
21 tc2.client.Select("Trash")
22
23 tc.transactf("bad", "copy") // Missing params.
24 tc.transactf("bad", "copy 1") // Missing params.
25 tc.transactf("bad", "copy 1 inbox ") // Leftover.
26
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`)
31 tc.client.Expunge()
32 tc.client.Append("inbox", nil, nil, []byte(exampleMsg))
33 tc.client.Append("inbox", nil, nil, []byte(exampleMsg))
34
35 tc.transactf("no", "copy 1 nonexistent")
36 tc.xcode("TRYCREATE")
37
38 tc.transactf("no", "copy 1 inbox") // Cannot copy to same mailbox.
39
40 tc2.transactf("ok", "noop") // Drain.
41
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")
46 tc2.xuntagged(
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)}},
50 )
51
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")
56 tc2.xuntagged(
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)}},
60 )
61
62 tclimit := startArgs(t, false, false, true, true, "limit")
63 defer tclimit.close()
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")
72}
73