File: get.go

package info (click to toggle)
aerc 0.21.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,892 kB
  • sloc: ansic: 1,181; python: 1,000; sh: 553; awk: 360; makefile: 23
file content (55 lines) | stat: -rw-r--r-- 1,257 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
package autoconfig

import (
	"context"
	"net/mail"
	"strings"

	"git.sr.ht/~rjarry/aerc/lib/log"
)

// GetConfig attempts to retrieve the settings for the given mail address.
func GetConfig(ctx context.Context, email string) *Config {
	log.Debugf("looking up configuration for %q", email)
	mail, err := mail.ParseAddress(email)
	if err != nil {
		return nil
	}

	parts := strings.SplitN(mail.Address, "@", 2)
	localpart := parts[0]
	domain := parts[1]

	resultList := make(chan chan *Config, 5)

	ProviderSRV := make(chan *Config, 1)
	go getFromProviderDNS(ctx, localpart, domain, ProviderSRV)
	resultList <- ProviderSRV

	ProviderHTTP := make(chan *Config, 1)
	go getFromAutoconfig(ctx, localpart, domain, ProviderHTTP)
	resultList <- ProviderHTTP

	ProviderMozilla := make(chan *Config, 1)
	go getFromMozilla(ctx, localpart, domain, ProviderMozilla)
	resultList <- ProviderMozilla

	ProviderGuess := make(chan *Config, 1)
	go guessMailserver(ctx, localpart, domain, ProviderGuess)
	resultList <- ProviderGuess

	ProviderMX := make(chan *Config, 1)
	go guessMX(ctx, localpart, domain, ProviderMX)
	resultList <- ProviderMX

	close(resultList)

	for reschan := range resultList {
		conf := <-reschan
		if conf != nil {
			return conf
		}
	}

	return nil
}