From 54ccb80925bac448b2cc79fe2020b6c7ebdeaf99 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Fri, 13 Oct 2023 16:27:57 +0200 Subject: [PATCH] Add base64 support in email parser Implemented base64 encoding support in the email parser. This addition allows the parser to read and decode base64 encoded emails. --- eml.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/eml.go b/eml.go index 2fd413b..7dd3686 100644 --- a/eml.go +++ b/eml.go @@ -6,6 +6,7 @@ package mail import ( "bytes" + "encoding/base64" "errors" "fmt" "mime" @@ -151,6 +152,16 @@ func parseEMLBodyParts(pm *nm.Message, mbbuf *bytes.Buffer, m *Msg) error { m.SetBodyString(TypeTextPlain, qpbuf.String()) break } + if cte == EncodingB64.String() { + m.SetEncoding(EncodingB64) + b64d := base64.NewDecoder(base64.StdEncoding, mbbuf) + b64buf := bytes.Buffer{} + if _, err := b64buf.ReadFrom(b64d); err != nil { + return fmt.Errorf("failed to read base64 body: %w", err) + } + m.SetBodyString(TypeTextPlain, b64buf.String()) + break + } default: } return nil