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

Function extractText

internal/mailparse/parse.go:108–123  ·  view source on GitHub ↗

extractText walks the MIME tree and returns the best text representation — the first text/plain part, or (failing that) the first text/html rendered to text — together with the first text/html part decoded but NOT rendered to text (htmlRaw, for display). Falls back to the raw body if MIME parsing fa

(raw []byte)

Source from the content-addressed store, hash-verified

106// text — together with the first text/html part decoded but NOT rendered to
107// text (htmlRaw, for display). Falls back to the raw body if MIME parsing fails.
108func extractText(raw []byte) (text, htmlRaw string) {
109 msg, err := mail.ReadMessage(bytes.NewReader(raw))
110 if err != nil {
111 return string(raw), ""
112 }
113 plain, htmlText, htmlRaw := walkParts(msg.Header.Get("Content-Type"), msg.Header.Get("Content-Transfer-Encoding"), msg.Body, 0)
114 if plain != "" {
115 return plain, htmlRaw
116 }
117 if htmlText != "" {
118 return htmlText, htmlRaw
119 }
120 // No recognized text part — return the decoded top-level body.
121 b, _ := io.ReadAll(msg.Body)
122 return string(b), htmlRaw
123}
124
125// walkParts returns the first text/plain, the first text/html rendered to text,
126// and the first text/html decoded as-is (htmlRaw) found anywhere in the

Callers 1

ParseFunction · 0.70

Calls 2

walkPartsFunction · 0.85
GetMethod · 0.65

Tested by

no test coverage detected