[exim] Run a shell script from transport?

Página Principal
Apagar esta mensagem
Responder a esta mensagem
Autor: Nils Altenbach
Data:  
Para: exim-users
Assunto: [exim] Run a shell script from transport?
Hi everybody,

I have very limited experience with configuring Exim. I'm using exim4 on
Lenny with a MySQL user database, which is working fine, but I want
exim4 to run a shell script every time the transport
local_mysql_delivery delivers a mail, with the username of the user
receiving the mail (local part of the email address) as argument for
that script.

I've tried using the transport_filter, but it doesn't work.

This is the transport in question:


local_mysql_delivery:
   driver        = appendfile
#  file         = /var/mail/$local_part
#  directory    = /home/$local_part/.maildir
   directory     = /var/mail/${domain}/${local_part}/
   maildir_format
   delivery_date_add
   envelope_to_add
   return_path_add
   user          = mail
   group         = mail
   mode          = 0660


# running the delivery alert script

# transport_filter = /bin/sh -c /usr/local/bin/maildelivered.sh
'${quote_mysql:$local_part}'

   # at this time, we know a local user to get his individual 
preferences to tag the mail
   # the '${eval:$header_X-Spam-Score-Int:}' is is a hack to cope with 
negative ints that seem to be parsed as strings, thus failing the 
comparsion
   # if there's no X-Spam-Score-Int header set by data-acl above, don't 
panic ;-)
   # another hack is that we remove important headers, we add later to 
be sure there are no multiple versions from earlier relays, or forged 
ones (this is BUGGY right now as it merges all equal headers!)
   #     therefore i implemented the 
${sg{$header_X-Spam-Score-Int:}{^.*\n}{}} regex hack, that strips all
   headers_remove = Subject : X-Spam-Flag : X-Spam-Score-Int : 
X-Spam-Score : X-Spam-Bar : X-Spam-Report
   headers_add   = "X-Spam-Threshold: ${lookup mysql{ \
                                         SELECT spam_threshold \
                                         FROM user \
                                         WHERE 
username='${quote_mysql:$local_part}' \
                                         AND 
domain='${quote_mysql:$domain}' \
                                         AND SMTP_allowed='YES' \
                                       }{$value}{ERROR}}\n\
                   X-Spam-Score: $header_X-Spam-Score:\n\
                   X-Spam-Score-Int: $header_X-Spam-Score-Int:\n\
                   X-Spam-Bar: $header_X-Spam-Bar:\n\
                   X-Spam-Report: $header_X-Spam-Report:\n\
                   X-Spam-Flag: ${if def:header_X-Spam-Score-Int:{\
                                         ${if 

>={${eval:${sg{$header_X-Spam-Score-Int:}{^.*\n}{}}}}\

                                                 {${lookup mysql{ \
                                         ${if 

>={${eval:${sg{$header_X-Spam-Score-Int:}{^.*\n}{}}}}\

                                                 {${lookup mysql{ \
                                                         SELECT 
spam_threshold*10 \
                                                         FROM user \
                                                         WHERE 
username='${quote_mysql:$local_part}' \
                                                         AND 
domain='${quote_mysql:$domain}' \
                                                         AND 
SMTP_allowed='YES' \


}{$value}{ERROR}}}{YES}{NO}}\
                                         }{\
                                         UNKNOWN\
                                 }}\n\
                   Subject: ${if def:header_X-Spam-Score-Int:{\
                                         ${if 

>={${eval:${sg{$header_X-Spam-Score-Int:}{^.*\n}{}}}}\

                                                 {${lookup mysql{ \
                                                         SELECT 
spam_threshold*10 \
                                                         FROM user \
                                                         WHERE 
username='${quote_mysql:$local_part}' \
                                                         AND 
domain='${quote_mysql:$domain}' \
                                                         AND 
SMTP_allowed='YES' \


}{$value}{ERROR}}}{${lookup mysql{ \

SELECT spam_tag \

FROM user \

WHERE username='${quote_mysql:$local_part}' \

AND domain='${quote_mysql:$domain}' \

AND SMTP_allowed='YES' \

}{$value}{ERROR}}$h_subject:}{$h_subject:}}\
                                 }{$h_subject:}}\n\
                   X-Delivered-To: $original_local_part@$original_domain 
($local_part@$domain)\n\
                   X-Message-Age: $message_age"


The transport filter is commented out because if I use it, mails aren't
delivered, and /var/log/exim4/mainlog gives me something like this:

2010-12-03 16:51:25 1POXtY-00035P-2l == abc@??? R=mysql_user
T=local_mysql_delivery defer (-24): transport filter process failed
(127) while writing to tmp/1291391485.H362240P11945.fooserver.net:
unable to execute command

What am I doing wrong? Should I use run instead of transport_filter, and
how exactly am I supposed to run a shell script from a transport? I
don't need any feedback from that shell script (other than it did run
without errors), I just need exim to run that script every time a MySQL
user receives a mail.

Thanks in advance.
Nils Altenbach