summary refs log tree commit diff stats
path: root/worker
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-01-13 16:18:10 -0500
committerDrew DeVault <sir@cmpwn.com>2019-01-13 16:18:10 -0500
commit2750f99a6049322b1361b5bfa4dff3b1df2b36ab (patch)
tree0c18f4a8180f1eda1616c07296d20323edfeab62 /worker
parentcf664620005cf65d060e689fbb27b939dd3192a7 (diff)
downloadaerc-2750f99a6049322b1361b5bfa4dff3b1df2b36ab.tar.gz
Issue IMAP SELECT command
Diffstat (limited to 'worker')
-rw-r--r--worker/imap/open.go20
-rw-r--r--worker/imap/worker.go20
-rw-r--r--worker/types/messages.go13
3 files changed, 52 insertions, 1 deletions
diff --git a/worker/imap/open.go b/worker/imap/open.go
new file mode 100644
index 0000000..d90a292
--- /dev/null
+++ b/worker/imap/open.go
@@ -0,0 +1,20 @@
+package imap
+
+import (
+	"git.sr.ht/~sircmpwn/aerc2/worker/types"
+)
+
+func (imapw *IMAPWorker) handleOpenDirectory(msg *types.OpenDirectory) {
+	imapw.worker.Logger.Printf("Opening %s", msg.Directory)
+	go func() {
+		_, err := imapw.client.Select(msg.Directory, false)
+		if err != nil {
+			imapw.worker.PostMessage(&types.Error{
+				Message: types.RespondTo(msg),
+				Error:   err,
+			}, nil)
+		} else {
+			imapw.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil)
+		}
+	}()
+}
diff --git a/worker/imap/worker.go b/worker/imap/worker.go
index d75dbb0..4381e22 100644
--- a/worker/imap/worker.go
+++ b/worker/imap/worker.go
@@ -149,12 +149,30 @@ func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error {
 		w.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil)
 	case *types.ListDirectories:
 		w.handleListDirectories(msg)
+	case *types.OpenDirectory:
+		w.handleOpenDirectory(msg)
 	default:
 		return errUnsupported
 	}
 	return nil
 }
 
+func (w *IMAPWorker) handleImapUpdate(update client.Update) {
+	w.worker.Logger.Printf("(= %T", update)
+	switch update := update.(type) {
+	case *client.MailboxUpdate:
+		status := update.Mailbox
+		w.worker.PostMessage(&types.DirectoryInfo{
+			ReadOnly: status.ReadOnly,
+			Flags:    status.Flags,
+
+			Exists: int(status.Messages),
+			Recent: int(status.Recent),
+			Unseen: int(status.Unseen),
+		}, nil)
+	}
+}
+
 func (w *IMAPWorker) Run() {
 	for {
 		select {
@@ -171,7 +189,7 @@ func (w *IMAPWorker) Run() {
 				}, nil)
 			}
 		case update := <-w.updates:
-			w.worker.Logger.Printf("(= %T", update)
+			w.handleImapUpdate(update)
 		}
 	}
 }
diff --git a/worker/types/messages.go b/worker/types/messages.go
index 69df6ca..27937ee 100644
--- a/worker/types/messages.go
+++ b/worker/types/messages.go
@@ -63,6 +63,11 @@ type ListDirectories struct {
 	Message
 }
 
+type OpenDirectory struct {
+	Message
+	Directory string
+}
+
 // Messages
 
 type CertificateApprovalRequest struct {
@@ -75,3 +80,11 @@ type Directory struct {
 	Attributes []string
 	Name       string
 }
+
+type DirectoryInfo struct {
+	Message
+	ReadOnly bool
+	Flags    []string
+
+	Exists, Recent, Unseen int
+}
x/019syscalls.cc.html?h=main&id=013d95266d563a3f531c13eba6d2a6bfe18f8808'>^
104e521c ^
c504ca56 ^
7328af20 ^


9c1056f5 ^
c504ca56 ^
9c1056f5 ^
c504ca56 ^
8aeb85f0 ^
7328af20 ^

4c37b3e9 ^
7328af20 ^



4c37b3e9 ^
c504ca56 ^
7328af20 ^
c504ca56 ^
7328af20 ^

c504ca56 ^



d1c9392a ^

c504ca56 ^




d1c9392a ^

c504ca56 ^






d1c9392a ^


c504ca56 ^



d1c9392a ^

c504ca56 ^





d1c9392a ^

c504ca56 ^




d1c9392a ^

c504ca56 ^





d1c9392a ^
c8a3ccbe ^



c504ca56 ^

c8a3ccbe ^

c504ca56 ^
c8a3ccbe ^




c504ca56 ^

c8a3ccbe ^
c504ca56 ^
c8a3ccbe ^


651fc300 ^
d1c9392a ^

c8a3ccbe ^

c504ca56 ^


c8a3ccbe ^





8aeb85f0 ^
c8a3ccbe ^




8aeb85f0 ^

c504ca56 ^
c8a3ccbe ^
c504ca56 ^
c8a3ccbe ^


5fe060d5 ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187