Re: [Exim] Rewrite Help

Top Page
Delete this message
Reply to this message
Author: Philip Hazel
Date:  
To: Padraic Renaghan
CC: exim-users
Subject: Re: [Exim] Rewrite Help
On Wed, 21 Jun 2000, Padraic Renaghan wrote:

> I am trying to say:
> for any mail from foo.com
>   if the sender address matches -bounce (e.g., testlist-bounce)
>   fail and skip further processing this rule
>   otherwise, if the from header is defined
>     rewrite the From envelope and sender header with the
>     value of the from header

>
> Here is what I have so far:
>
> ^.*@.*foo\.com$ "${if match{$sender_address}{.*-bounce}\
> fail${if def:header_from:{$h_from:} fail}}" Fs


1. The initial regex ^.*@.*foo\.com$ is not quite correct, unless you
really do want to include addresses such as xxx@??? (only one
dot). Usually people want the domain to end in .foo.com, not just
foo.com. So it could be ^.*@.*\.foo\.com$ but could be made more
efficient by rewriting like this:

^(?>.*)(?<=\.foo\.com)

but don't worry about it if you don't want to.

2. However, the syntax of your replacement is incorrect. It starts off
OK (syntactially): ${if match{$sender_address}{.*-bounce} tests for a
sender address containing "-bounce". (The inclusion of .* does not
change the result of the regex, though it affects which way it searches
the string.) But what you have afterwards is syntactially incorrect.
After an "if" test there must be one string in braces; "fail" can only
be used for the *second* string. So what you probably want is to negate
the test:

${if ! match {$sender_address}{.*-bounce}

However, if you really want to test the local part of the sender
address, you should use ${local_part:$sender_address} - but maybe you
know that there aren't any domains called xxx-bounce.foo.com. :-)

3. You have a syntax error in what you have for the second alternative:
it needs to be in braces.

{${if def:header_from:{$h_from:}fail}

4. So the whole thing should be

^(?>.*)(?<=\.foo\.com) "${if ! match {$sender_address}{-bounce}\
{${if def:header_from:{$h_from:}fail}fail}" Fs

> Also, is there a good way to test rewrite rules like this that depend
> on other headers short of sending test messages through exim?


Not really, I'm afraid.

-- 
Philip Hazel            University of Cambridge Computing Service,
ph10@???      Cambridge, England. Phone: +44 1223 334714.