when generating Authentication-Results, put each method on a new line for better readability

This commit is contained in:
Mechiel Lukkien 2023-12-14 15:14:07 +01:00
parent 406fdc312d
commit 2710a5b971
No known key found for this signature in database
3 changed files with 15 additions and 2 deletions

View file

@ -66,6 +66,8 @@ func (h AuthResults) Header() string {
w := &HeaderWriter{}
w.Add("", "Authentication-Results:"+optComment(h.Comment)+" "+value(h.Hostname)+";")
for i, m := range h.Methods {
w.Newline()
tokens := []string{}
addf := func(format string, args ...any) {
s := fmt.Sprintf(format, args...)
@ -86,10 +88,14 @@ func (h AuthResults) Header() string {
addf("%s.%s=%s%s", p.Type, p.Property, v, optComment(p.Comment))
}
for j, t := range tokens {
var sep string
if j > 0 {
sep = " "
}
if j == len(tokens)-1 && i < len(h.Methods)-1 {
t += ";"
}
w.Add(" ", t)
w.Add(sep, t)
}
}
return w.String()

View file

@ -19,7 +19,7 @@ func TestAuthResults(t *testing.T) {
},
}
s := authRes.Header()
const exp = "Authentication-Results: (xn--mx-lka.example) møx.example; dkim=pass\r\n\theader.d=møx.example (xn--mx-lka.example)\r\n"
const exp = "Authentication-Results: (xn--mx-lka.example) møx.example;\r\n\tdkim=pass header.d=møx.example (xn--mx-lka.example)\r\n"
if s != exp {
t.Fatalf("got %q, expected %q", s, exp)
}

View file

@ -59,6 +59,13 @@ func (w *HeaderWriter) AddWrap(buf []byte) {
}
}
// Newline starts a new line.
func (w *HeaderWriter) Newline() {
w.b.WriteString("\r\n\t")
w.lineLen = 1
w.nonfirst = true
}
// String returns the header in string form, ending with \r\n.
func (w *HeaderWriter) String() string {
return w.b.String() + "\r\n"