aerc/worker/imap/worker.go

58 lines
986 B
Go
Raw Normal View History

package imap
import (
2018-01-10 14:35:26 +01:00
"time"
2018-01-10 17:19:45 +01: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 17:19:45 +01:00
func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) {
switch msg := msg.(type) {
case types.Ping:
2018-01-10 03:24:50 +01:00
w.messages <- types.Ack{
Message: types.RespondTo(msg),
}
default:
2018-01-10 03:24:50 +01:00
w.messages <- types.Unsupported{
2018-01-10 17:19:45 +01: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 14:35:26 +01:00
time.Sleep(100 * time.Millisecond)
}
}
}