Custom Milter Headers in 1.6.0

1,145 views
Skip to first unread message

Thomas Leuxner

unread,
Jun 15, 2017, 5:25:25 AM6/15/17
to rsp...@googlegroups.com
Hi,

how would I add a custom Millter Header with 1.6.0? Tried this:

/etc/rspamd/local.d/milter_headers.conf:
header = "X-Spam-Spectre";
value = "yes";
remove = 1;

but still ended up with 'X-Spam: Yes‘.

Regards
Thomas

Andrew Lewis

unread,
Jun 15, 2017, 7:04:45 AM6/15/17
to rsp...@googlegroups.com
Do you want to change the name of an already-added header or add a new
header? To change the name of a header you should have something in
your config like follows:

~~~
routines {
x-spamd-bar {
header = "my-x-spamd-bar";
}
}
~~~

To add a new header you can write a Lua routine:
https://rspamd.com/doc/modules/milter_headers.html#custom-routines

Best,
-AL.

Thomas Leuxner

unread,
Jun 15, 2017, 7:37:01 AM6/15/17
to rsp...@googlegroups.com
* Andrew Lewis <rspam...@judo.za.org> 2017.06.15 13:04:

> Do you want to change the name of an already-added header or add a new
> header? To change the name of a header you should have something in your
> config like follows:
>
> ~~~
> routines {
> x-spamd-bar {
> header = "my-x-spamd-bar";

I'm trying to change an existing one to be unique. I went with this:

milter_headers {
use [
]
routines {
x-Spam {
header = "X-Spamd-Spectre";
}
}
}

Thomas Leuxner

unread,
Jun 15, 2017, 6:04:25 PM6/15/17
to rsp...@googlegroups.com
* Thomas Leuxner <t...@leuxner.net> 2017.06.15 13:36:

> * Andrew Lewis <rspam...@judo.za.org> 2017.06.15 13:04:
>
> > Do you want to change the name of an already-added header or add a new
> > header? To change the name of a header you should have something in your
> > config like follows:
> >
> > ~~~
> > routines {
> > x-spamd-bar {
> > header = "my-x-spamd-bar";

With the changes applied it still lists as:

X-Spam: Yes

Vsevolod Stakhov

unread,
Jun 15, 2017, 6:19:51 PM6/15/17
to Thomas Leuxner, rsp...@googlegroups.com
This header is not controlled by `milter_headers` module. It is added
whenever the action of message is `add_header`.

Thomas Leuxner

unread,
Jun 15, 2017, 6:51:35 PM6/15/17
to rsp...@googlegroups.com
* Vsevolod Stakhov <vsev...@highsecure.ru> 2017.06.16 00:19:

> This header is not controlled by `milter_headers` module. It is added
> whenever the action of message is `add_header`.

Understood. But how do I add custom headers for this action like possible with the old milter?

Alex JOST

unread,
Jun 21, 2017, 5:44:46 AM6/21/17
to rsp...@googlegroups.com
I'd like to know that too.

We are using Sieve to file mails with a 'X-Spam-Flag: Yes' header into
the users Junk folder. Changing those sieve scripts is not an option at
the moment.

--
Alex JOST

Andrew Lewis

unread,
Jun 21, 2017, 6:21:46 AM6/21/17
to rsp...@googlegroups.com

Quoting Alex JOST <jost+...@dimejo.at>:

>> Understood. But how do I add custom headers for this action like
>> possible with the old milter?
> I'd like to know that too.

Milter headers module supports user-defined routines:
https://rspamd.com/doc/modules/milter_headers.html#custom-routines

Library of already-provided functions includes "spam-header" which
happens to be perfect for the intended purpose:
https://rspamd.com/doc/modules/milter_headers.html#spam-header

I've added a purpose-specific `x-spam-flag` routine and enabled this
when `extended_spam_headers = true` however- that is in the master.

Best,
-AL.

Thomas Leuxner

unread,
Jun 22, 2017, 2:53:33 AM6/22/17
to rsp...@googlegroups.com
* Andrew Lewis <rspam...@judo.za.org> 2017.06.21 10:21:

> I've added a purpose-specific `x-spam-flag` routine and enabled this when
> `extended_spam_headers = true` however- that is in the master.

Thanks for the update. I have to admit that I'm a little confused now due to the contradicting statements about whether this header can be added via 'milter_headers' vs. it is fixed in code. So if the goal of a unique header can be achieved with the new lua file, can one also configure whether 'X-Spamd-Result' is added? Personally I deem the header data too bloated for my use case and wouldn't want to have it in each and every mail...

Regards
Thomas

Andrew Lewis

unread,
Jun 22, 2017, 4:11:56 AM6/22/17
to rsp...@googlegroups.com

Quoting Thomas Leuxner <t...@leuxner.net>:

> Thanks for the update. I have to admit that I'm a little confused
> now due to the contradicting statements about whether this header
> can be added via 'milter_headers' vs. it is fixed in code.

You can definitely add X-Spam-Flag to headers today by adding the
following to your milter_headers configuration:

~~~
use = ["spam-header"];
routines {
spam-header {
header = "X-Spam-Flag";
value = "Yes";
}
}
~~~

In a future release "extended_spam_headers = true;" will enable this.

> a unique header can be achieved with the new lua file, can one also
> configure whether 'X-Spamd-Result' is added? Personally I deem the
> header data too bloated for my use case and wouldn't want to have it
> in each and every mail...

If you don't want all headers added by "extended_spam_headers" don't
set this option. You can enable headers individually in `use`.

https://rspamd.com/doc/modules/milter_headers.html

Best,
-AL.

Alex JOST

unread,
Jun 22, 2017, 10:00:18 AM6/22/17
to rsp...@googlegroups.com
Hey,

>> Thanks for the update. I have to admit that I'm a little confused now
>> due to the contradicting statements about whether this header can be
>> added via 'milter_headers' vs. it is fixed in code.
>
> You can definitely add X-Spam-Flag to headers today by adding the
> following to your milter_headers configuration:
>
> ~~~
> use = ["spam-header"];
> routines {
> spam-header {
> header = "X-Spam-Flag";
> value = "Yes";
> }
> }
> ~~~

Reading your example it now makes sense to me. Thanks! For some reason
the documentation was not quite obvious ...

--
Alex JOST

Thomas Leuxner

unread,
Jun 23, 2017, 1:03:52 AM6/23/17
to rsp...@googlegroups.com
* Andrew Lewis <rspam...@judo.za.org> 2017.06.22 08:11:

> You can definitely add X-Spam-Flag to headers today by adding the following
> to your milter_headers configuration:

Thank you. I have successfully tested the following:

use = ["spam-header", "x-rspamd-server"];
routines {
spam-header {
header = "X-Spam-Flag-My_Unique_Header";
value = "Yes";
hide = 1;
}
x-rspamd-server {
header = "X-Rspamd-Server";
hide = 1;
}
}

For the record, this still adds the original 'X-Spam' header which I thought gets overridden by 'spam-header'.

Regards
Thomas

Andrew Lewis

unread,
Jun 23, 2017, 4:47:21 AM6/23/17
to rsp...@googlegroups.com

> For the record, this still adds the original 'X-Spam' header which I
> thought gets overridden by 'spam-header'.

That configuration works as expected in my testing:

"milter": {
"add_headers": {
"X-Spam-Flag-My_Unique_Header": "Yes",
"X-Rspamd-Server": "localhost.localdomain"
},
"remove_headers": {
"X-Spam-Flag-My_Unique_Header": 1,
"X-Rspamd-Server": 1
}
}

Note that "hide" isn't a valid configuration element; it would not
cause you trouble however.

Best,
-AL.

Reply all
Reply to author
Forward
0 new messages