mirror of
https://github.com/hanzoai/mail.git
synced 2026-09-23 23:53:02 +00:00
Fork of github.com/mjl-/mox at 5656ca6d1b
(upstream v0.0.15 plus 55 commits).
Rename the module path in go.mod and the import paths in 268 Go files. Also
update the five scripts that "go install" the module (genwebsite.sh,
docker-release.sh, apidiff.sh, test-upgrade.sh, Dockerfile.release), which
would otherwise build upstream rather than this fork.
Add NOTICE recording the upstream project, author, license, and fork point,
and stating which license covers which files: MIT for the mox source and our
changes, MPL-2.0 for publicsuffix/public_suffix_list.txt alone, and the
vendored dependencies' own licenses under licenses/. Embed NOTICE so
"mail licenses" prints the lineage from the running binary. LICENSE.MIT,
LICENSE.MPLv2.0 and the licenses/ tree are preserved verbatim; no code is
relicensed.
The mox command name, config keys, data directory layout and website content
are unchanged. LLM.md records the fork point, the rename, what was left alone,
and the steps to stand the server up.
Co-authored-by: Hanzo Dev <[email protected]>
256 lines
8.2 KiB
Go
256 lines
8.2 KiB
Go
package imapserver
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hanzoai/mail/imapclient"
|
|
"github.com/hanzoai/mail/store"
|
|
)
|
|
|
|
func TestListBasic(t *testing.T) {
|
|
testListBasic(t, false)
|
|
}
|
|
|
|
func TestListBasicUIDOnly(t *testing.T) {
|
|
testListBasic(t, true)
|
|
}
|
|
|
|
func testListBasic(t *testing.T, uidonly bool) {
|
|
tc := start(t, uidonly)
|
|
defer tc.close()
|
|
|
|
tc.login("[email protected]", password0)
|
|
|
|
ulist := func(name string, flags ...string) imapclient.UntaggedList {
|
|
if len(flags) == 0 {
|
|
flags = nil
|
|
}
|
|
return imapclient.UntaggedList{Flags: flags, Separator: '/', Mailbox: name}
|
|
}
|
|
|
|
tc.last(tc.client.List("INBOX"))
|
|
tc.xuntagged(ulist("Inbox"))
|
|
|
|
tc.last(tc.client.List("Inbox"))
|
|
tc.xuntagged(ulist("Inbox"))
|
|
|
|
tc.last(tc.client.List("expungebox"))
|
|
tc.xuntagged()
|
|
|
|
tc.last(tc.client.List("%"))
|
|
tc.xuntagged(ulist("Archive", `\Archive`), ulist("Drafts", `\Drafts`), ulist("Inbox"), ulist("Junk", `\Junk`), ulist("Sent", `\Sent`), ulist("Trash", `\Trash`))
|
|
|
|
tc.last(tc.client.List("*"))
|
|
tc.xuntagged(ulist("Archive", `\Archive`), ulist("Drafts", `\Drafts`), ulist("Inbox"), ulist("Junk", `\Junk`), ulist("Sent", `\Sent`), ulist("Trash", `\Trash`))
|
|
|
|
tc.last(tc.client.List("A*"))
|
|
tc.xuntagged(ulist("Archive", `\Archive`))
|
|
|
|
tc.client.Create("Inbox/todo", nil)
|
|
|
|
tc.last(tc.client.List("Inbox*"))
|
|
tc.xuntagged(ulist("Inbox"), ulist("Inbox/todo"))
|
|
|
|
tc.last(tc.client.List("Inbox/%"))
|
|
tc.xuntagged(ulist("Inbox/todo"))
|
|
|
|
tc.last(tc.client.List("Inbox/*"))
|
|
tc.xuntagged(ulist("Inbox/todo"))
|
|
|
|
// Leading full INBOX is turned into Inbox, so mailbox matches.
|
|
tc.last(tc.client.List("INBOX/*"))
|
|
tc.xuntagged(ulist("Inbox/todo"))
|
|
|
|
// No match because we are only touching various casings of the full "INBOX".
|
|
tc.last(tc.client.List("INBO*"))
|
|
tc.xuntagged()
|
|
}
|
|
|
|
func TestListExtended(t *testing.T) {
|
|
testListExtended(t, false)
|
|
}
|
|
|
|
func TestListExtendedUIDOnly(t *testing.T) {
|
|
testListExtended(t, true)
|
|
}
|
|
|
|
func testListExtended(t *testing.T, uidonly bool) {
|
|
defer mockUIDValidity()()
|
|
|
|
tc := start(t, uidonly)
|
|
defer tc.close()
|
|
|
|
tc.login("[email protected]", password0)
|
|
|
|
ulist := func(name string, flags ...string) imapclient.UntaggedList {
|
|
if len(flags) == 0 {
|
|
flags = nil
|
|
}
|
|
return imapclient.UntaggedList{Flags: flags, Separator: '/', Mailbox: name}
|
|
}
|
|
|
|
uidvals := map[string]uint32{}
|
|
use := store.DefaultInitialMailboxes.SpecialUse
|
|
for _, name := range []string{"Inbox", use.Archive, use.Draft, use.Junk, use.Sent, use.Trash} {
|
|
uidvals[name] = 1
|
|
}
|
|
for _, name := range store.DefaultInitialMailboxes.Regular {
|
|
uidvals[name] = 1
|
|
}
|
|
var uidvalnext uint32 = 3
|
|
uidval := func(name string) uint32 {
|
|
v, ok := uidvals[name]
|
|
if !ok {
|
|
v = uidvalnext
|
|
uidvals[name] = v
|
|
uidvalnext++
|
|
}
|
|
return v
|
|
}
|
|
|
|
ustatus := func(name string) imapclient.UntaggedStatus {
|
|
attrs := map[imapclient.StatusAttr]int64{
|
|
imapclient.StatusMessages: 0,
|
|
imapclient.StatusUIDNext: 1,
|
|
imapclient.StatusUIDValidity: int64(uidval(name)),
|
|
imapclient.StatusUnseen: 0,
|
|
imapclient.StatusDeleted: 0,
|
|
imapclient.StatusSize: 0,
|
|
imapclient.StatusRecent: 0,
|
|
imapclient.StatusAppendLimit: 0,
|
|
}
|
|
return imapclient.UntaggedStatus{Mailbox: name, Attrs: attrs}
|
|
}
|
|
|
|
const (
|
|
Fsubscribed = `\Subscribed`
|
|
Fhaschildren = `\HasChildren`
|
|
Fhasnochildren = `\HasNoChildren`
|
|
Fnonexistent = `\NonExistent`
|
|
Farchive = `\Archive`
|
|
Fdraft = `\Drafts`
|
|
Fjunk = `\Junk`
|
|
Fsent = `\Sent`
|
|
Ftrash = `\Trash`
|
|
)
|
|
|
|
// untaggedlist with flags subscribed and hasnochildren
|
|
xlist := func(name string, flags ...string) imapclient.UntaggedList {
|
|
flags = append([]string{Fhasnochildren, Fsubscribed}, flags...)
|
|
return ulist(name, flags...)
|
|
}
|
|
|
|
xchildlist := func(name string, flags ...string) imapclient.UntaggedList {
|
|
u := ulist(name, flags...)
|
|
comp := imapclient.TaggedExtComp{String: "SUBSCRIBED"}
|
|
u.Extended = []imapclient.MboxListExtendedItem{{Tag: "CHILDINFO", Val: imapclient.TaggedExtVal{Comp: &comp}}}
|
|
return u
|
|
}
|
|
|
|
tc.last(tc.client.ListFull(false, "INBOX"))
|
|
tc.xuntagged(xlist("Inbox"), ustatus("Inbox"))
|
|
|
|
tc.last(tc.client.ListFull(false, "Inbox"))
|
|
tc.xuntagged(xlist("Inbox"), ustatus("Inbox"))
|
|
|
|
tc.last(tc.client.ListFull(false, "%"))
|
|
tc.xuntagged(xlist("Archive", Farchive), ustatus("Archive"), xlist("Drafts", Fdraft), ustatus("Drafts"), xlist("Inbox"), ustatus("Inbox"), xlist("Junk", Fjunk), ustatus("Junk"), xlist("Sent", Fsent), ustatus("Sent"), xlist("Trash", Ftrash), ustatus("Trash"))
|
|
|
|
tc.last(tc.client.ListFull(false, "*"))
|
|
tc.xuntagged(xlist("Archive", Farchive), ustatus("Archive"), xlist("Drafts", Fdraft), ustatus("Drafts"), xlist("Inbox"), ustatus("Inbox"), xlist("Junk", Fjunk), ustatus("Junk"), xlist("Sent", Fsent), ustatus("Sent"), xlist("Trash", Ftrash), ustatus("Trash"))
|
|
|
|
tc.last(tc.client.ListFull(false, "A*"))
|
|
tc.xuntagged(xlist("Archive", Farchive), ustatus("Archive"))
|
|
|
|
tc.last(tc.client.ListFull(false, "A*", "Junk"))
|
|
tc.xuntagged(xlist("Archive", Farchive), ustatus("Archive"), xlist("Junk", Fjunk), ustatus("Junk"))
|
|
|
|
tc.client.Create("Inbox/todo", nil)
|
|
|
|
tc.last(tc.client.ListFull(false, "Inbox*"))
|
|
tc.xuntagged(ulist("Inbox", Fhaschildren, Fsubscribed), ustatus("Inbox"), xlist("Inbox/todo"), ustatus("Inbox/todo"))
|
|
|
|
tc.last(tc.client.ListFull(false, "Inbox/%"))
|
|
tc.xuntagged(xlist("Inbox/todo"), ustatus("Inbox/todo"))
|
|
|
|
tc.last(tc.client.ListFull(false, "Inbox/*"))
|
|
tc.xuntagged(xlist("Inbox/todo"), ustatus("Inbox/todo"))
|
|
|
|
// Leading full INBOX is turned into Inbox, so mailbox matches.
|
|
tc.last(tc.client.ListFull(false, "INBOX/*"))
|
|
tc.xuntagged(xlist("Inbox/todo"), ustatus("Inbox/todo"))
|
|
|
|
// No match because we are only touching various casings of the full "INBOX".
|
|
tc.last(tc.client.ListFull(false, "INBO*"))
|
|
tc.xuntagged()
|
|
|
|
tc.last(tc.client.ListFull(true, "Inbox"))
|
|
tc.xuntagged(xchildlist("Inbox", Fsubscribed, Fhaschildren), ustatus("Inbox"))
|
|
|
|
tc.client.Unsubscribe("Inbox")
|
|
tc.last(tc.client.ListFull(true, "Inbox"))
|
|
tc.xuntagged(xchildlist("Inbox", Fhaschildren), ustatus("Inbox"))
|
|
|
|
tc.client.Delete("Inbox/todo") // Still subscribed.
|
|
tc.last(tc.client.ListFull(true, "Inbox"))
|
|
tc.xuntagged(xchildlist("Inbox", Fhasnochildren), ustatus("Inbox"))
|
|
|
|
// Simple extended list without RETURN options.
|
|
tc.transactf("ok", `list "" ("inbox")`)
|
|
tc.xuntagged(ulist("Inbox"))
|
|
|
|
tc.transactf("ok", `list () "" ("inbox") return ()`)
|
|
tc.xuntagged(ulist("Inbox"))
|
|
|
|
tc.transactf("ok", `list "" ("inbox") return ()`)
|
|
tc.xuntagged(ulist("Inbox"))
|
|
|
|
tc.transactf("ok", `list () "" ("inbox")`)
|
|
tc.xuntagged(ulist("Inbox"))
|
|
|
|
tc.transactf("ok", `list (remote) "" ("inbox")`)
|
|
tc.xuntagged(ulist("Inbox"))
|
|
|
|
tc.transactf("ok", `list (remote) "" "/inbox"`)
|
|
tc.xuntagged()
|
|
|
|
tc.transactf("ok", `list (remote) "/inbox" ""`)
|
|
tc.xuntagged()
|
|
|
|
tc.transactf("ok", `list (remote) "inbox" ""`)
|
|
tc.xuntagged()
|
|
|
|
tc.transactf("ok", `list (remote) "inbox" "a"`)
|
|
tc.xuntagged()
|
|
|
|
tc.client.Create("inbox/a", nil)
|
|
tc.transactf("ok", `list (remote) "inbox" "a"`)
|
|
tc.xuntagged(ulist("Inbox/a"))
|
|
|
|
tc.client.Subscribe("x")
|
|
tc.transactf("ok", `list (subscribed) "" x return (subscribed)`)
|
|
tc.xuntagged(imapclient.UntaggedList{Flags: []string{`\Subscribed`, `\NonExistent`}, Separator: '/', Mailbox: "x"})
|
|
|
|
tc.transactf("bad", `list (recursivematch) "" "*"`) // Cannot have recursivematch without a base selection option like subscribed.
|
|
tc.transactf("bad", `list (recursivematch remote) "" "*"`) // "remote" is not a base selection option.
|
|
tc.transactf("bad", `list (unknown) "" "*"`) // Unknown selection options must result in BAD.
|
|
tc.transactf("bad", `list () "" "*" return (unknown)`) // Unknown return options must result in BAD.
|
|
|
|
// Return metadata.
|
|
tc.transactf("ok", `setmetadata inbox (/private/comment "y")`)
|
|
tc.transactf("ok", `list () "" ("inbox") return (metadata (/private/comment /shared/comment))`)
|
|
tc.xuntagged(
|
|
ulist("Inbox"),
|
|
imapclient.UntaggedMetadataAnnotations{
|
|
Mailbox: "Inbox",
|
|
Annotations: []imapclient.Annotation{
|
|
{Key: "/private/comment", IsString: true, Value: []byte("y")},
|
|
{Key: "/shared/comment"},
|
|
},
|
|
},
|
|
)
|
|
|
|
tc.transactf("bad", `list () "" ("inbox") return (metadata ())`) // Metadata list must be non-empty.
|
|
tc.transactf("bad", `list () "" ("inbox") return (metadata (/shared/comment "/private/comment" ))`) // Extra space.
|
|
}
|