# Alias support

Courier's support for the address alias file is similar to sendmail's, but with some notable differences. Aliasing addresses to programs is not allowed, the alias list is strictly a list of E-mail addresses. Mail addressed to a name of the alias is delivered to the list of E-mail addresses defined for that alias. The name of an alias has no corresponding mailbox, with one exception. The alias may include an E-mail address that is the same as the alias name, in which case the mail gets delivered to this mailbox in addition to being sent to all the other addresses defined for that alias. Otherwise, if a mailbox with the same name as an alias exists, it will not receive any mail, as any mail addressed to it will be forwarded to the alias members instead.

The alias file is called `aliases.dat`. Courier looks for `aliases.dat` first in the `${COURIER_HOME}/$ARCH/lib/modules/MODULE` directory. If not found, Courier looks for `aliases.dat` in `${COURIER_HOME}/lib`. This lets you define aliases that can be mailed to only locally, or define system wide aliases.

Please note that if `lib/modules/MODULE/aliases.dat` exists, and the E-mail address is not found there, Courier wll try again using `lib/aliases.dat`.

## `makealiases`

The `aliases.dat` file is created using the `makealiases` program. The syntax `makealiases` is as follows:

       makealiases -src=srcfile -tmp=tmpfile -auxtmp=auxtmpfile \
          [ -alias=aliasfile ] [-dump] [module]

The `src`, `tmp`, and `auxtmp` parameters must be specified. Either the `alias` parameter or the `dump` flag must be specified.

srcfile is a text file with alias definitions. `makealiases` uses two temporary files to create the `aliases.dat` file. You must specify the names of those files using the `tmp` and `auxtmp` parameters. aliasfile is the complete pathname to the final `aliases.dat` file, which should be either in the `lib` directory, or in the `MODULE` directory. tmpfile and auxtmpfile must be on the same filesystem as aliasfile.

You may not have more than one instance of `makealiases` running at the same time, using the same temporary files. `makealiases` automatically removes the temporary files when done.

It is safe to run `makealiases` while Courier is running. The new `aliases.dat` file takes effect immediately.

All E-mail addresses in srcfile are rewritten to the canonical format. The optional `module` parameter specifies the module whose rewriting functions are used. If not specified, it defaults to `local`, so that you can specify addresses in srcfile without your local domain name.

The `-dump` flag prevents the alias file from being created. Instead, `makealiases` just rewrites all the addresses, removes the duplicates, and displays the final alias list on standard output.

srcfile can be set to "-". `makealiases` will read alias specifications from standard input.

## The alias specifications file.

Blank lines in the file are ignored. Comments may be present on lines that start with the # character, which are also ignored.

An alias specification takes the form of:

`alias: address1, address2, address3 ...`

This specifies an alias whose name is alias. Mail that's sent to alias will be delivered to the specified list of addresses instead.

Instead of specifying an address, another alias can be used in its place, inserting the contents of the second alias list into the first alias list.

An alias specification may use mutiple lines. Start the second line with a tab character, or a space. For example:

    everyone: john, steve, mary, alice, tom,
              harry, gene

For example, here's a three person organization. Gloria is in Sales, Steve is a system administrator, John does both sales and system administrators:

    sales: john, gloria

    sysadmin: steve, john

    everyone: sales, sysadmin

This alias file specifies that mail addressed to '`sales`', will be delivered to the john and gloria accounts. Mail sent to '`sysadmin`' will be delivered to to the `steve` and `john` accounts. Mail sent to '`everyone`' will be delievered to `steve`, `john`, and `gloria`. Although `john` is listed twice in the `everyone` alias - once in the `sales` alias, and the second time in the `sysadmin` alias - `john` will receive only one copy of the message. The `makealiases` command (and the `submit` command also), automatically eliminates duplicates. Running makealiases with the -dump flag results in the following output.

    everyone@example.com: john@example.com, gloria@example.com, steve@example.com

    sysadmin@example.com: steve@example.com, john@example.com

    sales@example.com: john@example.com, gloria@example.com

In this example, the local domain is '`@example.com`'. The makealiases commands automatically converts all addresses to the canonical format.

The company grows in size, and it is now necessary for someone to be available 24 hours a day. Steve volunteers, and the following change is made:

    sales: john, gloria

    sysadmin: steve, john

    everyone: sales, sysadmin

    steve: steve, steve@domain.com

All mail sent to `steve` will now have a second copy mailed to `steve@domain.com`, IN ADDITION to being delivered to the local mailbox. `steve@domain.com` is Steve's Internet account at home. This changes affects all mail sent to `steve`, not just to mail sent to one of the defined aliases. Running `makealiases` with `-dump` now results in the following output:

    everyone@example.com: john@example.com, gloria@example.com, steve@example.com,
            steve@domain.com

    steve@example.com: steve@example.com, steve@domain.com

    sysadmin@example.com: steve@example.com, john@example.com, steve@domain.com

    sales@example.com: john@example.com, gloria@example.com

This kind of forwarding should really be implemented in the `.courier` delivery specification file in Steve's account. Although allowed, aliases should never have the same name as a local account. Typically, you should define aliases for `postmaster`, and `mailer-daemon`.

## The `-dump` flag

The previous examples of `-dump` flag's output give an indication of what `makealiases` does:

- All addresses are converted to the canonical format, using the selected module's rewrite function (called with address specified as `RW_RECIPIENT`).
- When another alias is specified, the alias's list of addresses is added. The output of `makealiases` consists of all alias references resolved, so the contents of all the defined aliases is just the end list of addresses.
- The output of the `-dump` flag can be reread by makealiases (it's pretty safe to assume that if addresses are already in canonical format, the rewrite function does nothing). Note that some information is lost - namely if a list of addresses in an alias actually came from another alias.
- The order in which aliases are listed by the `-dump` flag is completely random.
- If an alias contains many addresses, `-dump` may list the alias in parts.

## The `aliases.dat` file

The `aliases.dat` file is a GDBM (or a DB) database. Unless the list of addresses in a single alias is large, the layout is pretty basic. The GDBM/DB database is keyed by the alias name, and the contents of the record are the addresses defined by the alias. Each address is followed by a newline character.

In order to prevent the GDBM/DB library from consuming excessive amounts of memory, if an alias defines a large list of addresses, the list is saved in multiple records. The key of the second record is the alias name, followed by a newline, followed by "1". If a third record is necessary, it's name is the alias name, followed by a newline, followed by a "2". And so on.

## Differences from sendmail's `/etc/aliases` file

Although Courier's implementation of `aliases.dat` may seem very similar to sendmail's `/etc/aliases` file, there are some important differences:

- Pathnames and commands are not allowed. Only E-mail addresses can go into an `aliases.dat` file. To deliver mail to a command, or append it to a file, set aside a system mailbox, or a Qmail-style alias account, then create an appropriate `.courier` file.
- owner-alias is not supported.
- NIS maps are not supported.
- The "`foo: \foo, bar`" syntax is made redundant. Just use "`foo: foo, bar`".
- Finally, address rewriting implementation is obviously different. If you modify address rewriting code, you may need to rerun `makealiases` in order for the address rewriting changes to become effective.