The command line is (by default) broken down into a command name and arguments by the pipe transport itself. The allow_commands and restrict_to_path options can be used to restrict the commands that may be run.
Unquoted arguments are delimited by white space. If an argument appears in double quotes, backslash is interpreted as an escape character in the usual way. If an argument appears in single quotes, no escaping is done.
String expansion is applied to the command line except when it comes from a traditional .forward file (commands from a filter file are expanded). The expansion is applied to each argument in turn rather than to the whole line. For this reason, any string expansion item that contains white space must be quoted so as to be contained within a single argument. A setting such as
command = /some/path ${if eq{$local_part}{postmaster}{xx}{yy}}
will not work, because the expansion item gets split between several arguments. You have to write
command = /some/path "${if eq{$local_part}{postmaster}{xx}{yy}}"
to ensure that it is all in one argument. The expansion is done in this way, argument by argument, so that the number of arguments cannot be changed as a result of expansion, and quotes or backslashes in inserted variables do not interact with external quoting. However, this leads to problems if you want to generate multiple arguments (or the command name plus arguments) from a single expansion. In this situation, the simplest solution is to use a shell. For example:
command = /bin/sh -c ${lookup{$local_part}lsearch{/some/file}}
Special handling takes place when an argument consists of precisely the text $pipe_addresses. This is not a general expansion variable; the only place this string is recognized is when it appears as an argument for a pipe or transport filter command. It causes each address that is being handled to be inserted in the argument list at that point as a separate argument. This avoids any problems with spaces or shell metacharacters, and is of use when a pipe transport is handling groups of addresses in a batch.
After splitting up into arguments and expansion, the resulting command is run in a subprocess directly from the transport, not under a shell. The message that is being delivered is supplied on the standard input, and the standard output and standard error are both connected to a single pipe that is read by Exim. The max_output option controls how much output the command may produce, and the return_output and return_fail_output options control what is done with it.
Not running the command under a shell (by default) lessens the security risks in cases when a command from a user’s filter file is built out of data that was taken from an incoming message. If a shell is required, it can of course be explicitly specified as the command to be run. However, there are circumstances where existing commands (for example, in .forward files) expect to be run under a shell and cannot easily be modified. To allow for these cases, there is an option called use_shell, which changes the way the pipe transport works. Instead of breaking up the command line as just described, it expands it as a single string and passes the result to /bin/sh. The restrict_to_path option and the $pipe_addresses facility cannot be used with use_shell, and the whole mechanism is inherently less secure.
The string is expanded, and is then interpreted as a colon-separated list of permitted commands. If restrict_to_path is not set, the only commands permitted are those in the allow_commands list. They need not be absolute paths; the path option is still used for relative paths. If restrict_to_path is set with allow_commands, the command must either be in the allow_commands list, or a name without any slashes that is found on the path. In other words, if neither allow_commands nor restrict_to_path is set, there is no restriction on the command, but otherwise only commands that are permitted by one or the other are allowed. For example, if
allow_commands = /usr/bin/vacation
and restrict_to_path is not set, the only permitted command is /usr/bin/vacation. The allow_commands option may not be set if use_shell is set.
See the description of local delivery batching in chapter 25.
This limits the number of addresses that can be handled in a single delivery. See the description of local delivery batching in chapter 25.
As pipe writes the message, the start of each line is tested for matching check_string, and if it does, the initial matching characters are replaced by the contents of escape_string, provided both are set. The value of check_string is a literal string, not a regular expression, and the case of any letters it contains is significant. When use_bsmtp is set, the contents of check_string and escape_string are forced to values that implement the SMTP escaping protocol. Any settings made in the configuration file are ignored.
This option need not be set when pipe is being used to deliver to pipes obtained directly from address redirections. In other cases, the option must be set, to provide a command to be run. It need not yield an absolute path (see the path option below). The command is split up into separate arguments by Exim, and each argument is separately expanded, as described in section 29.3 above.
This option is used to add additional variables to the environment in which the command runs (see section 29.4 for the default list). Its value is a string which is expanded, and then interpreted as a colon-separated list of environment settings of the form <name>=<value>.
See check_string above.
Failure to exec the command in a pipe transport is by default treated like any other failure while running the command. However, if freeze_exec_fail is set, failure to exec is treated specially, and causes the message to be frozen, whatever the setting of ignore_status.
If this option is true, the status returned by the subprocess that is set up to run the command is ignored, and Exim behaves as if zero had been returned. Otherwise, a non-zero status or termination by signal causes an error return from the transport unless the status value is one of those listed in temp_errors; these cause the delivery to be deferred and tried again later.
Note: This option does not apply to timeouts, which do not return a status. See the timeout_defer option for how timeouts are handled.
If this option is set, and the status returned by the command is one of the codes listed in temp_errors (that is, delivery was deferred), and any output was produced, the first line of it is written to the main log.
If this option is set, and the command returns any output, and also ends with a return code that is neither zero nor one of the return codes listed in temp_errors (that is, the delivery failed), the first line of output is written to the main log. This option and log_output are mutually exclusive. Only one of them may be set.
If this option is set and the command returns any output, the first line of output is written to the main log, whatever the return code. This option and log_fail_output are mutually exclusive. Only one of them may be set.
This specifies the maximum amount of output that the command may produce on its standard output and standard error file combined. If the limit is exceeded, the process running the command is killed. This is intended as a safety measure to catch runaway processes. The limit is applied independently of the settings of the options that control what is done with such output (for example, return_output). Because of buffering effects, the amount of output may exceed the limit by a small amount before Exim notices.
The string specified here is expanded and output at the start of every message. The default is unset if use_bsmtp is set. Otherwise it is
message_prefix = \
From ${if def:return_path{$return_path}{MAILER-DAEMON}}\
${tod_bsdinbox}\n
This is required by the commonly used /usr/bin/vacation program. However, it must not be present if delivery is to the Cyrus IMAP server, or to the tmail local delivery agent. The prefix can be suppressed by setting
message_prefix =
The string specified here is expanded and output at the end of every message. The default is unset if use_bsmtp is set. Otherwise it is a single newline. The suffix can be suppressed by setting
message_suffix =
This option specifies the string that is set up in the PATH environment variable of the subprocess. If the command option does not yield an absolute path name, the command is sought in the PATH directories, in the usual way. Warning: This does not apply to a command specified as a transport filter.
If the generic user option is not set and this option is true, the delivery process is run under the uid that was in force when Exim was originally called to accept the message. If the group id is not otherwise set (via the generic group option), the gid that was in force when Exim was originally called to accept the message is used.
When this option is set, any command name not listed in allow_commands must contain no slashes. The command is searched for only in the directories listed in the path option. This option is intended for use in the case when a pipe command has been generated from a user’s .forward file. This is usually handled by a pipe transport called address_pipe.
If this option is true, and the command produced any output and ended with a return code other than zero or one of the codes listed in temp_errors (that is, the delivery failed), the output is returned in the bounce message. However, if the message has a null sender (that is, it is itself a bounce message), output from the command is discarded. This option and return_output are mutually exclusive. Only one of them may be set.
If this option is true, and the command produced any output, the delivery is deemed to have failed whatever the return code from the command, and the output is returned in the bounce message. Otherwise, the output is just discarded. However, if the message has a null sender (that is, it is a bounce message), output from the command is always discarded, whatever the setting of this option. This option and return_fail_output are mutually exclusive. Only one of them may be set.
This option contains either a colon-separated list of numbers, or a single asterisk. If ignore_status is false and return_output is not set, and the command exits with a non-zero return code, the failure is treated as temporary and the delivery is deferred if the return code matches one of the numbers, or if the setting is a single asterisk. Otherwise, non-zero return codes are treated as permanent errors. The default setting contains the codes defined by EX_TEMPFAIL and EX_CANTCREAT in sysexits.h. If Exim is compiled on a system that does not define these macros, it assumes values of 75 and 73, respectively.
If the command fails to complete within this time, it is killed. This normally causes the delivery to fail (but see timeout_defer). A zero time interval specifies no timeout. In order to ensure that any subprocesses created by the command are also killed, Exim makes the initial process a process group leader, and kills the whole process group on a timeout. However, this can be defeated if one of the processes starts a new process group.
A timeout in a pipe transport, either in the command that the transport runs, or in a transport filter that is associated with it, is by default treated as a hard error, and the delivery fails. However, if timeout_defer is set true, both kinds of timeout become temporary errors, causing the delivery to be deferred.
This specifies the umask setting for the subprocess that runs the command.
If this option is set true, the pipe transport writes messages in “batch SMTP” format, with the envelope sender and recipient(s) included as SMTP commands. If you want to include a leading HELO command with such messages, you can do so by setting the message_prefix option. See section 44.10 for details of batch SMTP.
This option is available only when Exim is running on FreeBSD, NetBSD, or BSD/OS. If it is set true, the setclassresources() function is used to set resource limits when a pipe transport is run to perform a delivery. The limits for the uid under which the pipe is to run are obtained from the login class database.
This option causes lines to be terminated with the two-character CRLF sequence (carriage return, linefeed) instead of just a linefeed character. In the case of batched SMTP, the byte sequence written to the pipe is then an exact image of what would be sent down a real SMTP connection.
The contents of the message_prefix and message_suffix options are written verbatim, so must contain their own carriage return characters if these are needed. Since the default values for both message_prefix and message_suffix end with a single linefeed, their values must be changed to end with \r\n if use_crlf is set.
If this option is set, it causes the command to be passed to /bin/sh instead of being run directly from the transport, as described in section 29.3. This is less secure, but is needed in some situations where the command is expected to be run under a shell and cannot easily be modified. The allow_commands and restrict_to_path options, and the $pipe_addresses facility are incompatible with use_shell. The command is expanded as a single string, and handed to /bin/sh as data for its -c option.
The next example shows a transport and a router for a system where local deliveries are handled by the Cyrus IMAP server.