summary refs log tree commit diff stats
path: root/commands/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'commands/util.go')
-rw-r--r--commands/util.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/commands/util.go b/commands/util.go
index 5529edb..e3395fd 100644
--- a/commands/util.go
+++ b/commands/util.go
@@ -10,6 +10,7 @@ import (
 	"strings"
 	"time"
 
+	"git.sr.ht/~sircmpwn/aerc/lib"
 	"git.sr.ht/~sircmpwn/aerc/models"
 	"git.sr.ht/~sircmpwn/aerc/widgets"
 	"github.com/gdamore/tcell"
@@ -152,7 +153,7 @@ func listDir(path string, hidden bool) []string {
 
 // MarkedOrSelected returns either all marked messages if any are marked or the
 // selected message instead
-func MarkedOrSelected(pm widgets.ProvidesMessages) ([]*models.MessageInfo, error) {
+func MarkedOrSelected(pm widgets.ProvidesMessages) ([]uint32, error) {
 	// marked has priority over the selected message
 	marked, err := pm.MarkedMessages()
 	if err != nil {
@@ -165,7 +166,7 @@ func MarkedOrSelected(pm widgets.ProvidesMessages) ([]*models.MessageInfo, error
 	if err != nil {
 		return nil, err
 	}
-	return []*models.MessageInfo{msg}, nil
+	return []uint32{msg.Uid}, nil
 }
 
 // UidsFromMessageInfos extracts a uid slice from a slice of MessageInfos
@@ -178,3 +179,15 @@ func UidsFromMessageInfos(msgs []*models.MessageInfo) []uint32 {
 	}
 	return uids
 }
+
+func MsgInfoFromUids(store *lib.MessageStore, uids []uint32) ([]*models.MessageInfo, error) {
+	infos := make([]*models.MessageInfo, len(uids))
+	for i, uid := range uids {
+		var ok bool
+		infos[i], ok = store.Messages[uid]
+		if !ok {
+			return nil, fmt.Errorf("uid not found")
+		}
+	}
+	return infos, nil
+}