msgstore: fetch missing headers in visual mode

fetches missing headers when in visual selection mode. This prevents
large archive operations from panicking due to a nil pointer
dereference.

The archive command will return an error to the ui when a nil message is
encountered to signal that the message store is not ready yet.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
This commit is contained in:
Koni Marti 2022-01-22 14:54:11 +01:00 committed by Robin Jarry
parent 44f81c87e4
commit e5ad877af5
2 changed files with 10 additions and 0 deletions

View File

@ -188,6 +188,9 @@ func MsgInfoFromUids(store *lib.MessageStore, uids []uint32) ([]*models.MessageI
if !ok { if !ok {
return nil, fmt.Errorf("uid not found") return nil, fmt.Errorf("uid not found")
} }
if infos[i] == nil {
return nil, fmt.Errorf("message store not ready yet")
}
} }
return infos, nil return infos, nil
} }

View File

@ -523,6 +523,13 @@ func (store *MessageStore) updateVisual() {
for _, uid := range visUids { for _, uid := range visUids {
store.marked[uid] = struct{}{} store.marked[uid] = struct{}{}
} }
missing := make([]uint32, 0)
for _, uid := range visUids {
if msg, _ := store.Messages[uid]; msg == nil {
missing = append(missing, uid)
}
}
store.FetchHeaders(missing, nil)
} }
func (store *MessageStore) NextPrev(delta int) { func (store *MessageStore) NextPrev(delta int) {