Mailing List Archive

Exim4 pipe email through two commands
Hi,
I currently have a few adresses that are set up as follows (in a aliases file):

someemail: "|/usr/bin/somecommand -opt someoption"

However, I would like the message to pass through another command
first, much like normal shell pipeling:

user@computer: echo "someemailcontents" | /usr/bin/somefilter -n 5 |
/usr/bin/somecommand -opt someoption

There are a couple of ways I imagine I could do this:
1. hardcode the second command in the first script (=> saving all the
output and calling the command with that output on its input
afterwards)
2. Modify the aliases file so that the mail goes through 2 commands
(like shell pipelining)
3. Modify the router in the config file so all email of that router
will go through that filter first (all the "special" adresses are in a
seperate router directive)

However I do not know if 2 or 3 is possible with exim4. Can anyone
enlighten me on this?

Thanks,
David

--
## List details at http://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Exim4 pipe email through two commands [ In reply to ]
David Hoepelman wrote:
> Hi,
> I currently have a few adresses that are set up as follows (in a aliases file):
>
> someemail: "|/usr/bin/somecommand -opt someoption"
>
> However, I would like the message to pass through another command
> first, much like normal shell pipeling:
>
> user@computer: echo "someemailcontents" | /usr/bin/somefilter -n 5 |
> /usr/bin/somecommand -opt someoption
>
> There are a couple of ways I imagine I could do this:
> 1. hardcode the second command in the first script (=> saving all the
> output and calling the command with that output on its input
> afterwards)
> 2. Modify the aliases file so that the mail goes through 2 commands
> (like shell pipelining)
> 3. Modify the router in the config file so all email of that router
> will go through that filter first (all the "special" adresses are in a
> seperate router directive)
>
> However I do not know if 2 or 3 is possible with exim4. Can anyone
> enlighten me on this?
>
> Thanks,
> David
>

As usual, here are several ways that will work...

'1' works- but... nothing to do with Exim.

'2' - chaining scripts in the ~/aliases file, should be essentially a 'don't
care' situation to Exim. Probably so even if one or more scripts ends up sending
back into Exim.

But I've never had a need to try this, so 'CAVEAT' - SWAG only.

'3' the use of bespoke router/transport sets AND NOT using the 'ordinary'
aliases file gets my vote. It would be only marginally harder to set up, but
potentially less work to maintain over time.

That partly because the addresses to be actioned could be held in a flat-file or
DB that Exim can read, but one that other (non-root) staff or daemons might be
allowed to alter. Manually OR automagically. That can be made so for a non
'system' (/etc/aliases) aliases-*style* file with appropriately altered perms,
... but those can perhaps be more hazardous. Too general-purpose, nore 'capable'
of doing the unwanted/unexpected...

A lookup 'hit' could be used to set an acl_m flag or X-header in an acl for
later use by router/transports, AND/OR/ELSE they can do their own lookups. So
long as either the acl or router you want to trigger is actually *traversed*.

See 'unseen' for chaining routers.... (perhaps also 'shadow transport')

.. and also 'no_verify', 'errors_to', and 'debug_print', one or all of which
might be helpful.

DISCLAIMER: applies to 'vanilla' Exim monobloc '~/configure'.

'Should' work the same in an Exim4 with split config, but not my ken where or
how to apply the necessaries..

HTH, -

Bill

--
## List details at http://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Exim4 pipe email through two commands [ In reply to ]
> I currently have a few adresses that are set up as follows (in a aliases file):
>
> someemail: "|/usr/bin/somecommand -opt someoption"
>
> However, I would like the message to pass through another command
> first, much like normal shell pipeling:
>
> user@computer: echo "someemailcontents" | /usr/bin/somefilter -n 5 |
> /usr/bin/somecommand -opt someoption

someemail: |/bin/sh -c '/usr/bin/somefilter -n 5 | /usr/bin/somecommand -opt someoption'

or:

someemail: |/root/script

file /root/script (chmod 755):
#!/bin/sh
/usr/bin/somefilter -n 5 | /usr/bin/somecommand -opt someoption

Double quotes are necessary only if an alias contains a comma.

--
## List details at http://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Exim4 pipe email through two commands [ In reply to ]
On 2010-11-25 at 22:18 +0100, David Hoepelman wrote:
> user@computer: echo "someemailcontents" | /usr/bin/somefilter -n 5 |
> /usr/bin/somecommand -opt someoption

> There are a couple of ways I imagine I could do this:
> 2. Modify the aliases file so that the mail goes through 2 commands
> (like shell pipelining)

> However I do not know if 2 or 3 is possible with exim4. Can anyone
> enlighten me on this?

The "redirect" Router which processes the aliases file will reference a
"pipe" transport, probably called "address_pipe". Change that to
"address_pipe_unsafe", then go to the Transports section of the config
(after "begin transports") and make a copy of "address_pipe", calling it
"address_pipe_unsafe". On this copy, add the "use_shell" option.

A Unix shell will then be used for parsing the command and constructing
the command pipeline and you can join together multiple commands, as you
show above. This has all the downsides of permitting arbitrary commands
to appear, with command substitution and other security issues, so be
cautious in your deployment of this -- only use it for Routers where the
command is specified by a trusted account, and no part of the original
address can appear in the command.

--
## List details at http://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/