From b0623e6038b77e17554cf6b74ed22db6c406f653 Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Mon, 22 May 2023 15:03:23 +0200 Subject: [PATCH] in queue.Drop, to drop a message from the outgoing queue, not only remove it from the database, but also its contents from the file system --- queue/queue.go | 10 +++++++++- queue/queue_test.go | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/queue/queue.go b/queue/queue.go index e01be77..9527fa2 100644 --- a/queue/queue.go +++ b/queue/queue.go @@ -206,7 +206,7 @@ func Add(ctx context.Context, log *mlog.Log, senderAccount string, mailFrom, rcp return err } - dst := mox.DataDirPath(filepath.Join("queue", store.MessagePath(qm.ID))) + dst := qm.MessagePath() defer func() { if dst != "" { err := os.Remove(dst) @@ -324,10 +324,18 @@ func Drop(ctx context.Context, ID int64, toDomain string, recipient string) (int return qm.Recipient().XString(true) == recipient }) } + var msgs []Msg + q.Gather(&msgs) n, err := q.Delete() if err != nil { return 0, fmt.Errorf("selecting and deleting messages from queue: %v", err) } + for _, m := range msgs { + p := m.MessagePath() + if err := os.Remove(p); err != nil { + xlog.WithContext(ctx).Errorx("removing queue message from file system", err, mlog.Field("queuemsgid", m.ID), mlog.Field("path", p)) + } + } return n, nil } diff --git a/queue/queue_test.go b/queue/queue_test.go index 8a307e4..fd9e2b8 100644 --- a/queue/queue_test.go +++ b/queue/queue_test.go @@ -102,6 +102,9 @@ func TestQueue(t *testing.T) { if n != 1 { t.Fatalf("dropped %d, expected 1", n) } + if _, err := os.Stat(msgs[1].MessagePath()); err == nil || !os.IsNotExist(err) { + t.Fatalf("dropped message not removed from file system") + } next := nextWork(ctxbg, nil) if next > 0 {