I want to know how to check if the header exists.

46 views
Skip to first unread message

rtaka...@gmail.com

unread,
Apr 7, 2017, 5:47:06 AM4/7/17
to rspamd
Hi there.

I want to add a score if a specific header exists.
I using regexp as follows now.

Exsample: (/local.d/regexp.conf)
---
HEADER_EXISTS {
     re = "X-Header=/.*/iH";
     group = "header";
     score = 1.0;
}
---
However, I do not think this is a good writing style.
Is there any better way to write it?

Andrew Lewis

unread,
Apr 10, 2017, 3:30:48 AM4/10/17
to rsp...@googlegroups.com
Hi,

> However, I do not think this is a good writing style.
> Is there any better way to write it?

That's probably fine. Way to write this with a Lua rule could be as follows:

~~~
-- /etc/rspamd/rspamd.local.lua
rspamd_config.HEADER_EXISTS_FOO = {
callback = function(task)
return task:get_header('Foo') and true or false
end,
score = 1.0
}
~~~

Best,
-AL.

Vsevolod Stakhov

unread,
Apr 10, 2017, 4:15:31 AM4/10/17
to Andrew Lewis, rsp...@googlegroups.com

rtaka...@gmail.com

unread,
Apr 10, 2017, 5:54:22 AM4/10/17
to rspamd
Is it better to use "header_exists" of Internal functions?

----
-- /etc/rspamd/rspamd.local.lua
rspamd_config.HEADER_EXISTS_FOO = { 
   callback = function(task) 
     return task:header_exists('Foo') and true or false 
   end, 
   score = 1.0 
}
----

Andrew Lewis

unread,
Apr 10, 2017, 6:36:25 AM4/10/17
to rsp...@googlegroups.com

> Is it better to use "header_exists" of Internal functions?

Yes.

~~~
-- /etc/rspamd/rspamd.local.lua
local reconf = config['regexp']
reconf['HEADER_EXISTS_FOO'] = {
re = 'header_exists("Foo")',
Reply all
Reply to author
Forward
0 new messages