From 7adc90e229b78a4e2aa556ae384ff62445425bdd Mon Sep 17 00:00:00 2001 From: Martin Ashby Date: Sun, 4 Jul 2021 22:12:26 +0100 Subject: Fix crash in alps theme when common mailboxes are not present. Fixes https://todo.sr.ht/~migadu/alps/154 Signed-off-by: Martin Ashby --- plugins/base/routes.go | 54 ++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 24 deletions(-) (limited to 'plugins') diff --git a/plugins/base/routes.go b/plugins/base/routes.go index 925da33..9b88ee5 100644 --- a/plugins/base/routes.go +++ b/plugins/base/routes.go @@ -98,16 +98,39 @@ type MailboxDetails struct { // Organizes mailboxes into common/uncommon categories type CategorizedMailboxes struct { Common struct { - Inbox MailboxDetails - Drafts MailboxDetails - Sent MailboxDetails - Junk MailboxDetails - Trash MailboxDetails - Archive MailboxDetails + Inbox *MailboxDetails + Drafts *MailboxDetails + Sent *MailboxDetails + Junk *MailboxDetails + Trash *MailboxDetails + Archive *MailboxDetails } Additional []MailboxDetails } +func (cc *CategorizedMailboxes) Append(mi MailboxInfo, status *MailboxStatus) { + name := mi.Name + details := &MailboxDetails{ + Info: &mi, + Status: status, + } + if name == "INBOX" { + cc.Common.Inbox = details + } else if name == "Drafts" { + cc.Common.Drafts = details + } else if name == "Sent" { + cc.Common.Sent = details + } else if name == "Junk" { + cc.Common.Junk = details + } else if name == "Trash" { + cc.Common.Trash = details + } else if name == "Archive" { + cc.Common.Archive = details + } else { + cc.Additional = append(cc.Additional, *details) + } +} + func newIMAPBaseRenderData(ctx *alps.Context, base *alps.BaseRenderData) (*IMAPBaseRenderData, error) { @@ -158,14 +181,6 @@ func newIMAPBaseRenderData(ctx *alps.Context, } var categorized CategorizedMailboxes - mmap := map[string]*MailboxDetails{ - "INBOX": &categorized.Common.Inbox, - "Drafts": &categorized.Common.Drafts, - "Sent": &categorized.Common.Sent, - "Junk": &categorized.Common.Junk, - "Trash": &categorized.Common.Trash, - "Archive": &categorized.Common.Archive, - } for i, _ := range mailboxes { // Populate unseen & active states @@ -180,16 +195,7 @@ func newIMAPBaseRenderData(ctx *alps.Context, } status, _ := subscriptions[mailboxes[i].Name] - if ptr, ok := mmap[mailboxes[i].Name]; ok { - ptr.Info = &mailboxes[i] - ptr.Status = status - } else { - categorized.Additional = append(categorized.Additional, - MailboxDetails{ - Info: &mailboxes[i], - Status: status, - }) - } + categorized.Append(mailboxes[i], status) } return &IMAPBaseRenderData{ -- cgit v1.2.3