Re: [exim] System Wide Filter & External File

Page principale
Supprimer ce message
Répondre à ce message
Auteur: Jasen Betts
Date:  
À: exim-users
Sujet: Re: [exim] System Wide Filter & External File
On 2017-07-07, Patrick Porteous <patrick.porteous@???> wrote:
>
> I've been working on this for a few days but still haven't been able to
> come up with a solution. If anyone has any suggestions they would be
> greatly appreciated.


>>
>> Is there a way to place all the words I'd like to filter in a file so
>> I don't have to keep adding them to the "OR" condition? I was
>> thinking about something like this but it isn't working as I would hope.


I'm not a user of exim filters myself, but it seems you can use any
string exapansion described in chapter 11 of the exim spec that is not
specifically banned from use in filters.

Exim string expansion can read files using "${readfile", and using
"${if forany" treat the file content as a list of values to test, the file will be
read as a user with few permissions. so it should be world readable.

But now there's a problem: expansion does not have a direct eqivalent to "contains"
the nearest is "match", which does a regex test, and is by default
case-sensitive, but case-sentitivity can be turned off by using (?i) as an
introduction

  if 
    ${if forany{<\n${readfile{/etc/exim/banned_subjects.conf}}}{match{${$h_subject}}{(?i)$item}}{bad}}
    is "bad"


#Note: this passes syntax checks but is otherwise untested.

There's a note on readfile that it can be banned using the
"forbid_filter_readfile" setting, so if it is banned, it's not going
to work.

Regular expressions are a complex subject, but if you only use
alphanumeric characters you can treat them the same as words.
Every other symbol represents itself if prefixed with a backslash,
other combinations may have special meanings - documentation here:
http://www.pcre.org/current/doc/html/pcre2pattern.html
but admittedly not the best introduction..

If you want to avoid regular expressions replace "$item" above with with
"${sg{$item}{([[:punct:]])}{\\\\$1}}" and every character of every line
in the file will then be treated as a "matching" character, disabling all
the regex features, giving what should be a exact copy of the
"contains" test.

Exim string expansion has a size limit of about 32K so you'll need to
keep the file with the word list below that size.

--
This email has not been checked by half-arsed antivirus software