Fix crash in alps theme when common mailboxes are not present.
Fixes https://todo.sr.ht/~migadu/alps/154 Signed-off-by: Martin Ashby <martin@ashbysoft.com>
This commit is contained in:
parent
765eeca8ce
commit
7adc90e229
1 changed files with 30 additions and 24 deletions
|
@ -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{
|
||||
|
|
Loading…
Reference in a new issue