mirror of
https://github.com/mjl-/mox.git
synced 2025-06-27 23:08:14 +03:00

Once clients enable this extension, commands can no longer refer to "message sequence numbers" (MSNs), but can only refer to messages with UIDs. This means both sides no longer have to carefully keep their sequence numbers in sync (error-prone), and don't have to keep track of a mapping of sequence numbers to UIDs (saves resources). With UIDONLY enabled, all FETCH responses are replaced with UIDFETCH response.
86 lines
3.3 KiB
Go
86 lines
3.3 KiB
Go
package imapserver
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/mjl-/mox/imapclient"
|
|
)
|
|
|
|
func TestSelect(t *testing.T) {
|
|
testSelectExamine(t, false, false)
|
|
}
|
|
|
|
func TestExamine(t *testing.T) {
|
|
testSelectExamine(t, true, false)
|
|
}
|
|
|
|
func TestSelectUIDOnly(t *testing.T) {
|
|
testSelectExamine(t, false, true)
|
|
}
|
|
|
|
func TestExamineUIDOnly(t *testing.T) {
|
|
testSelectExamine(t, true, true)
|
|
}
|
|
|
|
// select and examine are pretty much the same. but examine opens readonly instead of readwrite.
|
|
func testSelectExamine(t *testing.T, examine, uidonly bool) {
|
|
defer mockUIDValidity()()
|
|
tc := start(t, uidonly)
|
|
defer tc.close()
|
|
|
|
tc.login("mjl@mox.example", password0)
|
|
|
|
cmd := "select"
|
|
okcode := "READ-WRITE"
|
|
if examine {
|
|
cmd = "examine"
|
|
okcode = "READ-ONLY"
|
|
}
|
|
|
|
uclosed := imapclient.UntaggedResult{Status: imapclient.OK, RespText: imapclient.RespText{Code: "CLOSED", More: "x"}}
|
|
flags := strings.Split(`\Seen \Answered \Flagged \Deleted \Draft $Forwarded $Junk $NotJunk $Phishing $MDNSent`, " ")
|
|
permflags := strings.Split(`\Seen \Answered \Flagged \Deleted \Draft $Forwarded $Junk $NotJunk $Phishing $MDNSent \*`, " ")
|
|
uflags := imapclient.UntaggedFlags(flags)
|
|
upermflags := imapclient.UntaggedResult{Status: imapclient.OK, RespText: imapclient.RespText{Code: "PERMANENTFLAGS", CodeArg: imapclient.CodeList{Code: "PERMANENTFLAGS", Args: permflags}, More: "x"}}
|
|
urecent := imapclient.UntaggedRecent(0)
|
|
uexists0 := imapclient.UntaggedExists(0)
|
|
uexists1 := imapclient.UntaggedExists(1)
|
|
uuidval1 := imapclient.UntaggedResult{Status: imapclient.OK, RespText: imapclient.RespText{Code: "UIDVALIDITY", CodeArg: imapclient.CodeUint{Code: "UIDVALIDITY", Num: 1}, More: "x"}}
|
|
uuidnext1 := imapclient.UntaggedResult{Status: imapclient.OK, RespText: imapclient.RespText{Code: "UIDNEXT", CodeArg: imapclient.CodeUint{Code: "UIDNEXT", Num: 1}, More: "x"}}
|
|
ulist := imapclient.UntaggedList{Separator: '/', Mailbox: "Inbox"}
|
|
uunseen := imapclient.UntaggedResult{Status: imapclient.OK, RespText: imapclient.RespText{Code: "UNSEEN", CodeArg: imapclient.CodeUint{Code: "UNSEEN", Num: 1}, More: "x"}}
|
|
uuidnext2 := imapclient.UntaggedResult{Status: imapclient.OK, RespText: imapclient.RespText{Code: "UIDNEXT", CodeArg: imapclient.CodeUint{Code: "UIDNEXT", Num: 2}, More: "x"}}
|
|
|
|
// Parameter required.
|
|
tc.transactf("bad", "%s", cmd)
|
|
|
|
// Mailbox does not exist.
|
|
tc.transactf("no", "%s bogus", cmd)
|
|
tc.transactf("no", "%s expungebox", cmd)
|
|
|
|
tc.transactf("ok", "%s inbox", cmd)
|
|
tc.xuntagged(uflags, upermflags, urecent, uexists0, uuidval1, uuidnext1, ulist)
|
|
tc.xcode(okcode)
|
|
|
|
tc.transactf("ok", `%s "inbox"`, cmd)
|
|
tc.xuntagged(uclosed, uflags, upermflags, urecent, uexists0, uuidval1, uuidnext1, ulist)
|
|
tc.xcode(okcode)
|
|
|
|
// Append a message. It will be reported as UNSEEN.
|
|
tc.client.Append("inbox", makeAppend(exampleMsg))
|
|
tc.transactf("ok", "%s inbox", cmd)
|
|
if uidonly {
|
|
tc.xuntagged(uclosed, uflags, upermflags, urecent, uexists1, uuidval1, uuidnext2, ulist)
|
|
} else {
|
|
tc.xuntagged(uclosed, uflags, upermflags, urecent, uunseen, uexists1, uuidval1, uuidnext2, ulist)
|
|
}
|
|
tc.xcode(okcode)
|
|
|
|
// With imap4rev2, we no longer get untagged RECENT or untagged UNSEEN.
|
|
tc.client.Enable("imap4rev2")
|
|
tc.transactf("ok", "%s inbox", cmd)
|
|
tc.xuntagged(uclosed, uflags, upermflags, uexists1, uuidval1, uuidnext2, ulist)
|
|
tc.xcode(okcode)
|
|
}
|