decodeTransferEncoding decodes the Content-Transfer-Encoding wrapping of a body part. Unknown encodings pass through unchanged — better to surface raw bytes than drop the part entirely.
(data []byte, encoding string)
| 137 | // of a body part. Unknown encodings pass through unchanged — better to |
| 138 | // surface raw bytes than drop the part entirely. |
| 139 | func decodeTransferEncoding(data []byte, encoding string) []byte { |
| 140 | switch strings.ToLower(strings.TrimSpace(encoding)) { |
| 141 | case "quoted-printable": |
| 142 | decoded, err := io.ReadAll(quotedprintable.NewReader(bytes.NewReader(data))) |
| 143 | if err != nil { |
| 144 | return data |
| 145 | } |
| 146 | return decoded |
| 147 | case "base64": |
| 148 | decoded, err := base64.StdEncoding.DecodeString(string(bytes.TrimSpace(data))) |
| 149 | if err != nil { |
| 150 | return data |
| 151 | } |
| 152 | return decoded |
| 153 | default: |
| 154 | return data |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | // ForwardAttachments extracts the stored attachment parts of the message being |
| 159 | // forwarded and converts them to the outbound Attachment shape (base64-encoded |