Files
sam b1ee58c1b8 fix(email): retry mail after a transient failure, ignore automatic mail, thread replies
A gateway or SMTP failure skipped the message for the life of the process,
so mail sent during an outage was never answered. Only mail the channel
rejects is skipped now; the rest is retried on the next poll, and the
Message-ID as the source id makes the gateway replay a reply it already
produced instead of running the turn twice. Out-of-office replies, bulk and
list mail are ignored and replies are marked Auto-Submitted, so the channel
cannot loop with an auto-responder. Replies carry References for threading,
and port 465 uses implicit TLS.
2026-10-25 18:11:39 +11:00

57 lines
1.6 KiB
Go

package main
import (
"testing"
"github.com/emersion/go-message/mail"
)
func TestAuthenticated(t *testing.T) {
for _, tc := range []struct {
name string
results []string
want bool
}{
{"dmarc pass", []string{"mx.example.net; dmarc=pass header.from=a.com"}, true},
{"aligned dkim pass", []string{"mx.example.net; dkim=pass header.d=a.com"}, true},
{"dkim pass for another domain", []string{"mx.example.net; dkim=pass header.d=evil.com"}, false},
{"forged by another authserv", []string{"mx.evil.com; dmarc=pass header.from=a.com"}, false},
{"dmarc fail", []string{"mx.example.net; dmarc=fail header.from=a.com"}, false},
{"no results", nil, false},
} {
t.Run(tc.name, func(t *testing.T) {
var h mail.Header
for _, v := range tc.results {
h.Add("Authentication-Results", v)
}
if got := authenticated(h, "mx.example.net", "me@a.com"); got != tc.want {
t.Fatalf("authenticated = %v, want %v", got, tc.want)
}
})
}
}
func TestAutomatic(t *testing.T) {
for _, tc := range []struct {
name string
headers map[string]string
want bool
}{
{"written by a person", nil, false},
{"explicitly not automatic", map[string]string{"Auto-Submitted": "no"}, false},
{"out-of-office reply", map[string]string{"Auto-Submitted": "auto-replied"}, true},
{"bulk precedence", map[string]string{"Precedence": "bulk"}, true},
{"mailing list", map[string]string{"List-Id": "<dev.example.org>"}, true},
} {
t.Run(tc.name, func(t *testing.T) {
var h mail.Header
for k, v := range tc.headers {
h.Set(k, v)
}
if got := automatic(h); got != tc.want {
t.Fatalf("automatic = %v, want %v", got, tc.want)
}
})
}
}