{"record":{"id":"2111dcf4a331943a","repo":"larksuite/cli","slug":"html-body-references-missing-inline-cid-q","errorCode":null,"errorMessage":"html body references missing inline cid %q","messagePattern":"html body references missing inline cid %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/mail/draft/patch.go","lineNumber":1138,"sourceCode":"\t\tremoveOrphanedInlineParts(child, referencedCIDs)\n\t}\n}\n\n// ValidateCIDReferences checks that every cid: reference in the HTML body has\n// a matching entry in availableCIDs. Returns an error for the first missing CID.\n// Both sides are compared case-insensitively.\nfunc ValidateCIDReferences(html string, availableCIDs []string) error {\n\trefs := extractCIDRefs(html)\n\tif len(refs) == 0 {\n\t\treturn nil\n\t}\n\tcidSet := make(map[string]bool, len(availableCIDs))\n\tfor _, cid := range availableCIDs {\n\t\tcidSet[strings.ToLower(cid)] = true\n\t}\n\tfor _, ref := range refs {\n\t\tif !cidSet[strings.ToLower(ref)] {\n\t\t\treturn fmt.Errorf(\"html body references missing inline cid %q\", ref)\n\t\t}\n\t}\n\treturn nil\n}\n\n// FindOrphanedCIDs returns CIDs from addedCIDs that are not referenced in the\n// HTML body via <img src=\"cid:...\">. These would appear as unexpected\n// attachments when the email is sent.\nfunc FindOrphanedCIDs(html string, addedCIDs []string) []string {\n\trefs := extractCIDRefs(html)\n\trefSet := make(map[string]bool, len(refs))\n\tfor _, ref := range refs {\n\t\trefSet[strings.ToLower(ref)] = true\n\t}\n\tvar orphaned []string\n\tfor _, cid := range addedCIDs {\n\t\tif !refSet[strings.ToLower(cid)] {\n\t\t\torphaned = append(orphaned, cid)","sourceCodeStart":1120,"sourceCodeEnd":1156,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/mail/draft/patch.go#L1120-L1156","documentation":"ValidateCIDReferences checks every cid: reference extracted from the HTML body against the set of available inline CID values (case-insensitively). If any referenced cid does not have a corresponding inline MIME part, the draft would render a broken image, so the library rejects it with this error. It is the post-processing gate after inline images are attached.","triggerScenarios":"Calling postProcessInlineImages when the HTML contains `cid:` references that are not in availableCIDs — e.g. a cid was pruned because its image file failed, the cid was generated for a different run, or the HTML was edited so the reference no longer matches any inline part.","commonSituations":"Hand-editing HTML and keeping an old cid: URL after the attachment was removed; patching a draft where a previous signature replacement dropped the inline part the body still references; case/whitespace mismatches that survive normalization.","solutions":["Re-run inline image resolution so every cid: in the HTML has a matching generated inline part","Remove the stale cid: reference from the HTML body","Ensure the image whose cid is referenced is still in the inline attachments list","Check cid case matches (comparison is case-insensitive, but the part must exist)"],"exampleFix":"// before\n<img src=\"cid:old-pruned-cid@example\">\n// after\n<img src=\"cid:regenerated-cid-from-current-run@example\"> // or drop the tag","handlingStrategy":"validation","validationCode":"refs := extractCIDRefs(html)\nfor _, ref := range refs {\n  if !availableCIDSet[strings.ToLower(ref)] {\n    return fmt.Errorf(\"cid %q has no inline part; regenerate inline images\", ref)\n  }\n}","typeGuard":"func allCIDsAvailable(html string, available []string) bool {\n  set := make(map[string]bool, len(available))\n  for _, c := range available { set[strings.ToLower(c)] = true }\n  for _, ref := range extractCIDRefs(html) {\n    if !set[strings.ToLower(ref)] { return false }\n  }\n  return true\n}","tryCatchPattern":"if err := postProcessInlineImages(snap, ...); err != nil {\n  if strings.Contains(err.Error(), \"missing inline cid\") {\n    return regenerateInlineImages(snap) // re-run resolution to rebuild cids\n  }\n  return err\n}","preventionTips":["Never hand-edit cid: URLs in generated HTML","Re-run inline image resolution after any body edit","Keep inline parts and their cid references in the same patch pipeline","Use FindOrphanedCIDs to detect drift before saving"],"tags":["mail","draft-patch","cid","inline-image"],"backgroundTag":"missing-inline-cid","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}