mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-22 13:50:49 +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
23
eml.go
23
eml.go
|
@ -9,6 +9,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"mime"
|
"mime"
|
||||||
|
"mime/quotedprintable"
|
||||||
nm "net/mail"
|
nm "net/mail"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -132,16 +133,24 @@ func parseEMLBodyParts(pm *nm.Message, mbbuf *bytes.Buffer, m *Msg) error {
|
||||||
m.SetCharset(Charset(v))
|
m.SetCharset(Charset(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
if cte := pm.Header.Get(HeaderContentTransferEnc.String()); cte != "" {
|
cte := pm.Header.Get(HeaderContentTransferEnc.String())
|
||||||
switch strings.ToLower(cte) {
|
|
||||||
case NoEncoding.String():
|
|
||||||
m.SetEncoding(NoEncoding)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch strings.ToLower(mt) {
|
switch strings.ToLower(mt) {
|
||||||
case TypeTextPlain.String():
|
case TypeTextPlain.String():
|
||||||
|
if cte == NoEncoding.String() {
|
||||||
|
m.SetEncoding(NoEncoding)
|
||||||
m.SetBodyString(TypeTextPlain, mbbuf.String())
|
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:
|
default:
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in a new issue