util: fetch message headers for nil messages
Fix large archive operations that covers messages in the store with
unfetched headers. Commit e5ad877af5
("msgstore: fetch missing headers
in visual mode") fixed this for the visual selection mode but omitted
the case when 'mark -a' is used to mark all messages.
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
parent
22e6c9e4fa
commit
16dbb94221
3 changed files with 28 additions and 6 deletions
commands
|
@ -16,6 +16,7 @@ import (
|
|||
"git.sr.ht/~rjarry/aerc/logging"
|
||||
"git.sr.ht/~rjarry/aerc/models"
|
||||
"git.sr.ht/~rjarry/aerc/widgets"
|
||||
"git.sr.ht/~rjarry/aerc/worker/types"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/mitchellh/go-homedir"
|
||||
)
|
||||
|
@ -185,8 +186,9 @@ func UidsFromMessageInfos(msgs []*models.MessageInfo) []uint32 {
|
|||
return uids
|
||||
}
|
||||
|
||||
func MsgInfoFromUids(store *lib.MessageStore, uids []uint32) ([]*models.MessageInfo, error) {
|
||||
func MsgInfoFromUids(store *lib.MessageStore, uids []uint32, statusInfo func(string)) ([]*models.MessageInfo, error) {
|
||||
infos := make([]*models.MessageInfo, len(uids))
|
||||
needHeaders := make([]uint32, 0)
|
||||
for i, uid := range uids {
|
||||
var ok bool
|
||||
infos[i], ok = store.Messages[uid]
|
||||
|
@ -194,9 +196,24 @@ func MsgInfoFromUids(store *lib.MessageStore, uids []uint32) ([]*models.MessageI
|
|||
return nil, fmt.Errorf("uid not found")
|
||||
}
|
||||
if infos[i] == nil {
|
||||
return nil, fmt.Errorf("message store not ready yet")
|
||||
needHeaders = append(needHeaders, uid)
|
||||
}
|
||||
}
|
||||
if len(needHeaders) > 0 {
|
||||
store.FetchHeaders(needHeaders, func(msg types.WorkerMessage) {
|
||||
var info string
|
||||
switch m := msg.(type) {
|
||||
case *types.Done:
|
||||
info = "All headers fetched. Please repeat command."
|
||||
case *types.Error:
|
||||
info = fmt.Sprintf("Encountered error while fetching headers: %v", m.Error)
|
||||
}
|
||||
if statusInfo != nil {
|
||||
statusInfo(info)
|
||||
}
|
||||
})
|
||||
return nil, fmt.Errorf("Fetching missing message headers. Please wait.")
|
||||
}
|
||||
return infos, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue