mox/spf/received_test.go
Mechiel Lukkien 69d2699961
write base64 message parts with 76 data bytes on a line instead of 78
As required by RFC 2045 (MIME). The 78 byte lines work in practice, except that
SpamAssassin has rules that give messages with 78-byte lines spam points.

Mentioned by kjetilho on irc.
2025-04-03 10:22:15 +02:00

40 lines
1.1 KiB
Go

package spf
import (
"net"
"testing"
"github.com/mjl-/mox/dns"
)
func TestReceived(t *testing.T) {
test := func(r Received, exp string) {
t.Helper()
s := r.Header()
if s != exp {
t.Fatalf("got %q, expected %q", s, exp)
}
}
test(Received{
Result: StatusPass,
Comment: "c",
ClientIP: net.ParseIP("0.0.0.0"),
EnvelopeFrom: "x@x",
Helo: dns.IPDomain{Domain: dns.Domain{ASCII: "y"}},
Problem: `a b"\`,
Receiver: "z",
Identity: ReceivedMailFrom,
Mechanism: "+ip4:0.0.0.0/0",
}, "Received-SPF: pass (c) client-ip=0.0.0.0; envelope-from=\"x@x\"; helo=y;\r\n\tproblem=\"a b\\\"\\\\\"; mechanism=\"+ip4:0.0.0.0/0\"; receiver=z;\r\n\tidentity=mailfrom\r\n")
test(Received{
Result: StatusPass,
ClientIP: net.ParseIP("0.0.0.0"),
EnvelopeFrom: "x@x",
Helo: dns.IPDomain{IP: net.ParseIP("2001:db8::1")},
Receiver: "z",
Identity: ReceivedMailFrom,
}, "Received-SPF: pass client-ip=0.0.0.0; envelope-from=\"x@x\";\r\n\thelo=\"2001:db8::1\"; receiver=z; identity=mailfrom\r\n")
}