aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2020-05-13 18:18:13 +0200
committerSimon Ser <contact@emersion.fr>2020-05-13 18:18:13 +0200
commit3036cc44362f6965b7e90887965f8e5acc34ddf0 (patch)
treedc5e18e065e4992864468e43422fbff1dd2706af /plugins
parent37be46c047f03cadb5c8a53ff803d46c62fdd2f4 (diff)
downloadalps-3036cc44362f6965b7e90887965f8e5acc34ddf0.tar.gz
alps-3036cc44362f6965b7e90887965f8e5acc34ddf0.zip
plugins/base: fix mailbox unread count
Diffstat (limited to 'plugins')
-rwxr-xr-xplugins/base/imap.go33
-rw-r--r--plugins/base/routes.go8
2 files changed, 29 insertions, 12 deletions
diff --git a/plugins/base/imap.go b/plugins/base/imap.go
index cf028da..a693228 100755
--- a/plugins/base/imap.go
+++ b/plugins/base/imap.go
@@ -27,16 +27,6 @@ func (mbox *MailboxInfo) URL() *url.URL {
}
}
-type MailboxStatus struct {
- *imap.MailboxStatus
-}
-
-func (mbox *MailboxStatus) URL() *url.URL {
- return &url.URL{
- Path: fmt.Sprintf("/mailbox/%v", url.PathEscape(mbox.Name)),
- }
-}
-
func listMailboxes(conn *imapclient.Client) ([]MailboxInfo, error) {
ch := make(chan *imap.MailboxInfo, 10)
done := make(chan error, 1)
@@ -65,6 +55,29 @@ func listMailboxes(conn *imapclient.Client) ([]MailboxInfo, error) {
return mailboxes, nil
}
+type MailboxStatus struct {
+ *imap.MailboxStatus
+}
+
+func (mbox *MailboxStatus) URL() *url.URL {
+ return &url.URL{
+ Path: fmt.Sprintf("/mailbox/%v", url.PathEscape(mbox.Name)),
+ }
+}
+
+func getMailboxStatus(conn *imapclient.Client, name string) (*MailboxStatus, error) {
+ items := []imap.StatusItem{
+ imap.StatusMessages,
+ imap.StatusUidValidity,
+ imap.StatusUnseen,
+ }
+ status, err := conn.Status(name, items)
+ if err != nil {
+ return nil, fmt.Errorf("failed to get mailbox status: %v", err)
+ }
+ return &MailboxStatus{status}, nil
+}
+
type mailboxType int
const (
diff --git a/plugins/base/routes.go b/plugins/base/routes.go
index 2d4cb8c..a389495 100644
--- a/plugins/base/routes.go
+++ b/plugins/base/routes.go
@@ -111,7 +111,9 @@ func handleGetMailbox(ctx *alps.Context) error {
if err != nil {
return err
}
- mbox = &MailboxStatus{c.Mailbox()}
+ if mbox, err = getMailboxStatus(c, mboxName); err != nil {
+ return err
+ }
return nil
})
if err != nil {
@@ -213,7 +215,9 @@ func handleGetPart(ctx *alps.Context, raw bool) error {
if msg, part, err = getMessagePart(c, mboxName, uid, partPath); err != nil {
return err
}
- mbox = &MailboxStatus{c.Mailbox()}
+ if mbox, err = getMailboxStatus(c, mboxName); err != nil {
+ return err
+ }
return nil
})
if err != nil {