Regexp rule for specific message IDs

55 views
Skip to first unread message

Wiethoff, Helge

unread,
May 22, 2018, 4:53:38 AM5/22/18
to rsp...@googlegroups.com
Hi,

I try to understand and use https://rspamd.com/doc/tutorials/writing_rules.html.
I want to create a rule that returns a specific score for a particular message
ID (using regexp).

As I understood the manual, it is sufficient for my purpose to write the
following into "${CONFDIR}/rspamd.local.lua":

config['regexp']['LOCAL_MID_TEST'] = {
re = '/^Message ID:\sBla/',
score = 0,
description = 'custom MID rule',
group ='local',
}

But after a rspamd restart the symbol LOCAL_MID_TEST does not appear in the web
interface or in configdump. I don't think that the file rspamd.local.lua is
included in the configuration!?

Anybody got a hint for me?

Cheers,
Helge

Alexander Moisseev

unread,
May 22, 2018, 10:27:12 AM5/22/18
to rsp...@googlegroups.com
Use `rspamadm configtest` to check the configuration for correctness.

# rspamadm configtest
rcl parse error: cannot init lua file /usr/local/share/rspamd/rules/rspamd.lua: /usr/local/etc/rspamd/rspamd.local.lua:2: invalid escape sequence near ''/^Message ID:'; trace: [1]:{[C]:-1 - dofile [C]}; [2]:{rspamd.lua:50 - <unknown> [main]};
syntax BAD

That means the escape "\" character must be escaped as "\\" in Lua strings, or you can use square brackets as string delimeters "[[<string>]]" to avoid double-escaping.

Correct header name is "Message-ID", not "Message ID".

You need to match just "Message-ID" header value, not entire message source, so you should use a header regexp: "Header-Name=/regexp/flags"
https://rspamd.com/doc/modules/regexp.html#regular-expressions

So, you regexp could be
re = 'Message-ID=/^\\sBla/mH',
or
re = [[Message-ID=/^\sBla/mH]],

Wiethoff, Helge

unread,
May 22, 2018, 11:22:22 AM5/22/18
to 'Jason White' via rspamd
Hi Alex,

Thank you for the detailed explanation.

> Use `rspamadm configtest` to check the configuration for correctness.
I did use:
/etc/rspamd# rspamadm configtest
syntax OK

That's another reason why I don't think the file will be read at all. Even if I enter an obvious syntax error, "rspamadm configtest" returns syntax OK.

I just don't understand why the file rspamd.local.lua is not recognized. Does it still need to be referenced somewhere?
In /usr/share/rspamd/rules/rspamd.lua I only see:
if file_exists(local_conf .. '/rspamd.local.lua') then
dofile(local_conf ...'/rspamd.local.lua')
else

and my rspamd.local.lua is here: /etc/rspamd/rspamd.local.lua (world readable)

Strange ;-)

Cheers,
Helge

Alexander Moisseev

unread,
May 22, 2018, 12:03:32 PM5/22/18
to rsp...@googlegroups.com
It doesn't need to be referenced somewhere else. Everything looks good assuming $CONFDIR was set to "/etc/rspamd" at compile time.

Wiethoff, Helge

unread,
May 23, 2018, 4:22:06 AM5/23/18
to rsp...@googlegroups.com
Hi,

Alexander Moisseev, 22. Mai 2018 18:04:
> It doesn't need to be referenced somewhere else. Everything looks good
> assuming $CONFDIR was set to "/etc/rspamd" at compile time.

That's the way it should be. The configuration is in this directory and
modifications are generally accepted.

Can an incorrect configuration prevent rspamd.local.lua from being read? I think I
had a similar case with an incorrect DKIM configuration and resulting in an unread
history_redis.conf.

Thanks!
Helge

Wiethoff, Helge

unread,
May 23, 2018, 7:54:21 AM5/23/18
to rsp...@googlegroups.com
Hi,

after updating to 1.7.5 rspamd.local.lua is recognized... Nice :-)

Thanks, Alex!

Cheers
Helge

Reply all
Reply to author
Forward
0 new messages