about summary refs log tree commit diff stats
path: root/worker/imap
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-02-01 19:54:19 -0500
committerDrew DeVault <sir@cmpwn.com>2018-02-01 19:54:19 -0500
commitd603bbe2ce4adebfc9ec0bb708d814fd9152676c (patch)
tree0b6e06a272a68b98608c85b9b6cb21ef04181547 /worker/imap
parentcc03f6f4c802ee0742520145e9cacbd88f78ed9a (diff)
downloadaerc-d603bbe2ce4adebfc9ec0bb708d814fd9152676c.tar.gz
Refactoring; consume listing response
Diffstat (limited to 'worker/imap')
-rw-r--r--worker/imap/list.go12
-rw-r--r--worker/imap/worker.go39
2 files changed, 26 insertions, 25 deletions
diff --git a/worker/imap/list.go b/worker/imap/list.go
index f6d3677..2f5e5b4 100644
--- a/worker/imap/list.go
+++ b/worker/imap/list.go
@@ -6,7 +6,7 @@ import (
 	"git.sr.ht/~sircmpwn/aerc2/worker/types"
 )
 
-func (imapw *IMAPWorker) handleListDirectories(msg types.ListDirectories) {
+func (imapw *IMAPWorker) handleListDirectories(msg *types.ListDirectories) {
 	mailboxes := make(chan *imap.MailboxInfo)
 	done := make(chan error, 1)
 	imapw.worker.Logger.Println("Listing mailboxes")
@@ -18,18 +18,22 @@ func (imapw *IMAPWorker) handleListDirectories(msg types.ListDirectories) {
 			select {
 			case err := <-done:
 				if err != nil {
-					imapw.worker.PostMessage(types.Error{
+					imapw.worker.PostMessage(&types.Error{
 						Message: types.RespondTo(msg),
 						Error:   err,
 					}, nil)
 				} else {
 					imapw.worker.PostMessage(
-						types.Done{types.RespondTo(msg)}, nil)
+						&types.Done{types.RespondTo(msg)}, nil)
 				}
 				return
 			case mbox := <-mailboxes:
 				if mbox != nil {
-					imapw.worker.Logger.Printf("%v\n", mbox.Name)
+					imapw.worker.PostMessage(&types.Directory{
+						Message:    types.RespondTo(msg),
+						Name:       mbox.Name,
+						Attributes: mbox.Attributes,
+					}, nil)
 				}
 			}
 		}
diff --git a/worker/imap/worker.go b/worker/imap/worker.go
index d6337bc..d75dbb0 100644
--- a/worker/imap/worker.go
+++ b/worker/imap/worker.go
@@ -54,7 +54,7 @@ func (w *IMAPWorker) verifyPeerCert(msg types.WorkerMessage) func(
 			pool.AddCert(cert)
 		}
 
-		request := types.ApproveCertificate{
+		request := &types.CertificateApprovalRequest{
 			Message:  types.RespondTo(msg),
 			CertPool: pool,
 		}
@@ -62,25 +62,25 @@ func (w *IMAPWorker) verifyPeerCert(msg types.WorkerMessage) func(
 
 		response := <-w.worker.Actions
 		if response.InResponseTo() != request {
-			return fmt.Errorf("Expected UI to answer cert request")
+			return fmt.Errorf("Expected UI to respond to cert request")
 		}
-		switch response.(type) {
-		case types.Ack:
-			return nil
-		case types.Disconnect:
-			return fmt.Errorf("UI rejected certificate")
-		default:
-			return fmt.Errorf("Expected UI to answer cert request")
+		if approval, ok := response.(*types.ApproveCertificate); !ok {
+			return fmt.Errorf("Expected UI to send certificate approval")
+		} else {
+			if approval.Approved {
+				return nil
+			} else {
+				return fmt.Errorf("UI rejected certificate")
+			}
 		}
 	}
 }
 
 func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error {
 	switch msg := msg.(type) {
-	case types.Ping:
-	case types.Unsupported:
+	case *types.Unsupported:
 		// No-op
-	case types.Configure:
+	case *types.Configure:
 		u, err := url.Parse(msg.Config.Source)
 		if err != nil {
 			return err
@@ -99,14 +99,14 @@ func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error {
 
 		w.config.scheme = u.Scheme
 		w.config.user = u.User
-	case types.Connect:
+	case *types.Connect:
 		var (
 			c   *client.Client
 			err error
 		)
 		tlsConfig := &tls.Config{
 			InsecureSkipVerify:    true,
-			VerifyPeerCertificate: w.verifyPeerCert(&msg),
+			VerifyPeerCertificate: w.verifyPeerCert(msg),
 		}
 		switch w.config.scheme {
 		case "imap":
@@ -146,7 +146,8 @@ func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error {
 
 		c.Updates = w.updates
 		w.client = &imapClient{c, idle.NewClient(c)}
-	case types.ListDirectories:
+		w.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil)
+	case *types.ListDirectories:
 		w.handleListDirectories(msg)
 	default:
 		return errUnsupported
@@ -160,18 +161,14 @@ func (w *IMAPWorker) Run() {
 		case msg := <-w.worker.Actions:
 			msg = w.worker.ProcessAction(msg)
 			if err := w.handleMessage(msg); err == errUnsupported {
-				w.worker.PostMessage(types.Unsupported{
+				w.worker.PostMessage(&types.Unsupported{
 					Message: types.RespondTo(msg),
 				}, nil)
 			} else if err != nil {
-				w.worker.PostMessage(types.Error{
+				w.worker.PostMessage(&types.Error{
 					Message: types.RespondTo(msg),
 					Error:   err,
 				}, nil)
-			} else {
-				w.worker.PostMessage(types.Ack{
-					Message: types.RespondTo(msg),
-				}, nil)
 			}
 		case update := <-w.updates:
 			w.worker.Logger.Printf("(= %T", update)
f='#n22'>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