mirror of
https://github.com/mjl-/mox.git
synced 2025-06-28 01:48:15 +03:00

Keeping the message files around, and the message details in the database, is useful for IMAP sessions that haven't seen/processed the removal of a message yet and try to fetch it. Before, we would return errors. Similarly, a session that has a mailbox selected that is removed can (at least in theory) still read messages. The mechanics to do this need keeping removed mailboxes around too. JMAP needs that anyway, so we now keep modseq/createseq/expunged history for mailboxes too. And while we're at it, for annotations as well. For future JMAP support, we now also keep the mailbox parent id around for a mailbox, with an upgrade step to set the field for existing mailboxes and fixing up potential missing parents (which could possibly have happened in an obscure corner case that I doubt anyone ran into).
66 lines
2.1 KiB
Go
66 lines
2.1 KiB
Go
package imapserver
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/mjl-/mox/imapclient"
|
|
)
|
|
|
|
func TestDelete(t *testing.T) {
|
|
tc := start(t)
|
|
defer tc.close()
|
|
|
|
tc2 := startNoSwitchboard(t)
|
|
defer tc2.closeNoWait()
|
|
|
|
tc3 := startNoSwitchboard(t)
|
|
defer tc3.closeNoWait()
|
|
|
|
tc.client.Login("mjl@mox.example", password0)
|
|
tc2.client.Login("mjl@mox.example", password0)
|
|
tc3.client.Login("mjl@mox.example", password0)
|
|
|
|
tc.transactf("bad", "delete") // Missing mailbox.
|
|
tc.transactf("no", "delete inbox") // Cannot delete inbox.
|
|
tc.transactf("no", "delete nonexistent") // Cannot delete mailbox that does not exist.
|
|
tc.transactf("no", `delete "nonexistent"`) // Again, with quoted string syntax.
|
|
tc.transactf("no", `delete "expungebox"`) // Already removed.
|
|
|
|
tc.client.Subscribe("x")
|
|
tc.transactf("no", "delete x") // Subscription does not mean there is a mailbox that can be deleted.
|
|
|
|
tc.client.Create("a/b", nil)
|
|
tc2.transactf("ok", "noop") // Drain changes.
|
|
tc3.transactf("ok", "noop")
|
|
|
|
// ../rfc/9051:2000
|
|
tc.transactf("no", "delete a") // Still has child.
|
|
tc.xcode("HASCHILDREN")
|
|
|
|
tc3.client.Enable("IMAP4rev2") // For \NonExistent support.
|
|
tc.transactf("ok", "delete a/b")
|
|
tc2.transactf("ok", "noop")
|
|
tc2.xuntagged() // No IMAP4rev2, no \NonExistent.
|
|
tc3.transactf("ok", "noop")
|
|
tc3.xuntagged(imapclient.UntaggedList{Flags: []string{`\NonExistent`}, Separator: '/', Mailbox: "a/b"})
|
|
|
|
tc.transactf("no", "delete a/b") // Already removed.
|
|
tc.transactf("ok", "delete a") // Parent can now be removed.
|
|
tc.transactf("ok", `list (subscribed) "" (a/b a) return (subscribed)`)
|
|
// Subscriptions still exist.
|
|
tc.xuntagged(
|
|
imapclient.UntaggedList{Flags: []string{`\Subscribed`, `\NonExistent`}, Separator: '/', Mailbox: "a"},
|
|
imapclient.UntaggedList{Flags: []string{`\Subscribed`, `\NonExistent`}, Separator: '/', Mailbox: "a/b"},
|
|
)
|
|
|
|
// Let's try again with a message present.
|
|
tc.client.Create("msgs", nil)
|
|
tc.client.Append("msgs", makeAppend(exampleMsg))
|
|
tc.transactf("ok", "delete msgs")
|
|
|
|
// Delete for inbox/* is allowed.
|
|
tc.client.Create("inbox/a", nil)
|
|
tc.transactf("ok", "delete inbox/a")
|
|
|
|
}
|