2018-01-10 01:39:00 +00:00
|
|
|
package imap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-01-10 13:35:26 +00:00
|
|
|
"time"
|
2018-01-10 16:19:45 +00:00
|
|
|
|
|
|
|
"git.sr.ht/~sircmpwn/aerc2/worker/types"
|
2018-01-10 01:39:00 +00: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 16:19:45 +00:00
|
|
|
func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) {
|
|
|
|
switch msg := msg.(type) {
|
2018-01-10 01:39:00 +00:00
|
|
|
case types.Ping:
|
2018-01-10 02:24:50 +00:00
|
|
|
w.messages <- types.Ack{
|
2018-01-10 01:39:00 +00:00
|
|
|
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),
|
2018-01-10 01:39:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2018-01-10 01:39:00 +00:00
|
|
|
w.handleMessage(msg)
|
|
|
|
default:
|
2018-01-10 13:35:26 +00:00
|
|
|
time.Sleep(100 * time.Millisecond)
|
2018-01-10 01:39:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|