1package imapserver
2
3import (
4 "testing"
5
6 "github.com/mjl-/mox/imapclient"
7)
8
9func TestExpunge(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("inbox")
22
23 tc.transactf("bad", "expunge leftover") // Leftover data.
24 tc.transactf("ok", "expunge") // Nothing to remove though.
25 tc.xuntagged()
26
27 tc.client.Unselect()
28 tc.client.Examine("inbox")
29 tc.transactf("no", "expunge") // Read-only.
30 tc.transactf("no", "uid expunge 1") // Read-only.
31
32 tc.client.Unselect()
33 tc.client.Select("inbox")
34 tc.client.Append("inbox", nil, nil, []byte(exampleMsg))
35 tc.client.Append("inbox", nil, nil, []byte(exampleMsg))
36 tc.client.Append("inbox", nil, nil, []byte(exampleMsg))
37 tc.transactf("ok", "expunge") // Still nothing to remove.
38 tc.xuntagged()
39
40 tc.client.StoreFlagsAdd("1,3", true, `\Deleted`)
41
42 tc2.transactf("ok", "noop") // Drain.
43
44 tc.transactf("ok", "expunge")
45 tc.xuntagged(imapclient.UntaggedExpunge(1), imapclient.UntaggedExpunge(2))
46
47 tc2.transactf("ok", "noop") // Drain.
48 tc2.xuntagged(imapclient.UntaggedExpunge(1), imapclient.UntaggedExpunge(2))
49
50 tc.transactf("ok", "expunge") // Nothing to remove anymore.
51 tc.xuntagged()
52
53 // Only UID 2 is still left. We'll add 3 more. Getting us to UIDs 2,4,5,6.
54 tc.client.Append("inbox", nil, nil, []byte(exampleMsg))
55 tc.client.Append("inbox", nil, nil, []byte(exampleMsg))
56 tc.client.Append("inbox", nil, nil, []byte(exampleMsg))
57
58 tc.transactf("bad", "uid expunge") // Missing uid set.
59 tc.transactf("bad", "uid expunge 1 leftover") // Leftover data.
60 tc.transactf("bad", "uid expunge 1 leftover") // Leftover data.
61
62 tc.client.StoreFlagsAdd("1,2,4", true, `\Deleted`) // Marks UID 2,4,6 as deleted.
63
64 tc.transactf("ok", "uid expunge 1")
65 tc.xuntagged() // No match.
66
67 tc2.transactf("ok", "noop") // Drain.
68
69 tc.transactf("ok", "uid expunge 4:6") // Removes UID 4,6 at seqs 2,4.
70 tc.xuntagged(imapclient.UntaggedExpunge(2), imapclient.UntaggedExpunge(3))
71
72 tc2.transactf("ok", "noop")
73 tc.xuntagged(imapclient.UntaggedExpunge(2), imapclient.UntaggedExpunge(3))
74}
75