aerc

Working clone of aerc-mail.org
git clone git://git.danielmoch.com/aerc.git
Log | Files | Refs | README | LICENSE

worker.go (729B)


      1 package worker
      2 
      3 import (
      4 	"git.sr.ht/~sircmpwn/aerc/worker/imap"
      5 	"git.sr.ht/~sircmpwn/aerc/worker/types"
      6 
      7 	"fmt"
      8 	"log"
      9 	"net/url"
     10 	"strings"
     11 )
     12 
     13 // Guesses the appropriate worker type based on the given source string
     14 func NewWorker(source string, logger *log.Logger) (*types.Worker, error) {
     15 	u, err := url.Parse(source)
     16 	if err != nil {
     17 		return nil, err
     18 	}
     19 	worker := types.NewWorker(logger)
     20 	scheme := u.Scheme
     21 	if strings.ContainsRune(scheme, '+') {
     22 		scheme = scheme[:strings.IndexRune(scheme, '+')]
     23 		fmt.Println(scheme)
     24 	}
     25 	switch scheme {
     26 	case "imap":
     27 		fallthrough
     28 	case "imaps":
     29 		worker.Backend = imap.NewIMAPWorker(worker)
     30 	default:
     31 		return nil, fmt.Errorf("Unknown backend %s", u.Scheme)
     32 	}
     33 	return worker, nil
     34 }