Fix plain mbox reader buffer aliasing

This commit is contained in:
DonVoo 2026-07-15 00:57:16 +02:00
parent e63a513cff
commit 6c4073a01c
3 changed files with 134 additions and 2 deletions

View file

@ -439,7 +439,7 @@ func readMboxMessagesBytes(b []byte) [][]byte {
for _, line := range lines {
if bytes.HasPrefix(line, []byte("From ")) {
if inMsg && cur.Len() > 0 {
msgs = append(msgs, bytes.TrimRight(cur.Bytes(), "\n"))
msgs = append(msgs, cloneTrimmedMessage(cur.Bytes()))
cur.Reset()
}
inMsg = true
@ -455,11 +455,16 @@ func readMboxMessagesBytes(b []byte) [][]byte {
_ = cur.WriteByte('\n')
}
if inMsg && cur.Len() > 0 {
msgs = append(msgs, bytes.TrimRight(cur.Bytes(), "\n"))
msgs = append(msgs, cloneTrimmedMessage(cur.Bytes()))
}
return msgs
}
func cloneTrimmedMessage(b []byte) []byte {
trimmed := bytes.TrimRight(b, "\n")
return append([]byte(nil), trimmed...)
}
func readMboxListFromIndex(path string) ([]MboxEntry, bool) {
accountID, folder, ok := mboxIndexContext(path)
if !ok {