X-Spam-Score?

1,098 views
Skip to first unread message

Frank Schnell

unread,
Sep 11, 2017, 11:12:24 PM9/11/17
to rspamd
Is it possible to add a header X-Spam-Score very similar to X-Spam-Status but only containing the score?

X-Spam-Score: 0.75

Felix Schwarz

unread,
Sep 12, 2017, 3:07:39 AM9/12/17
to rspamd

Am 12.09.2017 um 05:12 schrieb Frank Schnell:
> Is it possible to add a header X-Spam-Score very similar to X-Spam-Status but only containing the score?
>
> X-Spam-Score: 0.75

IIRC the idea is that rspamd does not modify the message add all [1].

This should be configured in your MTA integration. With Exim I'm doing this by
adding/removing headers in routers/ACLs. For Postfix you probably should look
at milter.
(And yes just removing a header is not 100% safe because you might break DKIM.)

Felix

[1] https://github.com/vstakhov/rspamd/issues/603#issuecomment-213786988

Frank Schnell

unread,
Sep 12, 2017, 3:24:50 AM9/12/17
to rspamd


12.09.2017, 02:07, "Felix Schwarz" <felix....@oss.schwarz.eu>:
> Am 12.09.2017 um 05:12 schrieb Frank Schnell:
>>  Is it possible to add a header X-Spam-Score very similar to X-Spam-Status but only containing the score?
>>
>>  X-Spam-Score: 0.75
>
> IIRC the idea is that rspamd does not modify the message add all [1].
>
> This should be configured in your MTA integration. With Exim I'm doing this by
> adding/removing headers in routers/ACLs. For Postfix you probably should look
> at milter.

I use worker-proxy as milter. Rspamd adds other headers such as x-spam-status, so it should be able to add a new x-spam-score too.

Andrew Lewis

unread,
Sep 13, 2017, 7:51:06 AM9/13/17
to rsp...@googlegroups.com
Hi,

> I use worker-proxy as milter. Rspamd adds other headers such as
> x-spam-status, so it should be able to add a new x-spam-score too.

So milter headers module seems to miss support for exactly this.
However it's easily done with a bit of Lua, either by adding a "custom
routine" in milter headers module or by just calling
task:set_milter_reply() directly in a rule (things passed to this
function are merged these days so there's no particular need to use
the custom routine stuff anymore).

Milter headers "custom routine" way:

~~~
# /etc/rspamd/local.d/milter_headers.conf
use = ["my-x-spam-score"];
custom {
my-x-spam-score = <<EOD
return function(task, common_meta)
local sc = common_meta['metric_score'] or task:get_metric_score()
-- return no error
return nil,
-- header(s) to add
{['X-Spam-Score'] = string.format('%.2f', sc[1])},
-- header(s) to remove
{['X-Spam-Score'] = 1},
-- metadata to store
{}
end
EOD;
}
~~~

Lua way:

~~~
-- /etc/rspamd/rspamd.local.lua
rspamd_config.ADD_X_SPAM_SCORE = {
priority = 10,
type = 'postfilter',
callback = function(task)
local sc = string.format('%.2f', task:get_metric_score()[1])
task:set_milter_reply({
add_headers = {['X-Spam-Score'] = sc},
remove_headers = {['X-Spam-Score'] = 1},
})
end
}
~~~

Best,
-AL.

Frank Schnell

unread,
Sep 13, 2017, 1:24:24 PM9/13/17
to Andrew Lewis, rsp...@googlegroups.com


13.09.2017, 06:51, "Andrew Lewis" <rspam...@judo.za.org>:
Thank you, the Lua way works good. But now this error started showing in the logs:

task; lua_metric_symbol_callback: call to (SETTINGS_CHECK) failed (2): /usr/share/rspamd/lua/url_redirector.lua:260: attempt to index local 'url' (a nil value); trace: [1]:{/usr/share/rspamd/lua/url_redirector.lua:260 - <unknown> [Lua]};

Looks unrelated but it didn't happen until I added the code you suggested.

Is it advisable thus to use the other method?

Frank Schnell

unread,
Sep 13, 2017, 1:39:01 PM9/13/17
to Andrew Lewis, rsp...@googlegroups.com


13.09.2017, 12:24, "Frank Schnell" <fsch...@yandex.com>:
The other method seems to be error-free.
Reply all
Reply to author
Forward
0 new messages