larksuite/cli · error

draft raw EML is too large (%d bytes, max %d)

Error message

draft raw EML is too large (%d bytes, max %d)

What it means

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.

Source

Thrown at shortcuts/mail/draft/parse.go:52

		Body:    root,
	}
	if err := refreshSnapshot(snapshot); err != nil {
		return nil, err
	}
	return snapshot, nil
}

// maxRawEMLSize is the maximum accepted raw (base64-encoded) EML string length.
// Base64 encodes 3 bytes into 4 chars, so 35 MB covers a 25 MB decoded EML with margin.
const maxRawEMLSize = 35 * 1024 * 1024

func decodeRawEML(raw string) ([]byte, error) {
	raw = strings.TrimSpace(raw)
	if raw == "" {
		return nil, fmt.Errorf("draft raw EML is empty")
	}
	if len(raw) > maxRawEMLSize {
		return nil, fmt.Errorf("draft raw EML is too large (%d bytes, max %d)", len(raw), maxRawEMLSize)
	}
	decoders := []func(string) ([]byte, error){
		base64.URLEncoding.DecodeString,
		base64.RawURLEncoding.DecodeString,
		base64.StdEncoding.DecodeString,
		base64.RawStdEncoding.DecodeString,
	}
	for _, decode := range decoders {
		decoded, err := decode(raw)
		if err == nil {
			return normalizeLineEndings(decoded), nil
		}
	}
	return nil, fmt.Errorf("draft raw EML is not valid base64url")
}

func normalizeLineEndings(in []byte) []byte {
	in = bytes.ReplaceAll(in, []byte("\r\n"), []byte("\n"))

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Trim oversized attachments from the draft before fetching/parsing the raw EML
  2. Use a streaming or partial parser for the attachment payloads instead of parsing the whole EML string
  3. 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

Example fix

// before
if len(rawEML) > 35*1024*1024 {
    // proceed anyway
}
// after
if len(rawEML) > maxRawEMLSize {
    return fmt.Errorf("draft raw EML is %d bytes (limit %d); remove large attachments before parsing", len(rawEML), maxRawEMLSize)
}
part, err := draft.Parse(rawEML)
Defensive patterns

Strategy: validation

Validate before calling

const maxRawEMLSize = 35 * 1024 * 1024
if len(rawEML) > maxRawEMLSize {
    return fmt.Errorf("raw EML too large: %d > %d bytes", len(rawEML), maxRawEMLSize)
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/2061c7336ceebf1c. Report an issue: GitHub.