{"record":{"id":"2061c7336ceebf1c","repo":"larksuite/cli","slug":"draft-raw-eml-is-too-large-d-bytes-max-d","errorCode":null,"errorMessage":"draft raw EML is too large (%d bytes, max %d)","messagePattern":"draft raw EML is too large \\((.+?) bytes, max (.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/mail/draft/parse.go","lineNumber":52,"sourceCode":"\t\tBody:    root,\n\t}\n\tif err := refreshSnapshot(snapshot); err != nil {\n\t\treturn nil, err\n\t}\n\treturn snapshot, nil\n}\n\n// maxRawEMLSize is the maximum accepted raw (base64-encoded) EML string length.\n// Base64 encodes 3 bytes into 4 chars, so 35 MB covers a 25 MB decoded EML with margin.\nconst maxRawEMLSize = 35 * 1024 * 1024\n\nfunc decodeRawEML(raw string) ([]byte, error) {\n\traw = strings.TrimSpace(raw)\n\tif raw == \"\" {\n\t\treturn nil, fmt.Errorf(\"draft raw EML is empty\")\n\t}\n\tif len(raw) > maxRawEMLSize {\n\t\treturn nil, fmt.Errorf(\"draft raw EML is too large (%d bytes, max %d)\", len(raw), maxRawEMLSize)\n\t}\n\tdecoders := []func(string) ([]byte, error){\n\t\tbase64.URLEncoding.DecodeString,\n\t\tbase64.RawURLEncoding.DecodeString,\n\t\tbase64.StdEncoding.DecodeString,\n\t\tbase64.RawStdEncoding.DecodeString,\n\t}\n\tfor _, decode := range decoders {\n\t\tdecoded, err := decode(raw)\n\t\tif err == nil {\n\t\t\treturn normalizeLineEndings(decoded), nil\n\t\t}\n\t}\n\treturn nil, fmt.Errorf(\"draft raw EML is not valid base64url\")\n}\n\nfunc normalizeLineEndings(in []byte) []byte {\n\tin = bytes.ReplaceAll(in, []byte(\"\\r\\n\"), []byte(\"\\n\"))","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/mail/draft/parse.go#L34-L70","documentation":"decodeRawEML enforces maxRawEMLSize (35 MB) on the base64url-encoded EML string, since 4 base64 chars encode 3 bytes, this covers decoded EMLs up to ~25 MB. The error reports the actual size and the limit. It protects the parser from unbounded memory use on pathologically large drafts.","triggerScenarios":"Calling Parse with a raw EML string longer than 35 * 1024 * 1024 bytes, e.g. a mail with very large attachments (encoded size inflates ~4/3x).","commonSituations":"Parsing drafts with multi-megabyte binary attachments, re-encoding a decoded EML and passing the wrong (already large) payload, concatenating raw bodies, or an API returning more content than expected.","solutions":["Trim oversized attachments from the draft before fetching/parsing the raw EML","Use a streaming or partial parser for the attachment payloads instead of parsing the whole EML string","If the limit is genuinely too low for your workload, raise the EML size limit on the mail service side; do not expect the parser to accept arbitrarily large inputs"],"exampleFix":"// before\nif len(rawEML) > 35*1024*1024 {\n    // proceed anyway\n}\n// after\nif len(rawEML) > maxRawEMLSize {\n    return fmt.Errorf(\"draft raw EML is %d bytes (limit %d); remove large attachments before parsing\", len(rawEML), maxRawEMLSize)\n}\npart, err := draft.Parse(rawEML)","handlingStrategy":"validation","validationCode":"const maxRawEMLSize = 35 * 1024 * 1024\nif len(rawEML) > maxRawEMLSize {\n    return fmt.Errorf(\"raw EML too large: %d > %d bytes\", len(rawEML), maxRawEMLSize)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check raw size before calling Parse, especially for drafts with attachments","Strip or externalize large attachments before full-EML parsing","Document a max attachment budget for any automated draft-processing pipeline"],"tags":["mail","draft","size-limit","input-validation"],"backgroundTag":"payload-size-limit-exceeded","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"}