Debian Codegraph @

lib/autoconfig/get.go

raw
1 package autoconfig
2
3 import (
4 "context"
5 "net/mail"
6 "strings"
7
8 "git.sr.ht/~rjarry/aerc/lib/log"
9 )
10
11 // GetConfig attempts to retrieve the settings for the given mail address.
12 func GetConfig(ctx context.Context, email string) *Config {
13 log.Debugf("looking up configuration for %q", email)
14 mail, err := mail.ParseAddress(email)
15 if err != nil {
16 return nil
17 }
18
19 parts := strings.SplitN(mail.Address, "@", 2)
20 localpart := parts[0]
21 domain := parts[1]
22
23 resultList := make(chan chan *Config, 5)
24
25 ProviderSRV := make(chan *Config, 1)
26 go getFromProviderDNS(ctx, localpart, domain, ProviderSRV)
27 resultList <- ProviderSRV
28
29 ProviderHTTP := make(chan *Config, 1)
30 go getFromAutoconfig(ctx, localpart, domain, ProviderHTTP)
31 resultList <- ProviderHTTP
32
33 ProviderMozilla := make(chan *Config, 1)
34 go getFromMozilla(ctx, localpart, domain, ProviderMozilla)
35 resultList <- ProviderMozilla
36
37 ProviderGuess := make(chan *Config, 1)
38 go guessMailserver(ctx, localpart, domain, ProviderGuess)
39 resultList <- ProviderGuess
40
41 ProviderMX := make(chan *Config, 1)
42 go guessMX(ctx, localpart, domain, ProviderMX)
43 resultList <- ProviderMX
44
45 close(resultList)
46
47 for reschan := range resultList {
48 conf := <-reschan
49 if conf != nil {
50 return conf
51 }
52 }
53
54 return nil
55 }