From b37faa06bdd2a433f7ee1e2a09a8a75b14024887 Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Sun, 23 Mar 2025 11:07:39 +0100 Subject: [PATCH] After queueing a message in the web api's, prevent context cancelation from completing message changes Adding to the queue is done in a transaction, the queue db file is mox-global. Appending the message to the Sent folder, removing it from Drafts, marking the original message as answered/forwarded, is done in a separate database transaction that gets the ctx passed in. If the ctx was canceled in between, the queueing was finished, but the rest wasn't completed. Reported by mteege, thanks! --- webapisrv/server.go | 3 +++ webmail/api.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/webapisrv/server.go b/webapisrv/server.go index 2f49c29..6cb3c2a 100644 --- a/webapisrv/server.go +++ b/webapisrv/server.go @@ -1048,6 +1048,9 @@ func (s server) Send(ctx context.Context, req webapi.SendRequest) (resp webapi.S xcheckf(err, "adding messages to the delivery queue") metricSubmission.WithLabelValues("ok").Inc() + // Message has been added to the queue. Ensure we finish the work. + ctx = context.WithoutCancel(ctx) + if req.SaveSent { // Append message to Sent mailbox and mark original messages as answered/forwarded. acc.WithRLock(func() { diff --git a/webmail/api.go b/webmail/api.go index 8479e02..9968f46 100644 --- a/webmail/api.go +++ b/webmail/api.go @@ -1005,6 +1005,10 @@ func (w Webmail) MessageSubmit(ctx context.Context, m SubmitMessage) { var modseq store.ModSeq // Only set if needed. + // We have committed to sending the message. We want to follow through + // with appending to Sent and removing the draft message. + ctx = context.WithoutCancel(ctx) + // Append message to Sent mailbox, mark original messages as answered/forwarded, // remove any draft message. acc.WithWLock(func() {