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
This commit is contained in:
parent
9a7acd2791
commit
522454e009
2 changed files with 7 additions and 8 deletions
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue