From 522454e00986053c86060f8a03d39a626c540652 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 28 May 2020 12:09:44 +0200 Subject: base: don't use Client.Mailbox The information returned by Client.Mailbox may be out-of-date. Instead, retrieve the mailbox status from the server each time. Closes: https://todo.sr.ht/~emersion/alps/80 --- plugins/base/imap.go | 7 +++---- plugins/base/routes.go | 8 ++++---- 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'plugins/base') diff --git a/plugins/base/imap.go b/plugins/base/imap.go index 04ce8d7..db9a3f5 100755 --- a/plugins/base/imap.go +++ b/plugins/base/imap.go @@ -344,12 +344,11 @@ func (msg *IMAPMessage) HasFlag(flag string) bool { return false } -func listMessages(conn *imapclient.Client, mboxName string, page, messagesPerPage int) ([]IMAPMessage, error) { - if err := ensureMailboxSelected(conn, mboxName); err != nil { +func listMessages(conn *imapclient.Client, mbox *MailboxStatus, page, messagesPerPage int) ([]IMAPMessage, error) { + if err := ensureMailboxSelected(conn, mbox.Name); err != nil { return nil, err } - mbox := conn.Mailbox() to := int(mbox.Messages) - page*messagesPerPage from := to - messagesPerPage + 1 if from <= 0 { @@ -372,7 +371,7 @@ func listMessages(conn *imapclient.Client, mboxName string, page, messagesPerPag msgs := make([]IMAPMessage, 0, to-from) for msg := range ch { - msgs = append(msgs, IMAPMessage{msg, mboxName}) + msgs = append(msgs, IMAPMessage{msg, mbox.Name}) } if err := <-done; err != nil { diff --git a/plugins/base/routes.go b/plugins/base/routes.go index 9280e1d..d3ff371 100644 --- a/plugins/base/routes.go +++ b/plugins/base/routes.go @@ -104,17 +104,17 @@ func handleGetMailbox(ctx *alps.Context) error { if mailboxes, err = listMailboxes(c); err != nil { return err } + if mbox, err = getMailboxStatus(c, mboxName); err != nil { + return err + } if query != "" { msgs, total, err = searchMessages(c, mboxName, query, page, messagesPerPage) } else { - msgs, err = listMessages(c, mboxName, page, messagesPerPage) + msgs, err = listMessages(c, mbox, page, messagesPerPage) } if err != nil { return err } - if mbox, err = getMailboxStatus(c, mboxName); err != nil { - return err - } if mboxName == "INBOX" { inbox = mbox } else { -- cgit v1.2.3