mirror of
https://github.com/mjl-/mox.git
synced 2024-12-27 08:53:48 +03:00
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
This commit is contained in:
parent
88fd775ec4
commit
b0623e6038
2 changed files with 12 additions and 1 deletions
|
@ -206,7 +206,7 @@ func Add(ctx context.Context, log *mlog.Log, senderAccount string, mailFrom, rcp
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
dst := mox.DataDirPath(filepath.Join("queue", store.MessagePath(qm.ID)))
|
dst := qm.MessagePath()
|
||||||
defer func() {
|
defer func() {
|
||||||
if dst != "" {
|
if dst != "" {
|
||||||
err := os.Remove(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
|
return qm.Recipient().XString(true) == recipient
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
var msgs []Msg
|
||||||
|
q.Gather(&msgs)
|
||||||
n, err := q.Delete()
|
n, err := q.Delete()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("selecting and deleting messages from queue: %v", err)
|
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
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,6 +102,9 @@ func TestQueue(t *testing.T) {
|
||||||
if n != 1 {
|
if n != 1 {
|
||||||
t.Fatalf("dropped %d, expected 1", n)
|
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)
|
next := nextWork(ctxbg, nil)
|
||||||
if next > 0 {
|
if next > 0 {
|
||||||
|
|
Loading…
Reference in a new issue