Re: [exim] Pre-processing incoming mail

Αρχική Σελίδα
Delete this message
Reply to this message
Συντάκτης: Jaap Winius
Ημερομηνία:  
Προς: John Hall
Υ/ο: Exim-users
Αντικείμενο: Re: [exim] Pre-processing incoming mail
Hi John,

Just wanted to let you and the list know that your suggestion worked
for me. This is to let you know what I did. I'll start by saying that
I'm using Exim 4.50 and Perl 5.8.4 on a Debian sarge machine. The files
I created were:

 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



::: 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.


::: Transport::::::::::::::::
abc:
driver = pipe
user = mail
group = mail
command = /usr/local/sbin/abc-filter
log_output
use_bsmtp
batch_max = 100


::: 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).


Thanks for your help!

Jaap