wrap long dkim dns records at 100 characters instead of 255 for better display (no line-wrap)

This commit is contained in:
Mechiel Lukkien 2023-11-22 14:02:24 +01:00
parent 361bc2b516
commit c66fa64b8b
No known key found for this signature in database
2 changed files with 9 additions and 11 deletions

View file

@ -2132,8 +2132,8 @@ The DNS should be configured as a TXT record at $selector._domainkey.$domain.
fmt.Print("<selector>._domainkey.<your.domain.> TXT ") fmt.Print("<selector>._domainkey.<your.domain.> TXT ")
for record != "" { for record != "" {
s := record s := record
if len(s) > 255 { if len(s) > 100 {
s, record = record[:255], record[255:] s, record = record[:100], record[100:]
} else { } else {
record = "" record = ""
} }

View file

@ -34,19 +34,18 @@ import (
"github.com/mjl-/mox/tlsrpt" "github.com/mjl-/mox/tlsrpt"
) )
// TXTStrings returns a TXT record value as one or more quoted strings, taking the max // TXTStrings returns a TXT record value as one or more quoted strings, each max
// length of 255 characters for a string into account. In case of multiple // 100 characters. In case of multiple strings, a multi-line record is returned.
// strings, a multi-line record is returned.
func TXTStrings(s string) string { func TXTStrings(s string) string {
if len(s) <= 255 { if len(s) <= 100 {
return `"` + s + `"` return `"` + s + `"`
} }
r := "(\n" r := "(\n"
for len(s) > 0 { for len(s) > 0 {
n := len(s) n := len(s)
if n > 255 { if n > 100 {
n = 255 n = 100
} }
if r != "" { if r != "" {
r += " " r += " "
@ -578,10 +577,9 @@ func DomainRecords(domConf config.Domain, domain dns.Domain, hasDNSSEC bool) ([]
return nil, fmt.Errorf("making DKIM DNS TXT record: %v", err) return nil, fmt.Errorf("making DKIM DNS TXT record: %v", err)
} }
if len(txt) > 255 { if len(txt) > 100 {
records = append(records, records = append(records,
"; NOTE: Ensure the next record is added in DNS as a single record, it consists", "; NOTE: The following strings must be added to DNS as single record.",
"; of multiple strings (max size of each is 255 bytes).",
) )
} }
s := fmt.Sprintf("%s._domainkey.%s. TXT %s", name, d, TXTStrings(txt)) s := fmt.Sprintf("%s._domainkey.%s. TXT %s", name, d, TXTStrings(txt))