aboutsummaryrefslogtreecommitdiffstats
path: root/worker
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-01-09 21:24:50 -0500
committerDrew DeVault <sir@cmpwn.com>2018-01-09 21:31:36 -0500
commitb5d5e0dbedee34bd5d3edf13616f055d4f227d36 (patch)
treed4353b88a830a29c570b0a54adcda2126427fc95 /worker
parent6394e386c2a88c3b376cd422a7b7ce5ae7534984 (diff)
downloadaerc-b5d5e0dbedee34bd5d3edf13616f055d4f227d36.tar.gz
Parse account configuration
Diffstat (limited to 'worker')
-rw-r--r--worker/imap/worker.go6
-rw-r--r--worker/worker.go20
2 files changed, 20 insertions, 6 deletions
diff --git a/worker/imap/worker.go b/worker/imap/worker.go
index a095e60d..97cd4b0c 100644
--- a/worker/imap/worker.go
+++ b/worker/imap/worker.go
@@ -34,11 +34,11 @@ func (w *IMAPWorker) PostAction(msg types.WorkerMessage) {
func (w *IMAPWorker) handleMessage(_msg types.WorkerMessage) {
switch msg := _msg.(type) {
case types.Ping:
- w.messages <- &types.Ack{
+ w.messages <- types.Ack{
Message: types.RespondTo(msg),
}
default:
- w.messages <- &types.Unsupported{
+ w.messages <- types.Unsupported{
Message: types.RespondTo(_msg),
}
}
@@ -49,7 +49,7 @@ func (w *IMAPWorker) Run() {
for {
select {
case msg := <-w.actions:
- fmt.Printf("<= %T: %+v\n", msg, msg)
+ fmt.Printf("<= %T\n", msg)
w.handleMessage(msg)
default:
// no-op
diff --git a/worker/worker.go b/worker/worker.go
index 1f9f04cf..a5047904 100644
--- a/worker/worker.go
+++ b/worker/worker.go
@@ -3,6 +3,9 @@ package worker
import (
"git.sr.ht/~sircmpwn/aerc2/worker/imap"
"git.sr.ht/~sircmpwn/aerc2/worker/types"
+
+ "fmt"
+ "net/url"
)
type Worker interface {
@@ -12,7 +15,18 @@ type Worker interface {
}
// Guesses the appropriate worker type based on the given source string
-func NewWorker(source string) Worker {
- // TODO: Do this properly
- return imap.NewIMAPWorker()
+func NewWorker(source string) (Worker, error) {
+ var (
+ u *url.URL
+ err error
+ )
+ if u, err = url.Parse(source); err != nil {
+ return nil, err
+ }
+ switch u.Scheme {
+ case "imap":
+ case "imaps":
+ return imap.NewIMAPWorker(), nil
+ }
+ return nil, fmt.Errorf("Unknown backend %s", u.Scheme)
}