aliases

package
Version: v0.0.0-...-4bd2b9e Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package aliases implements an email aliases resolver.

The resolver can parse many files for different domains, and perform lookups to resolve the aliases.

File format

It generally follows the traditional aliases format used by sendmail and exim.

The file can contain lines of the form:

user: address, address
user: | command

Lines starting with "#" are ignored, as well as empty lines. User names cannot contain spaces, ":" or commas, for parsing reasons. This is a tradeoff between flexibility and keeping the file format easy to edit for people.

User names will be normalized internally to lower-case.

Usually there will be one database per domain, and there's no need to include the "@" in the user (in this case, "@" will be forbidden).

Recipients

Recipients can be of different types:

- Email: the usual user@domain we all know and love, this is the default.
- Pipe: if the right side starts with "| ", the rest of the line specifies
    a command to pipe the email through.
    Command and arguments are space separated. No quoting, escaping, or
    replacements of any kind.

Lookups

The resolver will perform lookups recursively, until it finds all the final recipients.

There are recursion limits to avoid alias loops. If the limit is reached, the entire resolution will fail.

Suffix removal

The resolver can also remove suffixes from emails, and drop characters completely. This can be used to turn "user+blah@domain" into "user@domain", and "us.er@domain" into "user@domain".

Both are optional, and the characters configurable globally.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRecursionLimitExceeded is returned when the resolving lookup
	// exceeded the recursion limit. Usually caused by aliases loops.
	ErrRecursionLimitExceeded = fmt.Errorf("recursion limit exceeded")
)

Functions

This section is empty.

Types

type RType

type RType string

RType represents a recipient type, see the contants below for valid values.

const (
	EMAIL RType = "(email)"
	PIPE  RType = "(pipe)"
)

Valid recipient types.

type Recipient

type Recipient struct {
	Addr string
	Type RType
}

Recipient represents a single recipient, after resolving aliases. They don't have any special interface, the callers will do a type switch anyway.

type Resolver

type Resolver struct {
	// Suffix separator, to perform suffix removal.
	SuffixSep string

	// Characters to drop from the user part.
	DropChars string

	// Path to resolve and exist hooks.
	ExistsHook  string
	ResolveHook string
	// contains filtered or unexported fields
}

Resolver represents the aliases resolver.

func NewResolver

func NewResolver() *Resolver

NewResolver returns a new, empty Resolver.

func (*Resolver) AddAliasForTesting

func (v *Resolver) AddAliasForTesting(addr, rcpt string, rType RType)

AddAliasForTesting adds an alias to the resolver, for testing purposes. Not for use in production code.

func (*Resolver) AddAliasesFile

func (v *Resolver) AddAliasesFile(domain, path string) error

AddAliasesFile to the resolver. The file will be parsed, and an error returned if it does not exist or parse correctly.

func (*Resolver) AddDomain

func (v *Resolver) AddDomain(domain string)

AddDomain to the resolver, registering its existence.

func (*Resolver) Exists

func (v *Resolver) Exists(addr string) (string, bool)

Exists check that the address exists in the database. It returns the cleaned address, and a boolean indicating the result. The clean address can be used to look it up in other databases, even if it doesn't exist.

func (*Resolver) Reload

func (v *Resolver) Reload() error

Reload aliases files for all known domains.

func (*Resolver) Resolve

func (v *Resolver) Resolve(addr string) ([]Recipient, error)

Resolve the given address, returning the list of corresponding recipients (if any).

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL