File: select_test.go

package info (click to toggle)
golang-github-protonmail-gluon 0.17.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 16,020 kB
  • sloc: sh: 55; makefile: 5
file content (82 lines) | stat: -rw-r--r-- 2,676 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package tests

import (
	"testing"

	"github.com/ProtonMail/gluon/imap"
)

func TestSelect(t *testing.T) {
	runOneToOneTestWithAuth(t, defaultServerOptions(t, withUIDValidityGenerator(imap.NewFixedUIDValidityGenerator(imap.UID(1)))), func(c *testConnection, _ *testSession) {
		c.C("A002 CREATE Archive")
		c.OK("A002")

		c.doAppend(`INBOX`, buildRFC5322TestLiteral(`To: 1@pm.me`), `\Seen`).expect("OK")
		c.doAppend(`INBOX`, buildRFC5322TestLiteral(`To: 2@pm.me`)).expect("OK")
		c.doAppend(`Archive`, buildRFC5322TestLiteral(`To: 3@pm.me`), `\Seen`).expect("OK")

		c.C("A006 select INBOX")
		c.S(`* FLAGS (\Deleted \Flagged \Seen)`,
			`* 2 EXISTS`,
			`* 2 RECENT`,
			`* OK [UNSEEN 2] Unseen messages`,
			`* OK [PERMANENTFLAGS (\Deleted \Flagged \Seen)] Flags permitted`,
			`* OK [UIDNEXT 3] Predicted next UID`,
			`* OK [UIDVALIDITY 1] UIDs valid`)
		c.S("A006 OK [READ-WRITE] SELECT")

		// Selecting again modifies the RECENT value.
		c.C("A006 select INBOX")
		c.S(`* FLAGS (\Deleted \Flagged \Seen)`,
			`* 2 EXISTS`,
			`* 0 RECENT`,
			`* OK [UNSEEN 2] Unseen messages`,
			`* OK [PERMANENTFLAGS (\Deleted \Flagged \Seen)] Flags permitted`,
			`* OK [UIDNEXT 3] Predicted next UID`,
			`* OK [UIDVALIDITY 1] UIDs valid`)
		c.S("A006 OK [READ-WRITE] SELECT")

		c.C("A007 select Archive")
		c.S(`* FLAGS (\Deleted \Flagged \Seen)`,
			`* 1 EXISTS`,
			`* 1 RECENT`,
			`* OK [PERMANENTFLAGS (\Deleted \Flagged \Seen)] Flags permitted`,
			`* OK [UIDNEXT 2] Predicted next UID`,
			`* OK [UIDVALIDITY 1] UIDs valid`)
		c.S(`A007 OK [READ-WRITE] SELECT`)
	})
}

func TestSelectNoSuchMailbox(t *testing.T) {
	runOneToOneTestWithAuth(t, defaultServerOptions(t), func(c *testConnection, _ *testSession) {
		c.C("a003 select What")
		c.Sx("a003 NO .*")
	})
}

func TestSelectUTF7(t *testing.T) {
	runOneToOneTestWithAuth(t, defaultServerOptions(t), func(c *testConnection, _ *testSession) {
		// Test we can create a mailbox with a UTF-7 name.
		c.C("A003 CREATE &ZeVnLIqe-").OK("A003")

		// Test we can select the mailbox.
		c.C("A004 SELECT &ZeVnLIqe-").OK("A004")

		// The mailbox should appear in LIST responses with the same UTF-7 encoding.
		c.C(`A005 LIST "" "*"`).Sxe(`&ZeVnLIqe-`).OK(`A005`)
	})
}

func TestSelectWithNilDelimiter(t *testing.T) {
	runOneToOneTestWithAuth(t, defaultServerOptions(t, withDelimiter("")), func(c *testConnection, _ *testSession) {
		// Test we can create a mailbox with a UTF-7 name.
		c.C("a CREATE A").OK("a")
		c.C("a CREATE A/B").OK("a")
		c.C("a CREATE A/B/C").OK("a")

		// Test we can select the mailbox.
		c.C("A001 SELECT A").OK("A001")
		c.C("A002 SELECT A/B").OK("A002")
		c.C("A003 SELECT A/B/C").OK("A003")
	})
}