discover

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package discover finds an address's mail servers (docs/design/accounts.md, Discovery): provider profiles, Mozilla autoconfig documents (also served by the ISPDB) and RFC 6186 SRV records. The readers here are pure; the engine fetches documents and queries DNS.

Index

Constants

This section is empty.

Variables

View Source
var ErrNothing = errors.New("discover: no usable server")

ErrNothing means a source offered no usable server.

Functions

func DAVStarts

func DAVStarts(ctx context.Context, r Resolver, email string, service api.ServiceKind) ([]string, error)

DAVStarts are where contacts or calendar discovery may start for an address on a domain without a provider profile (RFC 6764): the server the domain's _carddavs._tcp or _caldavs._tcp SRV record names, then the domain itself, whose /.well-known/ path davx.Discover asks first.

Types

type Deps

type Deps struct {
	// Get fetches an HTTPS URL (fetch: 64 KB, 10 s, redirects only within
	// the host).
	Get func(ctx context.Context, rawURL string) ([]byte, error)
	// Resolver answers SRV queries (net.DefaultResolver).
	Resolver Resolver
	// ISPDB is the base URL of Thunderbird's ISP database.
	ISPDB string
}

Deps are discovery's ways out; zero fields use the real ones.

type Resolver

type Resolver interface {
	LookupSRV(ctx context.Context, service, proto, name string) (string, []*net.SRV, error)
}

Resolver looks up SRV records; *net.Resolver satisfies it.

type Result

type Result struct {
	Kind   api.AccountKind
	Source api.DiscoverySource
	Auth   []api.AuthKind
	Settings
}

Result is what discovery found for an address.

func Discover

func Discover(ctx context.Context, email string, d Deps) (Result, error)

Discover finds an address's servers (docs/design/accounts.md, Discovery): a provider profile; the domain's autoconfig documents; the ISPDB; SRV records. The first source with both servers wins; otherwise the first with either; otherwise the result's Source is none.

type Server

type Server struct {
	Host     string
	Port     int
	TLS      api.TLSMode // tls or starttls; never insecure
	Username string
}

Server is one server's settings.

type Settings

type Settings struct {
	IMAP *Server
	SMTP *Server
}

Settings are the servers a source found; either may be nil.

func FromSRV

func FromSRV(ctx context.Context, r Resolver, email string) (Settings, error)

FromSRV reads an address's RFC 6186 SRV records, preferring the implicit-TLS services (imaps, submissions, RFC 8314) over their STARTTLS counterparts (imap, submission). It returns ErrNothing when neither protocol is offered, and a plain error when the address has no usable domain.

func ParseAutoconfig

func ParseAutoconfig(doc []byte, email string) (Settings, error)

ParseAutoconfig reads a Mozilla autoconfig document (config-v1.1.xml) for email and returns the first usable IMAP and SMTP servers it offers, in document order across providers. A server is usable when its socketType is SSL or STARTTLS, it offers at least one password-* authentication, and its expanded host name and port are valid. Placeholders in hostname and username are expanded from email. It returns ErrNothing when neither server is found, and a plain error when email is not an address or the document does not decode.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL