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]>
78 lines
2.2 KiB
Go
78 lines
2.2 KiB
Go
// Package dmarcdb stores incoming DMARC aggrate reports and evaluations for outgoing aggregate reports.
|
|
//
|
|
// With DMARC, a domain can request reports with DMARC evaluation results to be
|
|
// sent to a specified address. Mox parses such reports, stores them in its
|
|
// database and makes them available through its admin web interface. Mox also
|
|
// keeps track of the evaluations it does for incoming messages and sends reports
|
|
// to mail servers that request reports.
|
|
//
|
|
// Only aggregate reports are stored and sent. Failure reports about individual
|
|
// messages are not implemented.
|
|
package dmarcdb
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
|
|
"github.com/mjl-/bstore"
|
|
|
|
"github.com/hanzoai/mail/mlog"
|
|
"github.com/hanzoai/mail/mox-"
|
|
"github.com/hanzoai/mail/moxvar"
|
|
)
|
|
|
|
// Init opens the databases.
|
|
//
|
|
// The incoming reports and evaluations for outgoing reports are in separate
|
|
// databases for simpler file-based handling of the databases.
|
|
func Init() error {
|
|
if ReportsDB != nil || EvalDB != nil {
|
|
return fmt.Errorf("already initialized")
|
|
}
|
|
|
|
log := mlog.New("dmarcdb", nil)
|
|
var err error
|
|
|
|
ReportsDB, err = openReportsDB(mox.Shutdown, log)
|
|
if err != nil {
|
|
return fmt.Errorf("open reports db: %v", err)
|
|
}
|
|
|
|
EvalDB, err = openEvalDB(mox.Shutdown, log)
|
|
if err != nil {
|
|
return fmt.Errorf("open eval db: %v", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func Close() error {
|
|
if err := ReportsDB.Close(); err != nil {
|
|
return fmt.Errorf("closing reports db: %w", err)
|
|
}
|
|
ReportsDB = nil
|
|
|
|
if err := EvalDB.Close(); err != nil {
|
|
return fmt.Errorf("closing eval db: %w", err)
|
|
}
|
|
EvalDB = nil
|
|
return nil
|
|
}
|
|
|
|
func openReportsDB(ctx context.Context, log mlog.Log) (*bstore.DB, error) {
|
|
p := mox.DataDirPath("dmarcrpt.db")
|
|
os.MkdirAll(filepath.Dir(p), 0770)
|
|
opts := bstore.Options{Timeout: 5 * time.Second, Perm: 0660, RegisterLogger: moxvar.RegisterLogger(p, log.Logger)}
|
|
return bstore.Open(ctx, p, &opts, ReportsDBTypes...)
|
|
}
|
|
|
|
func openEvalDB(ctx context.Context, log mlog.Log) (*bstore.DB, error) {
|
|
p := mox.DataDirPath("dmarceval.db")
|
|
os.MkdirAll(filepath.Dir(p), 0770)
|
|
opts := bstore.Options{Timeout: 5 * time.Second, Perm: 0660, RegisterLogger: moxvar.RegisterLogger(p, log.Logger)}
|
|
return bstore.Open(ctx, p, &opts, EvalDBTypes...)
|
|
}
|