{"record":{"id":"32ecc85a5229951e","repo":"larksuite/cli","slug":"rewrite-entire-draft-cannot-synthesize-body-inside","errorCode":null,"errorMessage":"rewrite_entire_draft cannot synthesize body inside %q","messagePattern":"rewrite_entire_draft cannot synthesize body inside %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/mail/draft/patch.go","lineNumber":528,"sourceCode":"\t\tfor idx := range part.Children {\n\t\t\tchild := part.Children[idx]\n\t\t\tif child == nil {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif child.IsMultipart() && strings.EqualFold(child.MediaType, \"multipart/alternative\") {\n\t\t\t\treturn ensureBodyPartRef(&part.Children[idx], bodyKind)\n\t\t\t}\n\t\t}\n\t\tif len(part.Children) == 0 {\n\t\t\tleaf := newBodyLeaf(bodyKind)\n\t\t\tpart.Children = append(part.Children, leaf)\n\t\t\tpart.Dirty = true\n\t\t\tleaf.Dirty = true\n\t\t\treturn leaf, nil\n\t\t}\n\t\treturn ensureBodyPartRef(&part.Children[0], bodyKind)\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"rewrite_entire_draft cannot synthesize body inside %q\", part.MediaType)\n\t}\n}\n\nfunc newBodyLeaf(bodyKind string) *Part {\n\treturn &Part{\n\t\tMediaType:        strings.ToLower(bodyKind),\n\t\tMediaParams:      map[string]string{\"charset\": \"UTF-8\"},\n\t\tTransferEncoding: \"7bit\",\n\t\tHeaders: []Header{\n\t\t\t{Name: \"Content-Type\", Value: mime.FormatMediaType(strings.ToLower(bodyKind), map[string]string{\"charset\": \"UTF-8\"})},\n\t\t\t{Name: \"Content-Transfer-Encoding\", Value: \"7bit\"},\n\t\t},\n\t\tBody: []byte{},\n\t}\n}\n\nfunc newMultipartContainer(mediaType string) *Part {\n\tboundary := newBoundary()","sourceCodeStart":510,"sourceCodeEnd":546,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/mail/draft/patch.go#L510-L546","documentation":"During body synthesis, the recursive ensureBodyPartRef walked into a multipart container it does not understand (anything other than multipart/alternative or multipart/related, e.g. multipart/mixed as a body child or multipart/digest, multipart/signed). The rewrite_entire_draft path only knows how to synthesize a text body inside alternative/related containers, so it fails explicitly with the offending media type.","triggerScenarios":"Rewriting a draft whose body root descends into an unsupported multipart subtype — e.g. primaryBodyRootRef resolves to a multipart/mixed child that is itself multipart/mixed, or the first child of a multipart/related is multipart/signed or multipart/mixed.","commonSituations":"Drafts produced by other mail clients with nested multipart/mixed inside related containers; signed/encrypted (multipart/signed, multipart/encrypted) drafts; hand-built MIME trees with unusual nesting.","solutions":["Flatten unusual nesting so the body path contains only multipart/alternative and multipart/related before rewriting.","Rebuild the draft without signed/encrypted wrapping if you need programmatic body rewrite (signing can be reapplied after).","Handle the offending container manually: locate the text leaf yourself and patch its Body directly instead of using the synthesis path."],"exampleFix":"// before: multipart/related whose child is multipart/mixed\nrelated.Children[0] = mixedContainer\n// after: keep only supported nesting\nrelated.Children[0] = altContainer // multipart/alternative","handlingStrategy":"validation","validationCode":"func supportedBodyTree(p *Part) bool {\n\tif p == nil { return true }\n\tif p.IsMultipart() {\n\t\tmt := strings.ToLower(p.MediaType)\n\t\tif mt != \"multipart/alternative\" && mt != \"multipart/related\" && mt != \"multipart/mixed\" { return false }\n\t\tfor _, c := range p.Children { if !supportedBodyTree(c) { return false } }\n\t}\n\treturn true\n}\nif !supportedBodyTree(snapshot.Body) { /* flatten or rebuild before rewrite */ }","typeGuard":"func synthesizableContainer(p *Part) bool {\n\tmt := strings.ToLower(p.MediaType)\n\treturn mt == \"multipart/alternative\" || mt == \"multipart/related\"\n}","tryCatchPattern":null,"preventionTips":["Flatten nested multipart/mixed inside related/alternative containers before rewriting.","Strip multipart/signed or multipart/encrypted wrapping; re-sign after editing.","Restrict programmatic drafts to alternative/related nesting."],"tags":["email","mime","draft","unsupported-content"],"backgroundTag":"unsupported-multipart-structure","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"}