Issue IMAP SELECT command

This commit is contained in:
Drew DeVault 2019-01-13 16:18:10 -05:00
parent cf66462000
commit 2750f99a60
4 changed files with 53 additions and 1 deletions

View file

@ -47,6 +47,7 @@ func (dirlist *DirectoryList) UpdateList(done func(dirs []string)) {
func (dirlist *DirectoryList) Select(name string) { func (dirlist *DirectoryList) Select(name string) {
dirlist.selected = name dirlist.selected = name
dirlist.worker.PostAction(&types.OpenDirectory{Directory: name}, nil)
dirlist.Invalidate() dirlist.Invalidate()
} }

20
worker/imap/open.go Normal file
View file

@ -0,0 +1,20 @@
package imap
import (
"git.sr.ht/~sircmpwn/aerc2/worker/types"
)
func (imapw *IMAPWorker) handleOpenDirectory(msg *types.OpenDirectory) {
imapw.worker.Logger.Printf("Opening %s", msg.Directory)
go func() {
_, err := imapw.client.Select(msg.Directory, false)
if err != nil {
imapw.worker.PostMessage(&types.Error{
Message: types.RespondTo(msg),
Error: err,
}, nil)
} else {
imapw.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil)
}
}()
}

View file

@ -149,12 +149,30 @@ func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error {
w.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil) w.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil)
case *types.ListDirectories: case *types.ListDirectories:
w.handleListDirectories(msg) w.handleListDirectories(msg)
case *types.OpenDirectory:
w.handleOpenDirectory(msg)
default: default:
return errUnsupported return errUnsupported
} }
return nil return nil
} }
func (w *IMAPWorker) handleImapUpdate(update client.Update) {
w.worker.Logger.Printf("(= %T", update)
switch update := update.(type) {
case *client.MailboxUpdate:
status := update.Mailbox
w.worker.PostMessage(&types.DirectoryInfo{
ReadOnly: status.ReadOnly,
Flags: status.Flags,
Exists: int(status.Messages),
Recent: int(status.Recent),
Unseen: int(status.Unseen),
}, nil)
}
}
func (w *IMAPWorker) Run() { func (w *IMAPWorker) Run() {
for { for {
select { select {
@ -171,7 +189,7 @@ func (w *IMAPWorker) Run() {
}, nil) }, nil)
} }
case update := <-w.updates: case update := <-w.updates:
w.worker.Logger.Printf("(= %T", update) w.handleImapUpdate(update)
} }
} }
} }

View file

@ -63,6 +63,11 @@ type ListDirectories struct {
Message Message
} }
type OpenDirectory struct {
Message
Directory string
}
// Messages // Messages
type CertificateApprovalRequest struct { type CertificateApprovalRequest struct {
@ -75,3 +80,11 @@ type Directory struct {
Attributes []string Attributes []string
Name string Name string
} }
type DirectoryInfo struct {
Message
ReadOnly bool
Flags []string
Exists, Recent, Unseen int
}