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

Function decodeBytes

internal/mailparse/attachments.go:123–145  ·  view source on GitHub ↗

decodeBytes reads a body applying its Content-Transfer-Encoding, returning raw bytes (binary-safe — unlike decode(), which is for text bodies).

(body io.Reader, cte string)

Source from the content-addressed store, hash-verified

121// decodeBytes reads a body applying its Content-Transfer-Encoding, returning raw
122// bytes (binary-safe — unlike decode(), which is for text bodies).
123func decodeBytes(body io.Reader, cte string) []byte {
124 switch strings.ToLower(strings.TrimSpace(cte)) {
125 case "base64":
126 raw, _ := io.ReadAll(body)
127 clean := strings.Map(func(r rune) rune {
128 if r == '\r' || r == '\n' || r == ' ' || r == '\t' {
129 return -1
130 }
131 return r
132 }, string(raw))
133 dec, err := base64.StdEncoding.DecodeString(clean)
134 if err != nil {
135 return raw // not valid base64 — hand back what we have
136 }
137 return dec
138 case "quoted-printable":
139 b, _ := io.ReadAll(quotedprintable.NewReader(body))
140 return b
141 default:
142 b, _ := io.ReadAll(body)
143 return b
144 }
145}

Callers 1

collectAttachmentsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected