Configure a cPanel system to do Subject: tagging with SpamAssassin and Exim

By efault, on a cpanel system, Spam Assassin doesn’t allow the subject line rewriting.  I find it a quick short cut to be able to glace at the subject line and tell if the email is junk or not … Here is how to enable it.  Requires root level access on the server.

First off – thanks to the exim wiki

Start off by saving your current exim config :
cp /etc/exim.conf /etc/exim.conf.bak

Open /etc/exim.conf in your editor of choice, I use vi

go to line 390, and you should see something like :

condition = ${if eq {${acl_m0}}{1}{1}{0}}
spam = ${acl_m1}
log_message = “SpamAssassin as ${acl_m1} detected message as spam ($spam_score)”
add_header = X-Spam-Subject: ***SPAM*** $h_subject
add_header = X-Spam-Status: Yes, score=$spam_score
add_header = X-Spam-Score: $spam_score_int
add_header = X-Spam-Bar: $spam_bar
add_header = X-Spam-Report: $spam_report
add_header = X-Spam-Flag: YES
set acl_m2 = 1

Just before the last line we need to add a new header to the message :

add_header = X-Spam-Flag: YES
add_header = X-New-Subject: ***SPAM ($spam_score) *** $h_subject
set acl_m2 = 1

Save the file and restart exim. Now, when a message is detected as spam, it will add a header named X-New-Subject.

Now we need to edit the exim system filter, which on a cpanel system is located at :

make a backup : cp /etc/cpanel_exim_system_filter /etc/cpanel_exim_system_filter.bak

Then open in your editor and add the following lines @ the end of the file :

if first_delivery then
if $h_X-New-Subject: is not “”
headers remove Subject
headers add “Subject: $rh_X-New-Subject:”
headers remove X-New-Subject
# …

This first removes the existing subject, then adds a new Subject line with the spam tagging and the spam score.


Comments are Closed