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)
| 121 | // decodeBytes reads a body applying its Content-Transfer-Encoding, returning raw |
| 122 | // bytes (binary-safe — unlike decode(), which is for text bodies). |
| 123 | func 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 | } |
no outgoing calls
no test coverage detected