diff options
Diffstat (limited to 'plugins')
-rwxr-xr-x | plugins/base/imap.go | 33 | ||||
-rw-r--r-- | plugins/base/routes.go | 8 |
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 { |