2018-01-10 02:39:00 +01:00
|
|
|
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"
|
2018-01-10 02:39:00 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
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) {
|
2018-01-10 02:39:00 +01:00
|
|
|
case types.Ping:
|
2018-01-10 03:24:50 +01:00
|
|
|
w.messages <- types.Ack{
|
2018-01-10 02:39:00 +01:00
|
|
|
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),
|
2018-01-10 02:39:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2018-01-10 02:39:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|