[Rspamd-Users] Regex – how to do it right?

Tino Hendricks t.hendricks at interpool.de
Fri Jan 5 16:47:11 UTC 2024


Hey guys,

thank you so much for your input. I really appreciate your time!

As for the regex: Yes, it was just an (admittedly) stupid example, but I tried to keep it simple. 
The real regex is multiline with quantifiers („…{n}…“).

Andrew, the fine manual lists „…should be stored in the file ${CONFDIR}/rspamd.local.lua,..“, and without reading any further I thought CONFDIR is the local.d. %-/
https://rspamd.com/doc/tutorials/writing_rules.html#configuration-files
I think it’s a little bit confusing here:
https://rspamd.com/doc/configuration/index.html#rspamd-variables

LOCAL_CONFDIR: site-local configuration directory for Rspamd (usually the same value as $CONFDIR, and not to be confused with local.d)
„Hey, we call it LOCAL… but it isn’t local.d!“ 🧐

Putting rspamd.local.lua now into the correct place works like a charm, thank you!

Best,

Tino

> Am 04.01.2024 um 14:37 schrieb Andrew Lewis via Users <users at lists.rspamd.com>:
> 
> Hi Tino,
> 
> Use regex rules where possible, see here for additional information
> about them:
> 
> https://rspamd.com/doc/modules/regexp.html
> 
> If you need/want to use maps, multimap may be a reasonable choice. If
> you need flexibility beyond what's possible with regex rules you may
> want to reach for Lua (or some combination of regex & Lua).
> 
> The correct path for rspamd.local.lua is directly under /etc/rspamd
> (not under local.d).
> 
> You'd want something similar to as below I suppose:
> 
> config['regexp']['PAKETE_TEST'] = {
>  -- use square quotes to avoid escaping, set match type
>  re = [[/ *<p>Kunden.*<\/p>/{sa_raw_body}]],
>  score = 10.0,
> }
> 
> Best,
> -AL.
> 
> On Thu, 2024-01-04 at 11:42 +0100, Tino Hendricks wrote:
>> Dear list,
>> 
>> being new to rspamd I too often struggle with the (too?) extensive
>> manuals.
>> 
>> I want to filter out the annoying parcel delivery spams coming from
>> hotmail that obviously don’t get learned by Bayes.
>> It’s a multiline HTML that I consider the sufficient characteristic.
>> (For testing purpose I started with a one line snippet.)
>> 
>> From the manuals I think there are 3 ways to go:
>> 1. Mulitmap:
>>  https://rspamd.com/doc/modules/multimap.html#regexp-maps
>> 2. Rules (Regex)
>>  https://rspamd.com/doc/tutorials/writing_rules.html#regexp-rules
>> 3. Rules (Lua)
>>  https://rspamd.com/doc/tutorials/writing_rules.html#lua-rules
>> 
>> 
>> I tried #2 by putting 
>> 
>> config['regexp‘][PAKETE_TEST'] = '/ *<p>Kunden.*<\/p>/'
>> 
>> into /etc/rspamd/local.d/rspamd.local.lua to no avail
>> 
>> Next I tried #3 with 
>> 
>> config['regexp']['PAKETE_TEST'] = {
>>     re = '/ *<p>Kunden.*<\/p>/',
>>     score = 10.0,
>>     condition = function(task) -- run this rule only if some
>> condition is satisfied
>>         return true
>>     end,
>> }
>> 
>> into /etc/rspamd/local.d/pakete_rules.lua to no avail
>> 
>> #1 works but this seems to be the least comfortable way if it comes
>> to many and maybe complex Regexes.
>> 
>> How do you do it?
>> 
>> Thanks,
>> 
>> Tino
> 
> -- 
> Users mailing list
> Users at lists.rspamd.com
> https://lists.rspamd.com/mailman/listinfo/users



More information about the Users mailing list