Exim Specification - 23. The aliasfile director

Go to the first, previous, next, last section, table of contents.

# 23. The aliasfile director

The aliasfile director expands local parts by consulting a file or database of aliases. An incoming local part is looked up, and the result is a list of one or more replacement addresses, file names, pipe commands or certain special items. The expansion may safely contain the same local part as the input as one of its items, because a director is automatically skipped if it has an identical ancestor that was processed by that director. For the case of a new alias address that is identical to the input address, this rule means in effect that it starts its processing at the following director.

The alias list can be obtained from a text file that is searched linearly, a DBM direct-access file, a NIS or NIS+ map, an LDAP database, or any other kind of lookup supported by Exim (see chapter 6).

Unless the locally_caseless option has been set false, local parts are forced to lower case, and so the keys in alias files should normally be in lower case. For linearly searched files this isn't in fact necessary, because the searching is done in a case-independent manner, but it is relevant for other forms of alias lookup. The exim_dbmbuild utility can be used to convert a text file into a DBM database; the keys are lower-cased by default.

## 23.1 Specifying a transport for aliasfile

The generic transport option must not be specified for aliasfile when it is fulfilling a traditional aliasing function. If transport is specified, the director behaves differently, and doesn't really `alias' at all. Its lookup facilities are used as a means of validating the incoming address, but if it is successful, the message is directed to the given transport while retaining the original address. The data that is returned from the lookup is not used. For example, a file containing a list of cancelled users can be used to direct messages addressed to them to a particular script.

Another common use of aliasfile with a transport is for handling local deliveries without reference to /etc/passwd. Local parts are validated by using aliasfile to look them up in a file or database, which can also be used to hold information for use during delivery (for example, the uid to use, or the location of the mailbox). There is a sample configuration that gives more detail.

## 23.2 Alias file format

A textual alias file to be searched linearly consists of entries that start with the alias name, terminated by a colon or white space. However, a colon must be used if data for the alias starts with a colon, because white space is permitted between the alias name and its terminating colon. This is Exim's standard lsearch format (see chapter 6).

The remainder of the entry, up to the end of the line, consists of a list of addresses, file names, pipe commands, or certain special items (see below). The items in the list are separated by commas. The list can be continued over several lines by starting each of the continuation lines with white space. A single space is retained at each junction. However, a comma is still required following an item that ends at the end of a line, because the lsearch lookup code removes newlines from the string it returns.

Lines in textual alias files that start with a # character are comments, and are ignored, and a # may also appear following a comma in an item list, in which case everything after the # is ignored. Other forms of alias file (DBM, NIS, LDAP, etc.) involve lookups using the local part as a key on files and databases. The value returned is a list of items separated by commas or newlines. The returned list is normally used exactly as it stands, but if the expand option is set, it is first passed through the string expansion mechanism.

By default, alias names are simple local parts such as `postmaster', but if the include_domain option is set, they must contain both a local part and a domain, thus allowing aliases for more than one domain to be held in a single file.

It is possible to set up a default in an alias file that uses a single-key lookup type. This matches incoming local parts that do not match any other entry when the lookup type name is followed by an asterisk, for example dbm* (see section 6.6). For query-style lookups, the queries option specifies a list of queries to be tried.

## 23.3 Types of alias item

If an item is entirely enclosed in double quotes, these are removed. Otherwise double quotes are retained because some forms of mail address require their use (but never to enclose the entire address). In the following description, `item' refers to what remains after any surrounding double quotes have been removed. An item may safely be the same as the local part currently under consideration, because any director is automatically skipped if any ancestor has the same local part and was processed by that director.

