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.
This commit is contained in:
Winni Neessen 2023-10-13 16:27:57 +02:00
parent a3b3deb467
commit 54ccb80925
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D

11
eml.go
View file

@ -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