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)
| 65 | // walk. maxBytes <= 0 uses DefaultMaxBytes (applies to Text only). Best-effort: |
| 66 | // a parse failure yields the best content available, never an error. |
| 67 | func 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. |