about summary refs log tree commit diff stats
path: root/commands
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2020-05-09 11:50:31 +0200
committerDrew DeVault <sir@cmpwn.com>2020-05-11 09:47:34 -0400
commitea2646fc039a572491ba8cc8e2879b7bf61c25dd (patch)
tree3608b8064e4f67f1f53e177ddad2e5f5ae9a49d5 /commands
parent381c1fc05f6de95accbb520769d0cc9196955cf4 (diff)
downloadaerc-ea2646fc039a572491ba8cc8e2879b7bf61c25dd.tar.gz
Change MarkedMessages to return uids
Especially if one tries to interact with all marked messages there could be
the case that not all headers are fetched yet, hence the messageInfo is still nil.

This segfaults a lot of commands which in principle only need the uid to complete.

If we switch to uids, this issue can be alleviated for those commands.
Diffstat (limited to 'commands')
-rw-r--r--commands/msg/utils.go17
-rw-r--r--commands/util.go17
2 files changed, 25 insertions, 9 deletions
diff --git a/commands/msg/utils.go b/commands/msg/utils.go
index ae25535..cad0f82 100644
--- a/commands/msg/utils.go
+++ b/commands/msg/utils.go
@@ -18,12 +18,7 @@ func newHelper(aerc *widgets.Aerc) *helper {
 }
 
 func (h *helper) markedOrSelectedUids() ([]uint32, error) {
-	msgs, err := commands.MarkedOrSelected(h.msgProvider)
-	if err != nil {
-		return nil, err
-	}
-	uids := commands.UidsFromMessageInfos(msgs)
-	return uids, nil
+	return commands.MarkedOrSelected(h.msgProvider)
 }
 
 func (h *helper) store() (*lib.MessageStore, error) {
@@ -43,5 +38,13 @@ func (h *helper) account() (*widgets.AccountView, error) {
 }
 
 func (h *helper) messages() ([]*models.MessageInfo, error) {
-	return commands.MarkedOrSelected(h.msgProvider)
+	uid, err := commands.MarkedOrSelected(h.msgProvider)
+	if err != nil {
+		return nil, err
+	}
+	store, err := h.store()
+	if err != nil {
+		return nil, err
+	}
+	return commands.MsgInfoFromUids(store, uid)
 }
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
+}
f='#n264'>264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585