9 "github.com/mjl-/mox/mlog"
12func TestMboxReader(t *testing.T) {
13 createTemp := func(log mlog.Log, pattern string) (*os.File, error) {
14 return os.CreateTemp("", pattern)
16 mboxf, err := os.Open("../testdata/importtest.mbox")
18 t.Fatalf("open mbox: %v", err)
22 log := mlog.New("mboxreader", nil)
23 mr := NewMboxReader(log, createTemp, mboxf.Name(), mboxf)
24 _, mf0, _, err := mr.Next()
26 t.Fatalf("next mbox message: %v", err)
28 defer os.Remove(mf0.Name())
31 _, mf1, _, err := mr.Next()
33 t.Fatalf("next mbox message: %v", err)
35 defer os.Remove(mf1.Name())
38 _, _, _, err = mr.Next()
40 t.Fatalf("got err %v, expected eof for next mbox message", err)
44func TestMaildirReader(t *testing.T) {
45 createTemp := func(log mlog.Log, pattern string) (*os.File, error) {
46 return os.CreateTemp("", pattern)
48 // 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.
49 newf, err := os.Open("../testdata/importtest.maildir/new")
51 t.Fatalf("open maildir new: %v", err)
55 curf, err := os.Open("../testdata/importtest.maildir/cur")
57 t.Fatalf("open maildir cur: %v", err)
61 log := mlog.New("maildirreader", nil)
62 mr := NewMaildirReader(log, createTemp, newf, curf)
63 _, mf0, _, err := mr.Next()
65 t.Fatalf("next maildir message: %v", err)
67 defer os.Remove(mf0.Name())
70 _, mf1, _, err := mr.Next()
72 t.Fatalf("next maildir message: %v", err)
74 defer os.Remove(mf1.Name())
77 _, _, _, err = mr.Next()
79 t.Fatalf("got err %v, expected eof for next maildir message", err)
83func TestParseDovecotKeywords(t *testing.T) {
90 flags, err := ParseDovecotKeywordsFlags(strings.NewReader(data), mlog.New("dovecotkeywords", nil))
92 t.Fatalf("parsing dovecot-keywords: %v", err)
94 got := strings.Join(flags, ",")
95 want := "old,junk,nonjunk,$forwarded,$junk"
97 t.Fatalf("parsing dovecot keywords, got %q, expect %q", got, want)