Files
mail/store/import_test.go
zeekayandHanzo Dev 15909c7b79 Rename Go module path to github.com/hanzoai/mail
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]>
2026-07-27 23:16:19 -07:00

101 lines
2.4 KiB
Go

package store
import (
"io"
"os"
"strings"
"testing"
"github.com/hanzoai/mail/mlog"
)
func TestMboxReader(t *testing.T) {
createTemp := func(log mlog.Log, pattern string) (*os.File, error) {
return os.CreateTemp("", pattern)
}
mboxf, err := os.Open("../testdata/importtest.mbox")
if err != nil {
t.Fatalf("open mbox: %v", err)
}
defer mboxf.Close()
log := mlog.New("mboxreader", nil)
mr := NewMboxReader(log, createTemp, mboxf.Name(), mboxf)
_, mf0, _, err := mr.Next()
if err != nil {
t.Fatalf("next mbox message: %v", err)
}
defer os.Remove(mf0.Name())
defer mf0.Close()
_, mf1, _, err := mr.Next()
if err != nil {
t.Fatalf("next mbox message: %v", err)
}
defer os.Remove(mf1.Name())
defer mf1.Close()
_, _, _, err = mr.Next()
if err != io.EOF {
t.Fatalf("got err %v, expected eof for next mbox message", err)
}
}
func TestMaildirReader(t *testing.T) {
createTemp := func(log mlog.Log, pattern string) (*os.File, error) {
return os.CreateTemp("", pattern)
}
// todo: rename 1642966915.1.mox to "1642966915.1.mox:2,"? cannot have that name in the git repo because go module (or the proxy) doesn't like it. could also add some flags and test they survive the import.
newf, err := os.Open("../testdata/importtest.maildir/new")
if err != nil {
t.Fatalf("open maildir new: %v", err)
}
defer newf.Close()
curf, err := os.Open("../testdata/importtest.maildir/cur")
if err != nil {
t.Fatalf("open maildir cur: %v", err)
}
defer curf.Close()
log := mlog.New("maildirreader", nil)
mr := NewMaildirReader(log, createTemp, newf, curf)
_, mf0, _, err := mr.Next()
if err != nil {
t.Fatalf("next maildir message: %v", err)
}
defer os.Remove(mf0.Name())
defer mf0.Close()
_, mf1, _, err := mr.Next()
if err != nil {
t.Fatalf("next maildir message: %v", err)
}
defer os.Remove(mf1.Name())
defer mf1.Close()
_, _, _, err = mr.Next()
if err != io.EOF {
t.Fatalf("got err %v, expected eof for next maildir message", err)
}
}
func TestParseDovecotKeywords(t *testing.T) {
const data = `0 Old
1 Junk
2 NonJunk
3 $Forwarded
4 $Junk
`
flags, err := ParseDovecotKeywordsFlags(strings.NewReader(data), mlog.New("dovecotkeywords", nil))
if err != nil {
t.Fatalf("parsing dovecot-keywords: %v", err)
}
got := strings.Join(flags, ",")
want := "old,junk,nonjunk,$forwarded,$junk"
if got != want {
t.Fatalf("parsing dovecot keywords, got %q, expect %q", got, want)
}
}