mox/tlsrptdb/db.go
Mechiel Lukkien e24e1bee19
add suppression list for outgoing dmarc and tls reports
for reporting addresses that cause DSNs to be returned. that just adds noise.
the admin can add/remove/extend addresses through the webadmin.

in the future, we could send reports with a smtp mail from of
"postmaster+<signed-encoded-recipient>@...", and add the reporting recipient
on the suppression list automatically when a DSN comes in on that address, but
for now this will probably do.
2023-11-13 13:48:52 +01:00

50 lines
925 B
Go

package tlsrptdb
import (
"sync"
"github.com/mjl-/bstore"
"github.com/mjl-/mox/mlog"
"github.com/mjl-/mox/mox-"
)
var (
xlog = mlog.New("tlsrptdb")
ReportDBTypes = []any{TLSReportRecord{}}
ReportDB *bstore.DB
mutex sync.Mutex
// Accessed directly by tlsrptsend.
ResultDBTypes = []any{TLSResult{}, TLSRPTSuppressAddress{}}
ResultDB *bstore.DB
)
// Init opens and possibly initializes the databases.
func Init() error {
if _, err := reportDB(mox.Shutdown); err != nil {
return err
}
if _, err := resultDB(mox.Shutdown); err != nil {
return err
}
return nil
}
// Close closes the database connections.
func Close() {
if ResultDB != nil {
err := ResultDB.Close()
xlog.Check(err, "closing result database")
ResultDB = nil
}
mutex.Lock()
defer mutex.Unlock()
if ReportDB != nil {
err := ReportDB.Close()
xlog.Check(err, "closing report database")
ReportDB = nil
}
}