~bigbes/core-go

c05af16cf4fb6c318324f390eea49acda1e76b00 — Robin Jarry 1 year, 7 months ago 78a07dc
email: fix partial bodies

Depending on the email and buffer size, cleartext.Close() and
body.Close() may happen *after* buf.Bytes() is called; producing
incomplete emails, interrupted in the middle of the body.

Make sure to close both *before* getting the buffer contents.

Fixes: db4d67a2a6fb ("email: fix empty emails sent on retries")
Signed-off-by: Robin Jarry <robin@jarry.cc>
1 files changed, 2 insertions(+), 2 deletions(-)

M email/worker.go
M email/worker.go => email/worker.go +2 -2
@@ 157,7 157,6 @@ func EnqueueStd(ctx context.Context, header mail.Header,
			cleartext = nopWriteCloser{&buf}
		}
	}
	defer cleartext.Close()

	var inlineHeader mail.Header
	inlineHeader.SetContentType("text/plain", map[string]string{


@@ 168,12 167,13 @@ func EnqueueStd(ctx context.Context, header mail.Header,
	if err != nil {
		panic(err)
	}
	defer body.Close()

	_, err = io.Copy(body, bodyReader)
	if err != nil {
		log.Fatal(err)
	}
	body.Close()
	cleartext.Close()

	return queue.Enqueue(NewTask(buf.Bytes(), rcpts))
}