Fix decoding bug
j3s j3s@c3f.net
Sun, 22 Dec 2019 13:20:37 -0600
1 files changed,
16 insertions(+),
1 deletions(-)
jump to
M
mail/main.go
→
mail/main.go
@@ -173,6 +173,11 @@ if err != nil {
return textBody, htmlBody, embeddedFiles, err } + ContentTransferEncoding, params, err := mime.ParseMediaType(part.Header.Get("Content-Transfer-Encoding")) + if err != nil { + return textBody, htmlBody, embeddedFiles, err + } + switch contentType { case contentTypeTextPlain: ppContent, err := ioutil.ReadAll(part)@@ -180,7 +185,17 @@ if err != nil {
return textBody, htmlBody, embeddedFiles, err } - textBody += strings.TrimSuffix(string(ppContent[:]), "\n") + txt := strings.TrimSuffix(string(ppContent[:]), "\n") + + if ContentTransferEncoding == "base64" { + b, err := base64.StdEncoding.DecodeString(txt) + if err != nil { + return textBody, htmlBody, embeddedFiles, err + } + txt = string(b) + } + + textBody += txt case contentTypeTextHtml: ppContent, err := ioutil.ReadAll(part) if err != nil {