summary refs log tree commit diff stats
path: root/worker/notmuch/message.go
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2021-02-08 08:40:07 +0100
committerReto Brunner <reto@labrat.space>2021-02-08 08:40:07 +0100
commitdb6848fe1b77bc7f2a657231307d2a4271d41482 (patch)
tree1813b7a01427e6e161ca7f2bf197287fad85f75a /worker/notmuch/message.go
parent077063ba4ba3dbf0a7a43c58c73bc906ed4684d2 (diff)
downloadaerc-db6848fe1b77bc7f2a657231307d2a4271d41482.tar.gz
notmuch: don't read the full file into memory
Diffstat (limited to 'worker/notmuch/message.go')
-rw-r--r--worker/notmuch/message.go12
1 files changed, 3 insertions, 9 deletions
diff --git a/worker/notmuch/message.go b/worker/notmuch/message.go
index 82d00f3..10fbabc 100644
--- a/worker/notmuch/message.go
+++ b/worker/notmuch/message.go
@@ -3,10 +3,9 @@
 package notmuch
 
 import (
-	"bytes"
+	"bufio"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"os"
 
 	"git.sr.ht/~sircmpwn/aerc/models"
@@ -22,7 +21,7 @@ type Message struct {
 	db  *notmuch.DB
 }
 
-// NewReader reads a message into memory and returns an io.Reader for it.
+// NewReader returns a reader for a message
 func (m *Message) NewReader() (io.Reader, error) {
 	name, err := m.Filename()
 	if err != nil {
@@ -32,12 +31,7 @@ func (m *Message) NewReader() (io.Reader, error) {
 	if err != nil {
 		return nil, err
 	}
-	defer f.Close()
-	b, err := ioutil.ReadAll(f)
-	if err != nil {
-		return nil, err
-	}
-	return bytes.NewReader(b), nil
+	return bufio.NewReader(f), nil
 }
 
 // MessageInfo populates a models.MessageInfo struct for the message.