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]>
100 lines
2.6 KiB
Go
100 lines
2.6 KiB
Go
package store
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/mjl-/bstore"
|
|
|
|
"github.com/hanzoai/mail/message"
|
|
"github.com/hanzoai/mail/mlog"
|
|
"github.com/hanzoai/mail/mox-"
|
|
)
|
|
|
|
func TestReparse(t *testing.T) {
|
|
log := mlog.New("store", nil)
|
|
os.RemoveAll("../testdata/store/data")
|
|
mox.ConfigStaticPath = filepath.FromSlash("../testdata/store/mox.conf")
|
|
mox.MustLoadConfig(true, false)
|
|
err := Init(ctxbg)
|
|
tcheck(t, err, "init")
|
|
defer func() {
|
|
err := Close()
|
|
tcheck(t, err, "close")
|
|
}()
|
|
defer Switchboard()()
|
|
|
|
orig := reparseMessageBatchSize
|
|
reparseMessageBatchSize = 2
|
|
defer func() {
|
|
reparseMessageBatchSize = orig
|
|
}()
|
|
|
|
acc, err := OpenAccount(log, "mjl", false)
|
|
tcheck(t, err, "open account")
|
|
|
|
// Prepare message to add later.
|
|
msgFile, err := CreateMessageTemp(log, "account-test")
|
|
tcheck(t, err, "create temp message file")
|
|
defer CloseRemoveTempFile(log, msgFile, "temp message file")
|
|
msgWriter := message.NewWriter(msgFile)
|
|
_, err = msgWriter.Write([]byte(" message"))
|
|
tcheck(t, err, "write message")
|
|
|
|
msgPrefix := []byte("From: <[email protected]\r\nTo: <[email protected]>\r\nCc: <[email protected]>Subject: test\r\nMessage-Id: <[email protected]>\r\n\r\n")
|
|
m := Message{
|
|
Received: time.Now(),
|
|
Size: int64(len(msgPrefix)) + msgWriter.Size,
|
|
MsgPrefix: msgPrefix,
|
|
}
|
|
|
|
// Add messages.
|
|
acc.WithRLock(func() {
|
|
conf, _ := acc.Conf()
|
|
for range 10 {
|
|
nm := m
|
|
err := acc.DeliverDestination(log, conf.Destinations["mjl"], &nm, msgFile)
|
|
tcheck(t, err, "deliver")
|
|
}
|
|
})
|
|
|
|
// Reparse explicitly.
|
|
total, err := acc.ReparseMessages(ctxbg, log)
|
|
tcheck(t, err, "reparsing messages")
|
|
tcompare(t, total, 10)
|
|
|
|
// Ensure a next reopen will reparse messages in the background.
|
|
_, err = bstore.QueryDB[Upgrade](ctxbg, acc.DB).UpdateNonzero(Upgrade{MessageParseVersion: MessageParseVersionLatest + 1})
|
|
tcheck(t, err, "change")
|
|
|
|
// Close account, and wait until really closed.
|
|
err = acc.Close()
|
|
tcheck(t, err, "closing account")
|
|
acc.WaitClosed()
|
|
|
|
// Reopen account, should trigger reparse. We immediately Close again, account DB
|
|
// should be kept open.
|
|
acc, err = OpenAccount(log, "mjl", false)
|
|
tcheck(t, err, "open account")
|
|
err = acc.Close()
|
|
tcheck(t, err, "closing account")
|
|
acc.WaitClosed()
|
|
|
|
// Check that the reparse is finished.
|
|
acc, err = OpenAccount(log, "mjl", false)
|
|
tcheck(t, err, "open account")
|
|
for range 10 {
|
|
up, err := bstore.QueryDB[Upgrade](ctxbg, acc.DB).Get()
|
|
tcheck(t, err, "change")
|
|
if up.MessageParseVersion == MessageParseVersionLatest {
|
|
break
|
|
}
|
|
time.Sleep(time.Second / 10)
|
|
}
|
|
err = acc.Close()
|
|
tcheck(t, err, "closing account")
|
|
acc.WaitClosed()
|
|
}
|