about summary refs log tree commit diff stats
path: root/worker/imap
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-01-09 20:39:00 -0500
committerDrew DeVault <sir@cmpwn.com>2018-01-09 20:39:00 -0500
commit6394e386c2a88c3b376cd422a7b7ce5ae7534984 (patch)
tree2d78f622096e439cf5d91a090999f5c522796c42 /worker/imap
parent7d0edcc9e7ecdedb8cabafac1167581d7205596e (diff)
downloadaerc-6394e386c2a88c3b376cd422a7b7ce5ae7534984.tar.gz
Initial pass on worker/UI message passing
Diffstat (limited to 'worker/imap')
-rw-r--r--worker/imap/worker.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/worker/imap/worker.go b/worker/imap/worker.go
new file mode 100644
index 0000000..a095e60
--- /dev/null
+++ b/worker/imap/worker.go
@@ -0,0 +1,58 @@
+package imap
+
+import (
+	"git.sr.ht/~sircmpwn/aerc2/worker/types"
+
+	"fmt"
+)
+
+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:
+		w.messages <- &types.Ack{
+			Message: types.RespondTo(msg),
+		}
+	default:
+		w.messages <- &types.Unsupported{
+			Message: types.RespondTo(_msg),
+		}
+	}
+}
+
+func (w *IMAPWorker) Run() {
+	// TODO: IMAP shit
+	for {
+		select {
+		case msg := <-w.actions:
+			fmt.Printf("<= %T: %+v\n", msg, msg)
+			w.handleMessage(msg)
+		default:
+			// no-op
+		}
+	}
+}
>34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123