9// Authentication-Results header, see RFC 8601.
10type AuthResults struct {
12 Comment string // If not empty, header comment without "()", added after Hostname.
18// AuthMethod is a result for one authentication method.
20// Example encoding in the header: "spf=pass smtp.mailfrom=example.net".
21type AuthMethod struct {
22 // E.g. "dkim", "spf", "iprev", "auth".
24 Result string // Each method has a set of known values, e.g. "pass", "temperror", etc.
25 Comment string // Optional, message header comment.
26 Reason string // Optional.
32// AuthProp describes properties for an authentication method.
33// Each method has a set of known properties.
34// Encoded in the header as "type.property=value", e.g. "smtp.mailfrom=example.net"
37 // Valid values maintained at https://www.iana.org/assignments/email-auth/email-auth.xhtml
41 // Whether value is address-like (localpart@domain, or domain). Or another value,
42 // which is subject to escaping.
44 Comment string // If not empty, header comment without "()", added after Value.
47// MakeAuthProp is a convenient way to make an AuthProp.
48func MakeAuthProp(typ, property, value string, isAddrLike bool, Comment string) AuthProp {
49 return AuthProp{typ, property, value, isAddrLike, Comment}
52// todo future: we could store fields as dns.Domain, and when we encode as non-ascii also add the ascii version as a comment.
54// Header returns an Authentication-Results header, possibly spanning multiple
55// lines, always ending in crlf.
56func (h AuthResults) Header() string {
59 optComment := func(s string) string {
67 w.Add("", "Authentication-Results:"+optComment(h.Comment)+" "+value(h.Hostname)+";")
68 for i, m := range h.Methods {
72 addf := func(format string, args ...any) {
73 s := fmt.Sprintf(format, args...)
74 tokens = append(tokens, s)
76 addf("%s=%s", m.Method, m.Result)
77 if m.Comment != "" && (m.Reason != "" || len(m.Props) > 0) {
78 addf("(%s)", m.Comment)
81 addf("reason=%s", value(m.Reason))
83 for _, p := range m.Props {
88 addf("%s.%s=%s%s", p.Type, p.Property, v, optComment(p.Comment))
90 for j, t := range tokens {
95 if j == len(tokens)-1 && i < len(h.Methods)-1 {
104func value(s string) string {
106 for _, c := range s {
108 if c == '"' || c == '\\' || c <= ' ' || c == 0x7f {
117 for _, c := range s {
118 if c == '"' || c == '\\' {