mirror of
https://github.com/mjl-/mox.git
synced 2025-07-19 03:26:37 +03:00
imapserver: implement UIDONLY extension, RFC 9586
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.
This commit is contained in:
@ -8,63 +8,74 @@ import (
|
||||
)
|
||||
|
||||
func TestStore(t *testing.T) {
|
||||
tc := start(t)
|
||||
testStore(t, false)
|
||||
}
|
||||
|
||||
func TestStoreUIDOnly(t *testing.T) {
|
||||
testStore(t, true)
|
||||
}
|
||||
|
||||
func testStore(t *testing.T, uidonly bool) {
|
||||
tc := start(t, uidonly)
|
||||
defer tc.close()
|
||||
|
||||
tc.client.Login("mjl@mox.example", password0)
|
||||
tc.login("mjl@mox.example", password0)
|
||||
tc.client.Enable("imap4rev2")
|
||||
|
||||
tc.client.Append("inbox", makeAppend(exampleMsg))
|
||||
tc.client.Select("inbox")
|
||||
|
||||
uid1 := imapclient.FetchUID(1)
|
||||
noflags := imapclient.FetchFlags(nil)
|
||||
|
||||
tc.transactf("ok", "store 1 flags.silent ()")
|
||||
if !uidonly {
|
||||
tc.transactf("ok", "store 1 flags.silent ()")
|
||||
tc.xuntagged()
|
||||
}
|
||||
|
||||
tc.transactf("ok", `uid store 1 flags ()`)
|
||||
tc.xuntagged(tc.untaggedFetch(1, 1, noflags))
|
||||
tc.transactf("ok", `uid fetch 1 flags`)
|
||||
tc.xuntagged(tc.untaggedFetch(1, 1, noflags))
|
||||
|
||||
tc.transactf("ok", `uid store 1 flags.silent (\Seen)`)
|
||||
tc.xuntagged()
|
||||
tc.transactf("ok", `uid fetch 1 flags`)
|
||||
tc.xuntagged(tc.untaggedFetch(1, 1, imapclient.FetchFlags{`\Seen`}))
|
||||
|
||||
tc.transactf("ok", `store 1 flags ()`)
|
||||
tc.xuntagged(imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{uid1, noflags}})
|
||||
tc.transactf("ok", `fetch 1 flags`)
|
||||
tc.xuntagged(imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{uid1, noflags}})
|
||||
tc.transactf("ok", `uid store 1 flags ($Junk)`)
|
||||
tc.xuntagged(tc.untaggedFetch(1, 1, imapclient.FetchFlags{`$Junk`}))
|
||||
tc.transactf("ok", `uid fetch 1 flags`)
|
||||
tc.xuntagged(tc.untaggedFetch(1, 1, imapclient.FetchFlags{`$Junk`}))
|
||||
|
||||
tc.transactf("ok", `store 1 flags.silent (\Seen)`)
|
||||
tc.xuntagged()
|
||||
tc.transactf("ok", `fetch 1 flags`)
|
||||
tc.xuntagged(imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{uid1, imapclient.FetchFlags{`\Seen`}}})
|
||||
tc.transactf("ok", `uid store 1 +flags ()`)
|
||||
tc.xuntagged(tc.untaggedFetch(1, 1, imapclient.FetchFlags{`$Junk`}))
|
||||
tc.transactf("ok", `uid store 1 +flags (\Deleted)`)
|
||||
tc.xuntagged(tc.untaggedFetch(1, 1, imapclient.FetchFlags{`\Deleted`, `$Junk`}))
|
||||
tc.transactf("ok", `uid fetch 1 flags`)
|
||||
tc.xuntagged(tc.untaggedFetch(1, 1, imapclient.FetchFlags{`\Deleted`, `$Junk`}))
|
||||
|
||||
tc.transactf("ok", `store 1 flags ($Junk)`)
|
||||
tc.xuntagged(imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{uid1, imapclient.FetchFlags{`$Junk`}}})
|
||||
tc.transactf("ok", `fetch 1 flags`)
|
||||
tc.xuntagged(imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{uid1, imapclient.FetchFlags{`$Junk`}}})
|
||||
tc.transactf("ok", `uid store 1 -flags \Deleted $Junk`)
|
||||
tc.xuntagged(tc.untaggedFetch(1, 1, noflags))
|
||||
tc.transactf("ok", `uid fetch 1 flags`)
|
||||
tc.xuntagged(tc.untaggedFetch(1, 1, noflags))
|
||||
|
||||
tc.transactf("ok", `store 1 +flags ()`)
|
||||
tc.xuntagged(imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{uid1, imapclient.FetchFlags{`$Junk`}}})
|
||||
tc.transactf("ok", `store 1 +flags (\Deleted)`)
|
||||
tc.xuntagged(imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{uid1, imapclient.FetchFlags{`\Deleted`, `$Junk`}}})
|
||||
tc.transactf("ok", `fetch 1 flags`)
|
||||
tc.xuntagged(imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{uid1, imapclient.FetchFlags{`\Deleted`, `$Junk`}}})
|
||||
|
||||
tc.transactf("ok", `store 1 -flags \Deleted $Junk`)
|
||||
tc.xuntagged(imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{uid1, noflags}})
|
||||
tc.transactf("ok", `fetch 1 flags`)
|
||||
tc.xuntagged(imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{uid1, noflags}})
|
||||
|
||||
tc.transactf("bad", "store 2 flags ()") // ../rfc/9051:7018
|
||||
if !uidonly {
|
||||
tc.transactf("bad", "store 2 flags ()") // ../rfc/9051:7018
|
||||
}
|
||||
|
||||
tc.transactf("ok", "uid store 1 flags ()")
|
||||
tc.xuntagged(imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{uid1, noflags}})
|
||||
tc.xuntagged(tc.untaggedFetch(1, 1, noflags))
|
||||
|
||||
tc.transactf("ok", "store 1 flags (new)") // New flag.
|
||||
tc.xuntagged(imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{uid1, imapclient.FetchFlags{"new"}}})
|
||||
tc.transactf("ok", "store 1 flags (new new a b c)") // Duplicates are ignored.
|
||||
tc.xuntagged(imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{uid1, imapclient.FetchFlags{"a", "b", "c", "new"}}})
|
||||
tc.transactf("ok", "store 1 +flags (new new c d e)")
|
||||
tc.xuntagged(imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{uid1, imapclient.FetchFlags{"a", "b", "c", "d", "e", "new"}}})
|
||||
tc.transactf("ok", "store 1 -flags (new new e a c)")
|
||||
tc.xuntagged(imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{uid1, imapclient.FetchFlags{"b", "d"}}})
|
||||
tc.transactf("ok", "store 1 flags ($Forwarded Different)")
|
||||
tc.xuntagged(imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{uid1, imapclient.FetchFlags{"$Forwarded", "different"}}})
|
||||
tc.transactf("ok", "uid store 1 flags (new)") // New flag.
|
||||
tc.xuntagged(tc.untaggedFetch(1, 1, imapclient.FetchFlags{"new"}))
|
||||
tc.transactf("ok", "uid store 1 flags (new new a b c)") // Duplicates are ignored.
|
||||
tc.xuntagged(tc.untaggedFetch(1, 1, imapclient.FetchFlags{"a", "b", "c", "new"}))
|
||||
tc.transactf("ok", "uid store 1 +flags (new new c d e)")
|
||||
tc.xuntagged(tc.untaggedFetch(1, 1, imapclient.FetchFlags{"a", "b", "c", "d", "e", "new"}))
|
||||
tc.transactf("ok", "uid store 1 -flags (new new e a c)")
|
||||
tc.xuntagged(tc.untaggedFetch(1, 1, imapclient.FetchFlags{"b", "d"}))
|
||||
tc.transactf("ok", "uid store 1 flags ($Forwarded Different)")
|
||||
tc.xuntagged(tc.untaggedFetch(1, 1, imapclient.FetchFlags{"$Forwarded", "different"}))
|
||||
|
||||
tc.transactf("bad", "store") // Need numset, flags and args.
|
||||
tc.transactf("bad", "store 1") // Need flags.
|
||||
@ -80,5 +91,5 @@ func TestStore(t *testing.T) {
|
||||
flags := strings.Split(`\Seen \Answered \Flagged \Deleted \Draft $Forwarded $Junk $NotJunk $Phishing $MDNSent a b c d different e new`, " ")
|
||||
tc.xuntaggedOpt(false, imapclient.UntaggedFlags(flags))
|
||||
|
||||
tc.transactf("no", `store 1 flags ()`) // No permission to set flags.
|
||||
tc.transactf("no", `uid store 1 flags ()`) // No permission to set flags.
|
||||
}
|
||||
|
Reference in New Issue
Block a user