Skip to content

Commit b452b8b

Browse files
committed
mail: reset the content buffer before each part
When io.Copy from a part body failed, the loop continued without clearing the shared buffer, so leftover bytes from the failed part were carried into the next text part. Reset the buffer at the start of every iteration so each part starts clean. Signed-off-by: Robin Jarry <robin@jarry.cc>
1 parent d2fa2b9 commit b452b8b

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

‎pkg/mail/content.go‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func findTextParts(m *mail.Reader) []textPart {
5555
continue
5656
}
5757

58+
buf.Reset()
5859
if n, err := io.Copy(&buf, part.Body); err != nil {
5960
log.Warnf("failed to read part body: %s", err)
6061
continue
@@ -66,8 +67,6 @@ func findTextParts(m *mail.Reader) []textPart {
6667
payload: strings.ReplaceAll(buf.String(), "\r\n", "\n"),
6768
subtype: subtype,
6869
})
69-
70-
buf.Reset()
7170
}
7271

7372
return results

0 commit comments

Comments
 (0)