aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Ashby <martin@ashbysoft.com>2021-07-04 22:12:26 +0100
committerSimon Ser <contact@emersion.fr>2021-07-05 11:18:53 +0200
commit7adc90e229b78a4e2aa556ae384ff62445425bdd (patch)
tree4ebbfe792a82ab24ef30ae0b466f286ed4cf7b13
parent765eeca8ce4ad4364d9e1b05d4b6f6645f5f42cf (diff)
downloadalps-7adc90e229b78a4e2aa556ae384ff62445425bdd.tar.gz
alps-7adc90e229b78a4e2aa556ae384ff62445425bdd.zip
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>
-rw-r--r--plugins/base/routes.go54
1 files changed, 30 insertions, 24 deletions
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{