Improve Performance [Client] [ListMessages] [Grab Body] Optimize Memory Usage (#3)

- [+] fix(list_messages.go): optimize buffer handling in ListMessages function by resetting buffer before putting it back in the pool

Reviewed-on: #3
Co-authored-by: H0llyW00dzZ <h0llyw00dzz@pm.me>
Co-committed-by: H0llyW00dzZ <h0llyw00dzz@pm.me>
This commit is contained in:
H0llyW00dzZ 2025-01-24 05:18:55 +00:00 committed by H0llyW00dzZ
parent ff4bd67ceb
commit 9ce7f8dc5c

View File

@ -70,12 +70,11 @@ func (c *IMAPClient) ListMessages(mailbox string, numMessages uint32, config Mes
if config.GrabBody {
for _, literal := range msg.Body {
buf := bytebufferpool.Get()
defer bytebufferpool.Put(buf)
_, err := buf.ReadFrom(literal)
if err == nil {
if _, err := buf.ReadFrom(literal); err == nil {
details.Body = buf.String()
}
buf.Reset() // Reset the buffer before returning it to the pool.
bytebufferpool.Put(buf)
}
}
results = append(results, details)