- If an item begins with `\' and the rest of the item parses as a valid RFC 822 address that does not include a domain, the item is qualified using the domain of the incoming address. The use of `\' makes a difference only if there is more than one local domain. In the absence of a leading `\', unqualified addresses are qualified using the value in qualify_recipient, unless qualify_preserve_domain is set. It is not necessary to include `\' in aliases to prevent directing loops, because Exim has its own method of loop detection.
- An item is treated as a pipe command if it begins with `|' and does not parse as a valid RFC 822 address that includes a domain. A transport for running the command must be specified by the pipe_transport option. Either the director or the transport must specify a user and group under which to run the delivery. Either single or double quotes can be used for enclosing the individual arguments of the pipe command; no interpretation of escapes is done for single quotes. If the command contains a comma character, it is necessary to put the whole item in double quotes, for example:

      "|/some/command ready,steady,go"

  since items are terminated by commas. Do not, however, quote just the command. An item such as

      |"/some/command ready,steady,go"

  is interpreted as a pipe with a rather strange command name, and no arguments.
- An item is interpreted as a path name if it begins with `/' and does not parse as a valid RFC 822 address that includes a domain. For example,

      /home/world/minbari

  is treated as a file name, but

      /s=molari/o=babylon/@x400gate.way

  is treated as an address. For a file name, a transport must be specified using the file_transport option. However, if the generated path name ends with a forward slash character, it is interpreted as a directory name rather than a file name, and directory_transport is used instead. If it ends with two slashes, directory2_transport is required. This makes it possible to support two different kinds of directory delivery simultaneously. If a generated path is /dev/null, delivery to it is bypassed at a high level, and the log entry shows `**bypassed**' instead of a transport name. This avoids the need to specify a user and group, which are necessary for a genuine delivery to a file. When the file name is not /dev/null, either the director or the transport must specify a user and group under which to run the delivery.
- An item of the form

      :include:<path name>

  may appear in an alias file, in which case a list of further items is taken from the given file and included at that point. The items in the list are separated by commas or newlines and are not subject to expansion, even when the expand option is set. If this is the first item in an alias list, a colon must be used to terminate the alias name. This example is incorrect:

      list1    :include:/opt/lists/list1

  It must be given as

      list1:   :include:/opt/lists/list1

- Sometimes you want to throw away mail to a particular local part. An alias entry with no addresses causes Exim to generate an error, so that cannot be used. However, another special item that may appear in an alias file is

      :blackhole:

  which does what its name implies. No delivery is done for it, and no error message is generated. If this is the first item in an alias list, a colon must be used to terminate the alias name. This used to be more efficient than directing a message to /dev/null because it happens at directing time, and also there was no need to specify a user and group to run the transport process for delivery to a file. However, from Exim version 1.90 onwards /dev/null is recognized specially, and handled in essentially the same way as :blackhole:.
- An attempt to deliver to a particular local part can be deferred or forced to fail by aliasing the local part to

      :defer:
      or
      :fail:

  respectively. As this is normally the only item in an alias list, a colon must be used to terminate the alias name. When an alias list contains such an item, it applies to the entire alias; any other items in the list are ignored (:blackhole: is different). Any text following :fail: or :defer: is placed in the error text associated with the failure. For example:

      X.Employee:  :fail: Gone away, no forwarding address

  In the case of an address that is being verified for the SMTP RCPT or VRFY commands, the text is included in the SMTP error response, which has a 451 code for a :defer: failure, and 550 for :fail:. In other cases it is included in the error message that Exim generates. Normally the error text is the rest of the alias entry -- a comma does not terminate it -- but a newline does act as a terminator. Newlines are not normally present in alias expansions. In lsearch lookups they are removed as part of the continuation process, but they may exist in other kinds of lookup and in :include:d files. During message delivery, an alias containing :fail: causes an immediate failure of the incoming address, whereas :defer: causes the message to remain on the queue so that a subsequent delivery attempt can happen at a later time. If an address is :defer:red for too long, it will ultimately fail, since normal retry rules apply.
- Sometimes it is useful to use a search type with a default (see chapter 6) for aliases. However, there may be a need for exceptions to the default. These can be handled by aliasing them to

      :unknown:

  This differs from :fail: in that it causes aliasfile to pass the address on to the next director, whereas :fail: forces directing to fail immediately. If :unknown: is the first item in an alias list, a colon must be used to terminate the alias name.

## 23.4 Duplicate addresses

Exim removes duplicate addresses from the list to which it is delivering, so as to deliver just one copy to each address. This does not apply to deliveries directed at pipes by different immediate parent addresses, but an indirect aliasing scheme of the type

    pipe:       |/some/command ${local_part}
    localpart1: pipe
    localpart2: pipe

does not work with a message that is addressed to both local parts, because when the second is aliased to the intermediate local part `pipe' it gets discarded as being the same as a previously handled address. However, a scheme such as

    localpart1: |/some/command ${local_part}
    localpart2: |/some/command ${local_part}

does result in two different pipe deliveries, because the immediate parents of the pipes are distinct.

