{"record":{"id":"11932bf1b6d19663","repo":"Billionmail/BillionMail","slug":"failed-to-parse-dkim-record-v","errorCode":null,"errorMessage":"Failed to parse DKIM record: %v","messagePattern":"Failed to parse DKIM record: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"core/internal/service/domains/domains.go","lineNumber":665,"sourceCode":"\t}\n\n\t// Format DKIM record\n\t// Expected format is a pre-formatted TXT record value like \"v=DKIM1; k=rsa; p=MIIBIjANBg...\"\n\tdkimRecord := strings.TrimSpace(dkimPub)\n\n\t// If the raw public key is read, format it into DNS TXT record format\n\tif !strings.Contains(dkimRecord, \"v=DKIM1\") && !strings.Contains(dkimRecord, \"k=rsa\") && !strings.Contains(dkimRecord, \"p=\") {\n\t\t// Remove possible header/footer markers and newlines\n\t\tdkimRecord = strings.ReplaceAll(dkimRecord, \"-----BEGIN PUBLIC KEY-----\", \"\")\n\t\tdkimRecord = strings.ReplaceAll(dkimRecord, \"-----END PUBLIC KEY-----\", \"\")\n\t\tdkimRecord = strings.ReplaceAll(dkimRecord, \"\\n\", \"\")\n\t\tdkimRecord = strings.TrimSpace(dkimRecord)\n\t\tdkimRecord = fmt.Sprintf(\"v=DKIM1; k=rsa; p=%s\", dkimRecord)\n\t} else {\n\t\tvar ms [][]string\n\t\tms, err = gregex.MatchAllString(`\"([^\"\\r\\n]+)\"`, dkimRecord)\n\t\tif err != nil {\n\t\t\terr = fmt.Errorf(\"Failed to parse DKIM record: %v\", err)\n\t\t\treturn\n\t\t}\n\n\t\tif len(ms) < 2 {\n\t\t\terr = fmt.Errorf(\"Invalid DKIM record format\")\n\t\t\treturn\n\t\t}\n\n\t\ts := \"\"\n\t\tfor _, v := range ms {\n\t\t\tif len(v) < 2 {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\ts += v[1]\n\t\t}\n\n\t\tdkimRecord = s\n\t}","sourceCodeStart":647,"sourceCodeEnd":683,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/domains/domains.go#L647-L683","documentation":"Thrown when the regex extracting quoted segments from the DKIM TXT record (grex: `\"([^\"]+)\"`) fails to compile/match due to a regex engine error. This happens while normalizing an existing multi-line DKIM record read from rspamd back into a single-line record.","triggerScenarios":"gregex.MatchAllString returns an error on the raw dkimRecord content — effectively only on malformed regex invocation or pathological input handled by the engine; normal empty/no-match input yields len(ms)<2 (error 305) instead.","commonSituations":"Corrupted or binary content in the DKIM key file being parsed as a record, extremely long lines stressing the regex engine, or a GoFrame/gregex version regression in MatchAllString behavior.","solutions":["Inspect the DKIM key/record file content for corruption and regenerate keys via RepairDKIMSigningConfig","Verify the content is plain ASCII with standard quoted record sections","Upgrade/align GoFrame version if gregex behavior changed unexpectedly","Add a pre-read sanity check that the file content looks like a DKIM record before regex parsing"],"exampleFix":"// before\nms, err = gregex.MatchAllString(`\"([^\r\n]+)\"`, dkimRecord)\n// after: guard with a quick sanity check\nif !strings.Contains(dkimRecord, \"v=DKIM1\") && !strings.Contains(dkimRecord, \"p=\") {\n    return fmt.Errorf(\"file does not look like a DKIM record; regenerate keys\")\n}\nms, err = gregex.MatchAllString(`\"([^\r\n]+)\"`, dkimRecord)","handlingStrategy":"validation","validationCode":"raw, _ := os.ReadFile(dkimPubPath)\nif utf8.Valid(raw) && (strings.Contains(string(raw), \"v=DKIM1\") || strings.Contains(string(raw), \"p=\")) {\n    // safe to regex-parse\n}","typeGuard":"func looksLikeDKIMRecord(s string) bool {\n    return strings.Contains(s, \"v=DKIM1\") || strings.Contains(s, \"p=\")\n}","tryCatchPattern":"ms, err := gregex.MatchAllString(`\"([^\r\n]+)\"`, dkimRecord)\nif err != nil {\n    log.Printf(\"DKIM record regex failure: %v — content may be corrupt; regenerate keys\", err)\n    return err\n}","preventionTips":["Never hand-edit DKIM key/record files; always use RepairDKIMSigningConfig","Validate file contents are plain ASCII after any import/restore","Pin GoFrame versions and test gregex behavior on upgrade"],"tags":["regex","dkim","parsing"],"backgroundTag":"dkim-record-parse-failed","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}