How to remove X-Ham-Report from message header

Charles Lindsey

Registered
Aug 26, 2018
2
0
1
UK
cPanel Access Level
Website Owner
I have an incoming message which contains a header I want to remove before passing it on to the addressee (using a Forwarding Rule).

So I want to create a filter which recognises this is a message I need to fix. and which uses the "Pipe to a Program" option. I then have to provide a script which accepts this message on stdin, but I must not write anything to stdout because that would signify the message was to be discarded. I can easily edit the message to remove the offending header (I would probably use awk), but where do I then output it to so that it gets sent?

(And if you want to know why I want to remove a header, it is the X-Ham-Report which cpanel inserts after usinfgSpamassassin, and is incompliant with RFC 5322 - but that is another story :) )
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,260
463
Hello @Charles Lindsey,

Have you tried making use of the "headers remove" filter action to remove part of the message header instead of handling that through a script? EX:

Code:
#HamRemoval
if
 $header_to: is "[email protected]"
then
 headers remove "X-Ham-Report"
 deliver "[email protected]"
endif
Note this will only work as an Exim system filter rule, and requires root access to the server to setup:

How to Customize the Exim System Filter File - cPanel Knowledge Base - cPanel Documentation

Thank you.
 
Last edited:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,260
463
Hello @Charles Lindsey,

I performed some additional testing and concluded that it's not possible to remove X-Ham-Report from the email header using account-level and email-level filter rules or custom SpamAssassin rules. Header addition and removal is available only in the Exim system filters (which requires root access to add/edit).

I did test creating an Exim system filter as "root" and confirmed the following example works as intended:

Code:
#HamRemoval
if
 $header_to: is "[email protected]"
then
 headers remove "X-Ham-Report"
 deliver "[email protected]"
endif
The best advice I can provide is to reach out to your web hosting provider to see if they can setup this custom Exim system filter rule on your behalf.

Let me know if you have any additional questions.

Thank you.

Moderation Note: I edited/removed some of the previous posts on this thread to reflect the results of additional testing.