1package imapserver
2
3import (
4 "testing"
5
6 "github.com/mjl-/mox/imapclient"
7)
8
9func TestMove(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 tc3 := startNoSwitchboard(t)
18 defer tc3.close()
19
20 tc.client.Login("mjl@mox.example", password0)
21 tc.client.Select("inbox")
22
23 tc2.client.Login("mjl@mox.example", password0)
24 tc2.client.Select("Trash")
25
26 tc3.client.Login("mjl@mox.example", password0)
27 tc3.client.Select("inbox")
28
29 tc.transactf("bad", "move") // Missing params.
30 tc.transactf("bad", "move 1") // Missing params.
31 tc.transactf("bad", "move 1 inbox ") // Leftover.
32
33 // Seqs 1,2 and UIDs 3,4.
34 tc.client.Append("inbox", nil, nil, []byte(exampleMsg))
35 tc.client.Append("inbox", nil, nil, []byte(exampleMsg))
36 tc.client.StoreFlagsSet("1:2", true, `\Deleted`)
37 tc.client.Expunge()
38 tc.client.Append("inbox", nil, nil, []byte(exampleMsg))
39 tc.client.Append("inbox", nil, nil, []byte(exampleMsg))
40
41 tc.client.Unselect()
42 tc.client.Examine("inbox")
43 tc.transactf("no", "move 1 Trash") // Opened readonly.
44 tc.client.Unselect()
45 tc.client.Select("inbox")
46
47 tc.transactf("no", "move 1 nonexistent")
48 tc.xcode("TRYCREATE")
49
50 tc.transactf("no", "move 1 inbox") // Cannot move to same mailbox.
51
52 tc2.transactf("ok", "noop") // Drain.
53 tc3.transactf("ok", "noop") // Drain.
54
55 tc.transactf("ok", "move 1:* Trash")
56 ptr := func(v uint32) *uint32 { return &v }
57 tc.xuntagged(
58 imapclient.UntaggedResult{Status: "OK", RespText: imapclient.RespText{Code: "COPYUID", CodeArg: imapclient.CodeCopyUID{DestUIDValidity: 1, From: []imapclient.NumRange{{First: 3, Last: ptr(4)}}, To: []imapclient.NumRange{{First: 1, Last: ptr(2)}}}, More: "moved"}},
59 imapclient.UntaggedExpunge(1),
60 imapclient.UntaggedExpunge(1),
61 )
62 tc2.transactf("ok", "noop")
63 tc2.xuntagged(
64 imapclient.UntaggedExists(2),
65 imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(1), imapclient.FetchFlags(nil)}},
66 imapclient.UntaggedFetch{Seq: 2, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(2), imapclient.FetchFlags(nil)}},
67 )
68 tc3.transactf("ok", "noop")
69 tc3.xuntagged(imapclient.UntaggedExpunge(1), imapclient.UntaggedExpunge(1))
70
71 // UIDs 5,6
72 tc.client.Append("inbox", nil, nil, []byte(exampleMsg))
73 tc.client.Append("inbox", nil, nil, []byte(exampleMsg))
74 tc2.transactf("ok", "noop") // Drain.
75 tc3.transactf("ok", "noop") // Drain.
76
77 tc.transactf("no", "uid move 1:4 Trash") // No match.
78 tc.transactf("ok", "uid move 6:5 Trash")
79 tc.xuntagged(
80 imapclient.UntaggedResult{Status: "OK", RespText: imapclient.RespText{Code: "COPYUID", CodeArg: imapclient.CodeCopyUID{DestUIDValidity: 1, From: []imapclient.NumRange{{First: 5, Last: ptr(6)}}, To: []imapclient.NumRange{{First: 3, Last: ptr(4)}}}, More: "moved"}},
81 imapclient.UntaggedExpunge(1),
82 imapclient.UntaggedExpunge(1),
83 )
84 tc2.transactf("ok", "noop")
85 tc2.xuntagged(
86 imapclient.UntaggedExists(4),
87 imapclient.UntaggedFetch{Seq: 3, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(3), imapclient.FetchFlags(nil)}},
88 imapclient.UntaggedFetch{Seq: 4, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(4), imapclient.FetchFlags(nil)}},
89 )
90 tc3.transactf("ok", "noop")
91 tc3.xuntagged(imapclient.UntaggedExpunge(1), imapclient.UntaggedExpunge(1))
92}
93