andybalholm / spamass-milter

A Sendmail milter to run SpamAssassin
7 stars 10 forks source link

Ability to add arbitrary X-Spam-Foo headers? #11

Open thegushi opened 3 years ago

thegushi commented 3 years ago

Hey there.

I'm trying to use this milter (in its original, OS-packaged form) to add additional debugging headers, such as X-Spam-ASN.

The manpage isn't quite clear about this:

-M      Like -m, but also disables creation of any SpamAssassin
            X-Spam- headers as well.  Both tagged and untagged mail gets
             passed through unchanged.

So the assumption would be if you don't specify -M, you get those headers, right? Unfortunately, no -- there's a select list of headers that are maintained, and something happens at line 1212 of spamass-milter.cpp, but my C isn't good enough to tell if its stripping it out, or should be leaving it in but isn't.

This is partially a docbug to make this behavior clearer, and partially a request to make it so arbitrary headers work and can be added.

andybalholm commented 3 years ago

The code on line 1212 is about stripping off X-Spam headers that were already on the message before passing it to SpamAssassin.

The -M flag gets converted to the dontmodify boolean variable. So you'll need to look for places dontmodify is used to find the code that is affected by it.

thegushi commented 3 years ago

This isn't about dontmodify. The problem here is even without -M, any new headers are discarded. If you add to your spamassasin config something like:

add_header ham Ham THISISHAM

You won't get that header. Many spamassassin rules add tags that can be used by later filters (like in your MUA).

andybalholm commented 3 years ago

The message headers are modified by the update_or_insert function, and it's only called for the headers that SpamAssassin normally generates.

thegushi commented 3 years ago

Okay. Would you consider it out of scope to work to add a function that extends that to add any X-Spam-NNN header that SA can create? I can probably supply a patch. I'm not a C coder but the dayjob writes C all day long and it feels pretty trivial.

I forsee two uses. 1) Being able to supply a list of X-Spam-Foo headers that, if present in the modified message, will be update_or_inserted (if one is really concerned about arbitrary headers containing something). 2) Adding an option that says to update_or_insert any that come back.

Additionally, the headers that are by default allowed without this change should probably go in the manpage.

SvenEwald commented 3 years ago

I would appreciate this. I lost 3 days in debugging my setup to find the milter filter silently dropping the headers. :-( There are SA plugins like RelayCountry that can be used to add custom headers and I would love to use these downwards the pipe.

andybalholm commented 3 years ago

Pull requests are welcome. But I don't use SpamAssassin myself anymore, so I can't make the change myself without setting up a whole new mail server to test the changes.

MichaelStauber commented 2 years ago

SvenEwald said:

> I would appreciate this. I lost 3 days in debugging my setup to find the milter filter silently dropping the headers. :-( There are SA plugins like RelayCountry that can be used to add custom headers and I would love to use these downwards the pipe.

I had the same issue and I just did a fork that adds the X-Spam-ASN headers in the same way that the RelayCountry code changes added them.

The spamassassin-milter I'm using in production even has a couple of extra patches that I might patch in later. Like the "authuser.patch" that I found somewhere. It allows (if the -I flag is used) bypassing of the milter if the sender used SMTP-Auth.

There are so many forks of spamass-milter floating around these days (not just here), that it's a bit hard to keep track of features that were added here or there after the original Savannah repo got stale.

andybalholm commented 2 years ago

I've merged your patch, @MichaelStauber .

MichaelStauber commented 2 years ago

I've merged your patch, @MichaelStauber .

Thank you!