maildir,notmuch: pass in-memory message to callback

This fixes piped full message (:pipe -m) being empty.

Fixes: 904ffacb0e ("maildir,notmuch: avoid leaking open files")
Signed-off-by: Nguyễn Gia Phong <mcsinyx@disroot.org>
This commit is contained in:
Nguyễn Gia Phong 2022-01-20 21:40:34 +07:00 committed by Robin Jarry
parent b96326517d
commit bf4abd309e
2 changed files with 14 additions and 2 deletions

View File

@ -1,9 +1,11 @@
package maildir package maildir
import ( import (
"bytes"
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/url" "net/url"
"os" "os"
"path/filepath" "path/filepath"
@ -433,11 +435,15 @@ func (w *Worker) handleFetchFullMessages(msg *types.FetchFullMessages) error {
return err return err
} }
defer r.Close() defer r.Close()
b, err := ioutil.ReadAll(r)
if err != nil {
return err
}
w.worker.PostMessage(&types.FullMessage{ w.worker.PostMessage(&types.FullMessage{
Message: types.RespondTo(msg), Message: types.RespondTo(msg),
Content: &models.FullMessage{ Content: &models.FullMessage{
Uid: uid, Uid: uid,
Reader: r, Reader: bytes.NewReader(b),
}, },
}, nil) }, nil)
} }

View File

@ -5,7 +5,9 @@ package notmuch
import ( import (
"bufio" "bufio"
"bytes"
"fmt" "fmt"
"io/ioutil"
"net/url" "net/url"
"os" "os"
"path/filepath" "path/filepath"
@ -368,11 +370,15 @@ func (w *worker) handleFetchFullMessages(msg *types.FetchFullMessages) error {
return err return err
} }
defer r.Close() defer r.Close()
b, err := ioutil.ReadAll(r)
if err != nil {
return err
}
w.w.PostMessage(&types.FullMessage{ w.w.PostMessage(&types.FullMessage{
Message: types.RespondTo(msg), Message: types.RespondTo(msg),
Content: &models.FullMessage{ Content: &models.FullMessage{
Uid: uid, Uid: uid,
Reader: r, Reader: bytes.NewReader(b),
}, },
}, nil) }, nil)
} }