## 23.5 Repeated alias expansion

When a message cannot be delivered to all of its recipients immediately, leading to two or more delivery attempts, alias expansion is carried out afresh each time for those addresses whose children were not all previously delivered. If an alias is being used as a mailing list, this can lead to new members of the list receiving copies of old messages. The one_time option can be used to avoid this.

## 23.6 Errors in alias files

If skip_syntax_errors is set, a malformed address that causes a parsing error is skipped, and an entry is written to the main log. This may be useful for mailing lists that are automatically managed, but note the inherent danger. Otherwise, if an error is detected while generating the list of new addresses, the message is frozen, except for the special case of inability to open an included file, when no_freeze_missing_include is set. In this case, delivery is simply deferred.

## 23.7 Aliasfile private options

This section lists the private options that aliasfile does not have in common with forwardfile. Those that they share are given in chapter 22.

### expand (aliasfile)

Type: boolean
Default: false

If this option is set true, the text obtained by looking up the local part is passed through the string expansion mechanism before being interpreted as a list of alias items. Addresses that are subsequently added by means of the `include' mechanism are not expanded.

### file (aliasfile)

Type: string, expanded
Default: unset

This option specifies the name of the alias file, and it must be set if search_type specifies a single-key lookup; if it does not, an error occurs. (For query-style lookups, query must be set instead.) See chapter 6 for details of different lookup styles. The string is expanded before use; if expansion fails, Exim panics. The resulting string must be an absolute path for linear search and DBM lookups. If the original string does not start with `/' or `$' in these cases, Exim gives a configuration error when it starts up; otherwise, if an expanded string does not begin with `/' delivery is frozen.

### forbid_special (aliasfile)

Type: boolean
Default: false

If this option is set, the special items :defer:, :fail:, :blackhole: and :unknown: are forbidden. If any are encountered, delivery is deferred.

### include_domain (aliasfile)

Type: boolean
Default: false

Setting this option true causes the key that is looked up to be `local-part@domain' instead of just `local-part'. Thus a single file can be used to hold aliases for many local domains. This option has no effect if the search type specifies a query-style lookup.

If you want include defaults for each domain in an alias file in the form

    *@domain1:  default@domain1
    *@domain2:  default@domain2

then you need to include `*@' in the search type (for example, dbm*@). See section 6.1 for details of this kind of search.

### optional (aliasfile)

Type: boolean
Default: false

For a single-key lookup type, if the file cannot be opened because it does not exist (the ENOENT error) and this option is set, the director simply declines to handle the address. Otherwise any failure to open the file causes an entry to be written to the log and delivery to be deferred.

For a query-style lookup type, optional causes the director to decline if no query can be completed (for example, all databases are down). Without optional, delivery is deferred.

### queries (aliasfile)

Type: string, expanded
Default: unset

This option is an alternative to query; the two options are mutually exclusive. The difference is that queries contains a colon-separated list of queries, which are tried in order until one succeeds or defers, or all fail. Any colon characters actually required in an individual query must be doubled, in order that they not be treated as query separators.

### query (aliasfile)

Type: string, expanded
Default: unset

This option specifies a database query, and either it or queries must be set if search_type specifies a query-style lookup; if neither is set, an error occurs. (For single-key lookups, file must be set instead.) See chapter 6 for details of different lookup styles. The query is expanded before use, and would normally contain a reference to the local part. For example,

    search_type = nisplus
    query = [alias=${local_part}],mail_aliases.org_dir:expansion

could be used for a NIS+ lookup. Sometimes a lookup cannot be completed (for example, a NIS+ database might be inaccessible) and in this case the director causes delivery to be deferred.

### search_type (aliasfile)

Type: string
Default: unset

This option must be set to the name of a supported search type (`lsearch', `dbm', etc.), specifying the type of data lookup. For query-style lookups, the query option specifies the search query, and file must not be set. For the other search types, file is required and query must not be set. See chapter 6 for details of the different lookup styles.

Single-key search types for aliasfile can be preceded by ``partial-'` and/or followed by ``*'`. The former isn't likely to be useful very often, but the latter provides a default facility. Note, however, that if two addresses in the same message provoke the use of the default, only one copy gets delivered, but any added Envelope-to: header contains all the original addresses. Exceptions to the default can be set up by aliasing them to :unknown:.

Go to the first, previous, next, last section, table of contents.