Attachment names should probably be encoded

This commit is contained in:
Winni Neessen 2022-03-15 12:12:45 +01:00
parent ce1c37bd16
commit a87577d388
Signed by: wneessen
GPG key ID: 385AC9889632126E
2 changed files with 7 additions and 3 deletions

2
msg.go
View file

@ -461,7 +461,7 @@ func (m *Msg) Reset() {
// Write writes the formated Msg into a give io.Writer // Write writes the formated Msg into a give io.Writer
func (m *Msg) Write(w io.Writer) (int64, error) { func (m *Msg) Write(w io.Writer) (int64, error) {
mw := &msgWriter{w: w} mw := &msgWriter{w: w, c: m.charset, en: m.encoder}
mw.writeMsg(m) mw.writeMsg(m)
return mw.n, mw.err return mw.n, mw.err
} }

View file

@ -18,7 +18,9 @@ const MaxHeaderLength = 76
// msgWriter handles the I/O to the io.WriteCloser of the SMTP client // msgWriter handles the I/O to the io.WriteCloser of the SMTP client
type msgWriter struct { type msgWriter struct {
c Charset
d int8 d int8
en mime.WordEncoder
err error err error
mpw [3]*multipart.Writer mpw [3]*multipart.Writer
n int64 n int64
@ -125,7 +127,8 @@ func (mw *msgWriter) addFiles(fl []*File, a bool) {
if mt == "" { if mt == "" {
mt = "application/octet-stream" mt = "application/octet-stream"
} }
f.setHeader(HeaderContentType, fmt.Sprintf(`%s; name="%s"`, mt, f.Name)) f.setHeader(HeaderContentType, fmt.Sprintf(`%s; name="%s"`, mt,
mw.en.Encode(mw.c.String(), f.Name)))
} }
if _, ok := f.getHeader(HeaderContentTransferEnc); !ok { if _, ok := f.getHeader(HeaderContentTransferEnc); !ok {
@ -137,7 +140,8 @@ func (mw *msgWriter) addFiles(fl []*File, a bool) {
if a { if a {
d = "attachment" d = "attachment"
} }
f.setHeader(HeaderContentDisposition, fmt.Sprintf(`%s; filename="%s"`, d, f.Name)) f.setHeader(HeaderContentDisposition, fmt.Sprintf(`%s; filename="%s"`, d,
mw.en.Encode(mw.c.String(), f.Name)))
} }
if !a { if !a {