mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-18 14:47:03 +00:00
queue: Send DSN for messages that time out in the queue
The queue currently only considers failed recipients when deciding whether to send a DSN or not. This is a bug, as recipients that time out are not taken into account. This patch fixes that issue by including both failed and pending recipients in the DSN. It also adds more comprehensive tests for this case, both in the queue and in the dsn generation code.
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -113,6 +114,45 @@ func TestBasic(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDSNOnTimeout(t *testing.T) {
|
||||
localC := newTestCourier()
|
||||
remoteC := newTestCourier()
|
||||
q := New("/tmp/queue_test", set.NewString("loco"), aliases.NewResolver(),
|
||||
localC, remoteC, "dsndomain")
|
||||
|
||||
// Insert an expired item in the queue.
|
||||
item := &Item{
|
||||
Message: Message{
|
||||
ID: <-newID,
|
||||
From: fmt.Sprintf("from@loco"),
|
||||
Rcpt: []*Recipient{
|
||||
{"to@to", Recipient_EMAIL, Recipient_PENDING, "err", "to@to"}},
|
||||
Data: []byte("data"),
|
||||
},
|
||||
CreatedAt: time.Now().Add(-24 * time.Hour),
|
||||
}
|
||||
q.q[item.ID] = item
|
||||
err := item.WriteTo(q.path)
|
||||
if err != nil {
|
||||
t.Errorf("failed to write item: %v", err)
|
||||
}
|
||||
|
||||
// Launch the sending loop, expect 1 local delivery (the DSN).
|
||||
localC.wg.Add(1)
|
||||
go item.SendLoop(q)
|
||||
localC.wg.Wait()
|
||||
|
||||
req := localC.reqFor["from@loco"]
|
||||
if req == nil {
|
||||
t.Fatal("missing DSN")
|
||||
}
|
||||
|
||||
if req.from != "<>" || req.to != "from@loco" ||
|
||||
!strings.Contains(string(req.data), "X-Failed-Recipients: to@to,") {
|
||||
t.Errorf("wrong DSN: %q", string(req.data))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFullQueue(t *testing.T) {
|
||||
q := New("/tmp/queue_test", set.NewString(), aliases.NewResolver(),
|
||||
dumbCourier, dumbCourier, "dsndomain")
|
||||
|
||||
Reference in New Issue
Block a user