Hi list,
Just wanted to let everyone know that John Hall's suggestion worked for
me and what I did. This is me "giving back to the community". :-)
To recap, the objective was to single out certain messages and run one
or more search-and-replace routines over them before final delivery.
I'll start by saying that I'm using Exim 4.50 and Perl 5.8.4 on a
Debian sarge machine. The solution required me to create three files:
Exim router: /etc/exim4/conf.d/router/650_exim4-config_abc-filter
Exim transport: /etc/exim4/conf.d/transport/30_exim4-config_abc-filter
Perl script: /usr/local/sbin/abc-filter
::: Exim router :::::::::::::
abc:
debug_print = "R: abc-filter for $local_part@$domain"
driver = accept
local_parts = jaap
senders = info@???
transport = filter
condition = "${if eq{$received_protocol}{local-bsmtp}{no}{yes}}"
:::::::::::::::::::::::::::::
Note: I first tried to use a custom protocol, which I wanted to call
"abc-filter" (together with the 'exim4 -oMr <protoco_name>' option)
instead of "local-bsmtp", but that didn't work in my case. I suppose I
would have to do more to override this default. Not that I care now...
The file name, 650_exim4-config_abc-filter, was important in that it
had to be placed above the 700_exim4-config_procmail router.
::: Exim Transport ::::::::::
abc:
driver = pipe
user = mail
group = mail
command = /usr/local/sbin/abc-filter
log_output
use_bsmtp
batch_max = 100
::: Perl script :::::::::::::
#!/usr/bin/perl
while (<>) {
s/foo/bar/;
s/junk//g;
$array[$i] = "$_";
$i++;
}
unshift @array, "helo localhost\n";
pop @array;
push @array, "\n.\nquit\n";
open BSMTP, "| /usr/sbin/exim4 -bS";
print BSMTP @array;
:::::::::::::::::::::::::::::
Note: To allow Exim to start the script, I changed its group ID to
'mail' (Exim's group) and the group permissions to read and execute.
This script edits the stream of text from the message as it arrives
through standard in, after which it adds a valid helo to the beginning,
and the bit with the '.' and the .'quit' on the end. Actually, the
original message already ended with a '.', but for some reason if I
didn't pop it off the end of the message and add it back on myself, a
warning would show up in Exim's mainlog.
Also, I further modifed this script to send more than one message at a
time, but then I had to reopen the BSMTP file handle for each message I
sent with it (actually, I used 'close' and 'open', but I don't think
that should make a difference).
Jaap