summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorBen Fiedler <git@services.bfiedler.ch>2020-04-24 22:31:39 +0200
committerDrew DeVault <sir@cmpwn.com>2020-05-01 11:10:08 -0400
commit05fa79eb8efa02e39962c08231ec0e40cafe0020 (patch)
tree90cc60bbc6ec1829021abbb219ba9e49d7b653a2 /lib
parentb650bb30a2d3ebd527c66dc7f7b229ca238fe297 (diff)
downloadaerc-05fa79eb8efa02e39962c08231ec0e40cafe0020.tar.gz
store.FetchFull: Change callback type to expose entire message
This is a prerequisite for allowing the FetchFull message to return both
the message content and the message headers.
Diffstat (limited to 'lib')
-rw-r--r--lib/messageview.go4
-rw-r--r--lib/msgstore.go10
2 files changed, 8 insertions, 6 deletions
diff --git a/lib/messageview.go b/lib/messageview.go
index be3b90f..3bf133a 100644
--- a/lib/messageview.go
+++ b/lib/messageview.go
@@ -12,6 +12,7 @@ import (
 
 	"git.sr.ht/~sircmpwn/aerc/models"
 	"git.sr.ht/~sircmpwn/aerc/worker/lib"
+	"git.sr.ht/~sircmpwn/aerc/worker/types"
 )
 
 // This is an abstraction for viewing a message with semi-transparent PGP
@@ -65,7 +66,8 @@ func NewMessageStoreView(messageInfo *models.MessageInfo,
 		nil, nil, messageInfo.BodyStructure}
 
 	if usePGP(messageInfo.BodyStructure) {
-		store.FetchFull([]uint32{messageInfo.Uid}, func(reader io.Reader) {
+		store.FetchFull([]uint32{messageInfo.Uid}, func(fm *types.FullMessage) {
+			reader := fm.Content.Reader
 			pgpReader, err := pgpmail.Read(reader, Keyring, decryptKeys, nil)
 			if err != nil {
 				panic(err)
diff --git a/lib/msgstore.go b/lib/msgstore.go
index 481fcb9..b3a86b3 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -20,7 +20,7 @@ type MessageStore struct {
 	uids []uint32
 
 	selected        int
-	bodyCallbacks   map[uint32][]func(io.Reader)
+	bodyCallbacks   map[uint32][]func(*types.FullMessage)
 	headerCallbacks map[uint32][]func(*types.MessageInfo)
 
 	//marking
@@ -64,7 +64,7 @@ func NewMessageStore(worker *types.Worker,
 
 		selected:        0,
 		marked:          make(map[uint32]struct{}),
-		bodyCallbacks:   make(map[uint32][]func(io.Reader)),
+		bodyCallbacks:   make(map[uint32][]func(*types.FullMessage)),
 		headerCallbacks: make(map[uint32][]func(*types.MessageInfo)),
 
 		defaultSortCriteria: defaultSortCriteria,
@@ -105,7 +105,7 @@ func (store *MessageStore) FetchHeaders(uids []uint32,
 	}
 }
 
-func (store *MessageStore) FetchFull(uids []uint32, cb func(io.Reader)) {
+func (store *MessageStore) FetchFull(uids []uint32, cb func(*types.FullMessage)) {
 	// TODO: this could be optimized by pre-allocating toFetch and trimming it
 	// at the end. In practice we expect to get most messages back in one frame.
 	var toFetch []uint32
@@ -117,7 +117,7 @@ func (store *MessageStore) FetchFull(uids []uint32, cb func(io.Reader)) {
 				if list, ok := store.bodyCallbacks[uid]; ok {
 					store.bodyCallbacks[uid] = append(list, cb)
 				} else {
-					store.bodyCallbacks[uid] = []func(io.Reader){cb}
+					store.bodyCallbacks[uid] = []func(*types.FullMessage){cb}
 				}
 			}
 		}
@@ -233,7 +233,7 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
 			delete(store.pendingBodies, msg.Content.Uid)
 			if cbs, ok := store.bodyCallbacks[msg.Content.Uid]; ok {
 				for _, cb := range cbs {
-					cb(msg.Content.Reader)
+					cb(msg)
 				}
 				delete(store.bodyCallbacks, msg.Content.Uid)
 			}