Another fix for the written byte counting, this time for parts (alt/attach/embed)

This commit is contained in:
Winni Neessen 2022-03-19 18:32:51 +01:00
parent 429c9a1883
commit 68049b568d
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D

View file

@ -260,8 +260,11 @@ func (mw *msgWriter) writeBody(f func(io.Writer) (int64, error), e Encoding) {
case EncodingB64:
ew = base64.NewEncoder(base64.StdEncoding, &wbuf)
case NoEncoding:
n, mw.err = f(w)
_, mw.err = f(&wbuf)
n, mw.err = io.Copy(w, &wbuf)
if mw.d == 0 {
mw.n += n
}
return
default:
ew = quotedprintable.NewWriter(w)
@ -270,5 +273,10 @@ func (mw *msgWriter) writeBody(f func(io.Writer) (int64, error), e Encoding) {
_, mw.err = f(ew)
mw.err = ew.Close()
n, mw.err = io.Copy(w, &wbuf)
// Since the part writer uses the Write() method, we don't need to add the
// bytes twice
if mw.d == 0 {
mw.n += n
}
}