mirror of
https://github.com/wneessen/go-mail.git
synced 2024-12-23 02:50:39 +01:00
#145: Support for quoted-printable encoding in email parser
Added support for quoted-printable encoding in email parser to increase its functionality. The change includes a case handling feature for 'EncodingQP' and related conversions to allow for proper message body reading and encoding setting. This improves the robustness and the scope of email content types that the parser can handle."
This commit is contained in:
parent
e7c717d0fc
commit
a3b3deb467
1 changed files with 17 additions and 8 deletions
25
eml.go
25
eml.go
|
@ -9,6 +9,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"mime"
|
||||
"mime/quotedprintable"
|
||||
nm "net/mail"
|
||||
"os"
|
||||
"strings"
|
||||
|
@ -132,16 +133,24 @@ func parseEMLBodyParts(pm *nm.Message, mbbuf *bytes.Buffer, m *Msg) error {
|
|||
m.SetCharset(Charset(v))
|
||||
}
|
||||
|
||||
if cte := pm.Header.Get(HeaderContentTransferEnc.String()); cte != "" {
|
||||
switch strings.ToLower(cte) {
|
||||
case NoEncoding.String():
|
||||
m.SetEncoding(NoEncoding)
|
||||
}
|
||||
}
|
||||
|
||||
cte := pm.Header.Get(HeaderContentTransferEnc.String())
|
||||
switch strings.ToLower(mt) {
|
||||
case TypeTextPlain.String():
|
||||
m.SetBodyString(TypeTextPlain, mbbuf.String())
|
||||
if cte == NoEncoding.String() {
|
||||
m.SetEncoding(NoEncoding)
|
||||
m.SetBodyString(TypeTextPlain, mbbuf.String())
|
||||
break
|
||||
}
|
||||
if cte == EncodingQP.String() {
|
||||
m.SetEncoding(EncodingQP)
|
||||
qpr := quotedprintable.NewReader(mbbuf)
|
||||
qpbuf := bytes.Buffer{}
|
||||
if _, err := qpbuf.ReadFrom(qpr); err != nil {
|
||||
return fmt.Errorf("failed to read quoted-printable body: %w", err)
|
||||
}
|
||||
m.SetBodyString(TypeTextPlain, qpbuf.String())
|
||||
break
|
||||
}
|
||||
default:
|
||||
}
|
||||
return nil
|
||||
|
|
Loading…
Reference in a new issue