Re: [Exim] help with condition

Top Page
Delete this message
Reply to this message
Author: Nico Erfurth
Date:  
To: Johann Spies, exim-users
Subject: Re: [Exim] help with condition
Johann Spies wrote:
> --
> I have not received my exim book yet and the syntax for conditions not
> very clear to me.
>
> I want to test two things with this condition:
>
> 1. Is the message smaller than 80k.
> 2. Is there an entry in the postgres-table "emailuser" which has the
>    $local_part" in the field "username" and for that record is the
>    contents of the field "spamdelete" equal to 't'.

>
>
> condition = ${if and {{ < { $message_size}{80k}}}{${lookup pgsql
> {select distinct spamdelete from emailuser where username =
> '${uc:${quote_pgsql:$local_part}}' and spamdelete = 't' limit
> 1}{${lc:$value}}{:fail:}}}}
>
> If both these conditions are true, the message must be scanned by
> Spamassassin.
>
> I would appreciate some help with this one please.


1.) some formatting helps to make the condition more readable
2.) you're trying to use a lookup as an if condition
3.) you're making it more complex than it needs to be ;) (IMHO)

I assume you want to use this inside of an router?
The obvious way:

Using two preconditions:
local_parts = pgsql;select 1 from emailuser where \
                       username='${uc:${quote_pgsql:$local_part}}' and \
                       spamdelete = 't' limit 1
condition = ${if < {$message_size}{80k}{1}}


The problem with this is, that the pgsql-lookup will be done in any
case, because the local_parts condition is checked before the
condition-statement.

The more advanced way:

condition = ${if < {$message_size} {80k} \
     {${lookup pgsql \
         {select 1 from emailuser where \
          username='${uc:${quote_pgsql:$local_part}}' and \
          spamdelete = 't' limit 1} \
       }\
     }\
   }


How it works:
The if-condition checks for the message-size, when the message is bigger
than 80k, the expansion will return an empty string, because no value
was given for this case. When the message is smaller, it will evaluate
the lookup, that will return 1 as a value, otherwise an empty string.

Nico