Fix in writeBody method which returned wrong bytes amounts for encoded message bodies

This commit is contained in:
Winni Neessen 2022-03-19 16:56:14 +01:00
parent b6d90eac6a
commit d6f131c36d
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D

View file

@ -1,6 +1,7 @@
package mail package mail
import ( import (
"bytes"
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"io" "io"
@ -251,12 +252,13 @@ func (mw *msgWriter) writeBody(f func(io.Writer) (int64, error), e Encoding) {
if mw.d > 0 { if mw.d > 0 {
w = mw.pw w = mw.pw
} }
wbuf := bytes.Buffer{}
switch e { switch e {
case EncodingQP: case EncodingQP:
ew = quotedprintable.NewWriter(w) ew = quotedprintable.NewWriter(&wbuf)
case EncodingB64: case EncodingB64:
ew = base64.NewEncoder(base64.StdEncoding, w) ew = base64.NewEncoder(base64.StdEncoding, &wbuf)
case NoEncoding: case NoEncoding:
n, mw.err = f(w) n, mw.err = f(w)
mw.n += n mw.n += n
@ -265,7 +267,8 @@ func (mw *msgWriter) writeBody(f func(io.Writer) (int64, error), e Encoding) {
ew = quotedprintable.NewWriter(w) ew = quotedprintable.NewWriter(w)
} }
n, mw.err = f(ew) _, mw.err = f(ew)
mw.n += int64(n)
mw.err = ew.Close() mw.err = ew.Close()
n, mw.err = io.Copy(w, &wbuf)
mw.n += n
} }