aerc/worker/imap/worker.go

58 lines
986 B
Go
Raw Normal View History

package imap
import (
2018-01-10 13:35:26 +00:00
"time"
2018-01-10 16:19:45 +00:00
"git.sr.ht/~sircmpwn/aerc2/worker/types"
)
type IMAPWorker struct {
messages chan types.WorkerMessage
actions chan types.WorkerMessage
}
func NewIMAPWorker() *IMAPWorker {
return &IMAPWorker{
messages: make(chan types.WorkerMessage, 50),
actions: make(chan types.WorkerMessage, 50),
}
}
func (w *IMAPWorker) GetMessage() types.WorkerMessage {
select {
case msg := <-w.messages:
return msg
default:
return nil
}
}
func (w *IMAPWorker) PostAction(msg types.WorkerMessage) {
w.actions <- msg
}
2018-01-10 16:19:45 +00:00
func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) {
switch msg := msg.(type) {
case types.Ping:
2018-01-10 02:24:50 +00:00
w.messages <- types.Ack{
Message: types.RespondTo(msg),
}
default:
2018-01-10 02:24:50 +00:00
w.messages <- types.Unsupported{
2018-01-10 16:19:45 +00:00
Message: types.RespondTo(msg),
}
}
}
func (w *IMAPWorker) Run() {
// TODO: IMAP shit
for {
select {
case msg := <-w.actions:
w.handleMessage(msg)
default:
2018-01-10 13:35:26 +00:00
time.Sleep(100 * time.Millisecond)
}
}
}