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 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.
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.
- type RType
- type Recipient
- type Resolver
- func (v *Resolver) AddAliasForTesting(addr, rcpt string, rType RType)
- func (v *Resolver) AddAliasesFile(domain, path string) error
- func (v *Resolver) AddDomain(domain string)
- func (v *Resolver) Exists(addr string) (string, bool)
- func (v *Resolver) Reload() error
- func (v *Resolver) Resolve(addr string) (Recipient, error)
This section is empty.
This section is empty.
type RType string
RType represents a recipient type, see the contants below for valid values.
Recipient represents a single recipient, after resolving aliases. They don't have any special interface, the callers will do a type switch anyway.
Resolver represents the aliases resolver.
func (*Resolver) AddAliasForTesting ¶
AddAliasForTesting adds an alias to the resolver, for testing purposes. Not for use in production code.
func (*Resolver) AddAliasesFile ¶
AddAliasesFile to the resolver. The file will be parsed, and an error returned if it does not exist or parse correctly.
AddDomain to the resolver, registering its existence.
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.
Reload aliases files for all known domains.