aerc/worker/imap/worker.go

60 lines
1.0 KiB
Go
Raw Normal View History

package imap
import (
"git.sr.ht/~sircmpwn/aerc2/worker/types"
"fmt"
2018-01-10 13:35:26 +00:00
"time"
)
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
}
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{
Message: types.RespondTo(_msg),
}
}
}
func (w *IMAPWorker) Run() {
// TODO: IMAP shit
for {
select {
case msg := <-w.actions:
2018-01-10 02:24:50 +00:00
fmt.Printf("<= %T\n", msg)
w.handleMessage(msg)
default:
2018-01-10 13:35:26 +00:00
time.Sleep(100 * time.Millisecond)
}
}
}