Exim: Need help with script syntax (system_filter.exim)

Aspegic

Verified User
Joined
Aug 4, 2005
Messages
282
I added a condition to system_filter.exim so that all email originating from a certain domain is automatically forwarded to the feedback mailbox of that domain:

Code:
if $sender_address contains somedomain.com 
then
  unseen deliver [email][email protected][/email]
endif

and this works correctly.

Now I want to add the following condition: "EXCEPT if the mail was generated from a php script".

Mail generated by the php script contains the following header variable:
header_X-PHP-Originating-Script
so I should be able to check for this.

I have studied the exim scripting documentation and I came up with this:

Code:
if $sender_address contains somedomain.com and ${if !def:header_X-PHP-Originating-Script:}
then
  unseen deliver [email][email protected][/email]
endif

Unfortunately this doesn't work. I have tried several alternative ways to write this, like this for example:

Code:
if $sender_address contains somedomain.com then
  if ${if !def:header_X-PHP-Originating-Script:} then
    unseen deliver [email][email protected][/email]
  endif
endif

but this also doesn't work.

The documentation on this subject gives very few examples. In fact I couldn't find any that give examples of correctly using the "!" (not) modifier, or the correct syntax for nesting ifs.

Is there someone here who can help me write this in the correct way?
Many thanks in advance!

CentOS 6.0 64-Bit
DirectAdmin 1.49.1
Exim 4.86
 
Last edited:
Yes, I've read that page, and this one too:
http://www.exim.org/exim-html-3.30/doc/html/filter_33.html#SEC33
But there are no *examples* on either page. The second page for example, only says this about the "not" condition:
Code:
!<condition>
Preceding any condition with an exclamation mark negates the result of the condition.
That is the entire text on that page explaining anything about "not".

With just that little piece of information, should I write it like this:

${if !def:header_X-PHP-Originating-Script:}

or like this:

${!if def:header_X-PHP-Originating-Script:}

or like this:

!${if def:header_X-PHP-Originating-Script:}

And I'm not even certain that it is the "not" condition that is causing my script to fail. Maybe I made an error somewhere else in the script.

I'm not being lazy here! The documentation is sparse. Probably, if you already know the answer, then this is easy, it is always like that. But I don't know, I'm trying to figure it out. And once I've figured it out, I too might say "RTFM". But at the moment, all I can say is "IRTFM" and I still don't know.
 
Just try:
Code:
if $[COLOR=#333333]header_X-PHP-Originating-Script:[/COLOR] matches "" then

If X-PHP-Originating-Script is not available in headers, it'll just return an empty string (which is equal to "").
 
It works!
I still don't know how to use "not", but your solution doesn't require it, so that's ok.

For posterity,
the following script will forward any email coming from somedomain.com to [email protected], except if the mail was generated by a PHP script:

Code:
if $sender_address contains somedomain.com and $header_X-PHP-Originating-Script matches ""
then
  unseen deliver [email protected]
endif

Many thanks smtalk for your assistance!
 
Last edited:
It works!
I still don't know how to use "not", but your solution doesn't require it, so that's ok.

For posterity,
the following script will forward any email coming from somedomain.com to [email protected], except if the mail was generated by a PHP script:

Code:
if $sender_address contains somedomain.com and $header_X-PHP-Originating-Script matches ""
then
  unseen deliver [email protected]
endif

Many thanks smtalk for your assistance!

You're welcome. With not it'd look like:
Code:
if $header_X-PHP-Originating-Script: does not match "" then

But it wouldn't do what you need (it would do the opposite).
 
Back
Top