From 2710a5b97122e1c8576ef94d2040314766533ac8 Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Thu, 14 Dec 2023 15:14:07 +0100 Subject: [PATCH] when generating Authentication-Results, put each method on a new line for better readability --- message/authresults.go | 8 +++++++- message/authresults_test.go | 2 +- message/headerwriter.go | 7 +++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/message/authresults.go b/message/authresults.go index aa507a9..94fccfa 100644 --- a/message/authresults.go +++ b/message/authresults.go @@ -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() diff --git a/message/authresults_test.go b/message/authresults_test.go index 2a8bc59..012be0b 100644 --- a/message/authresults_test.go +++ b/message/authresults_test.go @@ -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) } diff --git a/message/headerwriter.go b/message/headerwriter.go index 8ba6f18..96c4424 100644 --- a/message/headerwriter.go +++ b/message/headerwriter.go @@ -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"