aboutsummaryrefslogtreecommitdiffstats
path: root/worker/lib
diff options
context:
space:
mode:
Diffstat (limited to 'worker/lib')
-rw-r--r--worker/lib/parse.go3
-rw-r--r--worker/lib/parse_test.go18
2 files changed, 8 insertions, 13 deletions
diff --git a/worker/lib/parse.go b/worker/lib/parse.go
index 87f94bdd..6d73a1f5 100644
--- a/worker/lib/parse.go
+++ b/worker/lib/parse.go
@@ -211,7 +211,7 @@ func parseAddressList(h *mail.Header, key string) ([]*mail.Address, error) {
// RawMessage is an interface that describes a raw message
type RawMessage interface {
- NewReader() (io.Reader, error)
+ NewReader() (io.ReadCloser, error)
ModelFlags() ([]models.Flag, error)
Labels() ([]string, error)
UID() uint32
@@ -225,6 +225,7 @@ func MessageInfo(raw RawMessage) (*models.MessageInfo, error) {
if err != nil {
return nil, err
}
+ defer r.Close()
msg, err := message.Read(r)
if err != nil {
return nil, fmt.Errorf("could not read message: %v", err)
diff --git a/worker/lib/parse_test.go b/worker/lib/parse_test.go
index 5c0a1b17..12190981 100644
--- a/worker/lib/parse_test.go
+++ b/worker/lib/parse_test.go
@@ -1,9 +1,9 @@
package lib
import (
- "bytes"
"io"
"io/ioutil"
+ "os"
"path/filepath"
"testing"
@@ -36,23 +36,17 @@ func TestMessageInfoHandledError(t *testing.T) {
}
type mockRawMessage struct {
- body []byte
+ path string
}
-func newMockRawMessage(body []byte) *mockRawMessage {
+func newMockRawMessageFromPath(p string) *mockRawMessage {
return &mockRawMessage{
- body: body,
+ path: p,
}
}
-func newMockRawMessageFromPath(p string) *mockRawMessage {
- b, err := ioutil.ReadFile(p)
- die(err)
- return newMockRawMessage(b)
-}
-
-func (m *mockRawMessage) NewReader() (io.Reader, error) {
- return bytes.NewReader(m.body), nil
+func (m *mockRawMessage) NewReader() (io.ReadCloser, error) {
+ return os.Open(m.path)
}
func (m *mockRawMessage) ModelFlags() ([]models.Flag, error) { return nil, nil }
func (m *mockRawMessage) Labels() ([]string, error) { return nil, nil }