MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / Parse

Function Parse

internal/mailparse/parse.go:67–83  ·  view source on GitHub ↗

Parse extracts the derived view from a raw RFC 5322 message in a single MIME walk. maxBytes <= 0 uses DefaultMaxBytes (applies to Text only). Best-effort: a parse failure yields the best content available, never an error.

(raw []byte, maxBytes int)

Source from the content-addressed store, hash-verified

65// walk. maxBytes <= 0 uses DefaultMaxBytes (applies to Text only). Best-effort:
66// a parse failure yields the best content available, never an error.
67func Parse(raw []byte, maxBytes int) ParsedView {
68 if maxBytes <= 0 {
69 maxBytes = DefaultMaxBytes
70 }
71 bestText, htmlRaw := extractText(raw)
72 text := normalizeWhitespace(stripQuotedReplies(bestText))
73 truncated := false
74 if len(text) > maxBytes {
75 text = strings.TrimSpace(text[:runeBoundary(text, maxBytes)])
76 truncated = true
77 }
78 html := htmlRaw
79 if len(html) > MaxHTMLBytes {
80 html = html[:runeBoundary(html, MaxHTMLBytes)]
81 }
82 return ParsedView{Text: text, Truncated: truncated, HTML: html}
83}
84
85// ParsedBody extracts the injection-reduced text (see ParsedView.Text).
86// truncated is true when the cap cut content. maxBytes <= 0 uses DefaultMaxBytes.

Callers 3

messageViewFromIdentityFunction · 0.92
TestParseHTMLFunction · 0.85
ParsedBodyFunction · 0.85

Calls 4

normalizeWhitespaceFunction · 0.85
stripQuotedRepliesFunction · 0.85
runeBoundaryFunction · 0.85
extractTextFunction · 0.70

Tested by 1

TestParseHTMLFunction · 0.68