mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 19:44:34 +03:00
Refactor how messages are added to mailboxes
DeliverMessage() is now MessageAdd(), and it takes a Mailbox object that it modifies but doesn't write to the database (the caller must do it, and plenty of times can do it more efficiently by doing it once for multiple messages). The new AddOpts let the caller influence how many checks and how much of the work MessageAdd() does. The zero-value AddOpts enable all checks and all the work, but callers can take responsibility of some of the checks/work if it can do it more efficiently itself. This simplifies the code in most places, and makes it more efficient. The checks to update per-mailbox keywords is a bit simpler too now. We are also more careful to close the junk filter without saving it in case of errors. Still part of more upcoming changes.
This commit is contained in:
@ -1099,24 +1099,18 @@ func (s server) Send(ctx context.Context, req webapi.SendRequest) (resp webapi.S
|
||||
MsgPrefix: []byte(msgPrefix),
|
||||
}
|
||||
|
||||
if ok, maxSize, err := acc.CanAddMessageSize(tx, sentm.Size); err != nil {
|
||||
xcheckf(err, "checking quota")
|
||||
} else if !ok {
|
||||
panic(webapi.Error{Code: "sentOverQuota", Message: fmt.Sprintf("message was sent, but not stored in sent mailbox due to quota of total %d bytes reached", maxSize)})
|
||||
}
|
||||
|
||||
// Update mailbox before delivery, which changes uidnext.
|
||||
sentmb.Add(sentm.MailboxCounts())
|
||||
err = tx.Update(&sentmb)
|
||||
xcheckf(err, "updating sent mailbox for counts")
|
||||
|
||||
err = acc.DeliverMessage(log, tx, &sentm, dataFile, true, false, false, true)
|
||||
if err != nil {
|
||||
err = acc.MessageAdd(log, tx, &sentmb, &sentm, dataFile, store.AddOpts{})
|
||||
if err != nil && errors.Is(err, store.ErrOverQuota) {
|
||||
panic(webapi.Error{Code: "sentOverQuota", Message: fmt.Sprintf("message was sent, but not stored in sent mailbox: %v", err)})
|
||||
} else if err != nil {
|
||||
metricSubmission.WithLabelValues("storesenterror").Inc()
|
||||
metricked = true
|
||||
}
|
||||
xcheckf(err, "message submitted to queue, appending message to Sent mailbox")
|
||||
|
||||
err = tx.Update(&sentmb)
|
||||
xcheckf(err, "updating mailbox")
|
||||
|
||||
changes = append(changes, sentm.ChangeAddUID(), sentmb.ChangeCounts())
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user