mirror of
https://github.com/mjl-/mox.git
synced 2024-12-28 01:13:47 +03:00
7f1b7198a8
for conditional storing and quick resynchronisation (not sure if mail clients are actually using it that). each message now has a "modseq". it is increased for each change. with condstore, imap clients can request changes since a certain modseq. that already allows quickly finding changes since a previous connection. condstore also allows storing (e.g. setting new message flags) only when the modseq of a message hasn't changed. qresync should make it fast for clients to get a full list of changed messages for a mailbox, including removals. we now also keep basic metadata of messages that have been removed (expunged). just enough (uid, modseq) to tell client that the messages have been removed. this does mean we have to be careful when querying messages from the database. we must now often filter the expunged messages out. we also keep "createseq", the modseq when a message was created. this will be useful for the jmap implementation.
84 lines
3.8 KiB
Go
84 lines
3.8 KiB
Go
package imapserver
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/mjl-/mox/imapclient"
|
|
)
|
|
|
|
func TestStore(t *testing.T) {
|
|
tc := start(t)
|
|
defer tc.close()
|
|
|
|
tc.client.Login("mjl@mox.example", "testtest")
|
|
tc.client.Enable("imap4rev2")
|
|
|
|
tc.client.Append("inbox", nil, nil, []byte(exampleMsg))
|
|
tc.client.Select("inbox")
|
|
|
|
uid1 := imapclient.FetchUID(1)
|
|
noflags := imapclient.FetchFlags(nil)
|
|
|
|
tc.transactf("ok", "store 1 flags.silent ()")
|
|
tc.xuntagged()
|
|
|
|
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", `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", `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", `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
|
|
|
|
tc.transactf("ok", "uid store 1 flags ()")
|
|
tc.xuntagged(imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{uid1, 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{"new", "a", "b", "c"}}})
|
|
tc.transactf("ok", "store 1 +flags (new new c d e)")
|
|
tc.xuntagged(imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{uid1, imapclient.FetchFlags{"new", "a", "b", "c", "d", "e"}}})
|
|
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("bad", "store") // Need numset, flags and args.
|
|
tc.transactf("bad", "store 1") // Need flags.
|
|
tc.transactf("bad", "store 1 +") // Need flags.
|
|
tc.transactf("bad", "store 1 -") // Need flags.
|
|
tc.transactf("bad", "store 1 flags ") // Need flags.
|
|
tc.transactf("bad", "store 1 flags ") // Need flags.
|
|
|
|
tc.client.Unselect()
|
|
tc.transactf("ok", "examine inbox") // Open read-only.
|
|
|
|
// Flags are added to mailbox, not removed.
|
|
flags := strings.Split(`\Seen \Answered \Flagged \Deleted \Draft $Forwarded $Junk $NotJunk $Phishing $MDNSent new a b c d e different`, " ")
|
|
tc.xuntaggedOpt(false, imapclient.UntaggedFlags(flags))
|
|
|
|
tc.transactf("no", `store 1 flags ()`) // No permission to set flags.
|
|
}
|