summary refs log tree commit diff stats
path: root/worker/worker.go
diff options
context:
space:
mode:
Diffstat (limited to 'worker/worker.go')
-rw-r--r--worker/worker.go20
1 files changed, 17 insertions, 3 deletions
diff --git a/worker/worker.go b/worker/worker.go
index 1f9f04c..a504790 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)
 }