in smtp submission, if a fromid is present in the mailfrom command, use it when queueing

it's the responsibility of the sender to use unique fromid's.
we do check if that's the case, and return an error if not.

also make it more clear that "unique smtp mail from addresses" map to the
"FromIDLoginAddresses" account config field.

based on feedback from cuu508 for #31, thanks!
This commit is contained in:
Mechiel Lukkien
2024-04-28 13:18:25 +02:00
parent 32cf6500bd
commit 8cc795b2ec
12 changed files with 126 additions and 19 deletions

View File

@ -41,6 +41,10 @@ import (
"github.com/mjl-/mox/webhook"
)
// ErrFromID indicate a fromid was present when adding a message to the queue, but
// it wasn't unique.
var ErrFromID = errors.New("fromid not unique")
var (
metricConnection = promauto.NewCounterVec(
prometheus.CounterOpts{
@ -662,6 +666,22 @@ func Add(ctx context.Context, log mlog.Log, senderAccount string, msgFile *os.Fi
// message inserted.
var baseID int64
for i := range qml {
// FromIDs must be unique if present. We don't have a unique index because values
// can be the empty string. We check in both Msg and MsgRetired, both are relevant
// for uniquely identifying a message sent in the past.
if fromID := qml[i].FromID; fromID != "" {
if exists, err := bstore.QueryTx[Msg](tx).FilterNonzero(Msg{FromID: fromID}).Exists(); err != nil {
return fmt.Errorf("looking up fromid: %v", err)
} else if exists {
return fmt.Errorf("%w: fromid %q already present in message queue", ErrFromID, fromID)
}
if exists, err := bstore.QueryTx[MsgRetired](tx).FilterNonzero(MsgRetired{FromID: fromID}).Exists(); err != nil {
return fmt.Errorf("looking up fromid: %v", err)
} else if exists {
return fmt.Errorf("%w: fromid %q already present in retired message queue", ErrFromID, fromID)
}
}
qml[i].SenderAccount = senderAccount
qml[i].BaseID = baseID
for _, hr := range holdRules {