diff options
author | Simon Ser <contact@emersion.fr> | 2020-05-28 12:09:44 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2020-05-28 12:09:44 +0200 |
commit | 522454e00986053c86060f8a03d39a626c540652 (patch) | |
tree | 8a741c1b6cb43f34055c7bdfe2b749fed47fb59d /plugins/base | |
parent | 9a7acd27919900edae5a8cdda29e02fd96d2f1ce (diff) | |
download | alps-522454e00986053c86060f8a03d39a626c540652.tar.gz alps-522454e00986053c86060f8a03d39a626c540652.zip |
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
Diffstat (limited to 'plugins/base')
-rwxr-xr-x | plugins/base/imap.go | 7 | ||||
-rw-r--r-- | plugins/base/routes.go | 8 |
2 files changed, 7 insertions, 8 deletions
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 { |