Can you change the Spamassassin Spam Box folder

spadmin

Member
Jul 31, 2011
6
3
53
Is is possible to change the Spam Box Folder?

Maybe to INBOX.Junk instead.

Is it possible to Capitalize it to "Spam" instead of "spam"?


If so, can these changes be done for all new accounts?
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
42
348
somewhere over the rainbow
cPanel Access Level
Root Administrator
The spam box name cannot be changed from the information I checked so far, but you could use a filter rule rather than the spam box to put emails into a different box:

#SpamFolderRule
if
$h_X-Spam-Bar: contains "+++++"
then
save "/home/username/mail/.foldername/" 660
endif

This could be done in cPanel > Account Level Filtering area by selecting "Create a New Filter" option, then using Spam Bar, contains, +++++ (this is a score of 5.0 or greater) in the "Rules" area. In the "Actions" area, select Deliver to folder and then click the "Change" button to change to a set folder on the account.

If you want this for each individual email account, you would want to do this in the User Level Filtering area instead for each email account.

If you do want to try to automate it, you'll have to add not only rules for each email account in /etc/vfilters/domain.com file where domain.com is the domain name in question, but also in /home/username/etc/domain.com/emailuser/filter file where username is the cPanel username, domain.com is the domain name, and emailuser is the email account user's name such as admin in [email protected]. You'd want to enable a filter and then cat the file to see how the filter file looks typically at that location.
 

spadmin

Member
Jul 31, 2011
6
3
53
I did find the location of the "spam" folder.

It's in /etc/exim.conf

Code:
directory = "${extract{5}{:}{${lookup passwd{$local_part}{$value}}}}/mail/.spam"
However, this will get overwriten on each Update. Also this requires that each client set the Spam Box to ON.

So I found a better solution:
( I did want this to be global so I didn't have to run it for each user)
( WHM 11.30.1 (build 4) CENTOS 5.6 x86_64 )

1. Turn OFF "Spam Box" in WHM -> Tweak Settings -> Mail.
This just allows the user to control it, but I wanted it always on and I want to forward to the ".Junk" folder anyways.
WHM -> Tweak Settings -> Mail -> Enable SpamAssassin Spam Box: OFF
WHM -> Tweak Settings -> Mail -> Enable SpamAssassin spam filter: ON
WHM -> Exim Configuration Editor -> SpamAssassin Options -> SpamAssassin: Forced Global ON: ON

2. Go into WHM - > Exim Configuration Editor -> Advanced Editor
( Be Careful)

About halfway down right after:

Code:
#spam_filter:
#  driver = forwardfile
#  file = /etc/spam.filter
#  no_check_local_user
#  no_verify
#  filter
#  allow_system_actions
you will see a textarea box that will allow you to input text.
Here you will need to create a new Filter. Here is mine and should work for most.

Code:
#
#  CUSTOM - Account level filtering for everything but the main account
#

custom_central_filter:
    driver = redirect
    allow_filter
    no_check_local_user
    file = /etc/cpanel_exim_system_filter_custom
    directory_transport = address_directory
    file_transport = address_file
    domains = +user_domains
    pipe_transport = virtual_address_pipe
    reply_transport = address_reply
    router_home_directory = ${extract{5}{:}{${lookup passwd{${lookup{$domain}lsearch*{/etc/userdomains}{$value}}}{$value}}}}
    user = "${lookup{$domain}lsearch* {/etc/userdomains}{$value}}"
    allow_fail
    no_verify
Save

3. Now you need to create a custom filter file that matches the one shown above.
/etc/cpanel_exim_system_filter_custom

Contents:

Code:
# Exim filter

if not first_delivery and error_message then finish endif

#Spam
if $h_X-Spam-Status: contains "Yes" then
  if "${if exists {$home/mail/$domain/$local_part/.Junk}{yes}{no}}" contains "yes"
   then
    save "$home/mail/$domain/$local_part/.Junk/" 660
    finish
   endif
endif
Note:
# Exim filter (is required)

This will now Redirect all mail marked as Spam by Spamassassin to the users "Junk" folder.
this is now affecting all accounts. If the Junk folder does not exist it will attempt to create it.
If the user is not already subscribed to this folder then they will not see the email.
Although Dovecot, Courier, Squirrel Mail, RoundCube, Outlook, and Thunderbird all seem to create it by default.

This does still allow each user to specify the spam rating before it is marked as spam. The default is 5.

There is only one issue with this and it is that this filter runs first before all other user defined filters.
If someone has a solution to making this run after all user defined filters then please let me know.

Thanks
 
Last edited:

wired420

Active Member
Nov 17, 2005
35
2
158
I did find the location of the "spam" folder.

It's in /etc/exim.conf

Code:
directory = "${extract{5}{:}{${lookup passwd{$local_part}{$value}}}}/mail/.spam"
However, this will get overwriten on each Update. Also this requires that each client set the Spam Box to ON.

So I found a better solution:
( I did want this to be global so I didn't have to run it for each user)
( WHM 11.30.1 (build 4) CENTOS 5.6 x86_64 )

1. Turn OFF "Spam Box" in WHM -> Tweak Settings -> Mail.
This just allows the user to control it, but I wanted it always on and I want to forward to the ".Junk" folder anyways.
WHM -> Tweak Settings -> Mail -> Enable SpamAssassin Spam Box: OFF
WHM -> Tweak Settings -> Mail -> Enable SpamAssassin spam filter: ON
WHM -> Exim Configuration Editor -> SpamAssassin Options -> SpamAssassin: Forced Global ON: ON

2. Go into WHM - > Exim Configuration Editor -> Advanced Editor
( Be Careful)

About halfway down right after:

Code:
#spam_filter:
#  driver = forwardfile
#  file = /etc/spam.filter
#  no_check_local_user
#  no_verify
#  filter
#  allow_system_actions
you will see a textarea box that will allow you to input text.
Here you will need to create a new Filter. Here is mine and should work for most.

Code:
#
#  CUSTOM - Account level filtering for everything but the main account
#

custom_central_filter:
    driver = redirect
    allow_filter
    no_check_local_user
    file = /etc/cpanel_exim_system_filter_custom
    directory_transport = address_directory
    file_transport = address_file
    domains = +user_domains
    pipe_transport = virtual_address_pipe
    reply_transport = address_reply
    router_home_directory = ${extract{5}{:}{${lookup passwd{${lookup{$domain}lsearch*{/etc/userdomains}{$value}}}{$value}}}}
    user = "${lookup{$domain}lsearch* {/etc/userdomains}{$value}}"
    allow_fail
    no_verify
Save

3. Now you need to create a custom filter file that matches the one shown above.
/etc/cpanel_exim_system_filter_custom

Contents:

Code:
# Exim filter

if not first_delivery and error_message then finish endif

#Spam
if $h_X-Spam-Status: contains "Yes" then
  if "${if exists {$home/mail/$domain/$local_part/.Junk}{yes}{no}}" contains "yes"
   then
    save "$home/mail/$domain/$local_part/.Junk/" 660
    finish
   endif
endif
Note:
# Exim filter (is required)

This will now Redirect all mail marked as Spam by Spamassassin to the users "Junk" folder.
this is now affecting all accounts. If the Junk folder does not exist it will attempt to create it.
If the user is not already subscribed to this folder then they will not see the email.
Although Dovecot, Courier, Squirrel Mail, RoundCube, Outlook, and Thunderbird all seem to create it by default.

This does still allow each user to specify the spam rating before it is marked as spam. The default is 5.

There is only one issue with this and it is that this filter runs first before all other user defined filters.
If someone has a solution to making this run after all user defined filters then please let me know.

Thanks
This is one of the most useful posts I've ever found on this forum. I've updated the pipe_transport to take into account CloudLinux + CageFS if anyone else is running CloudLinux and wanted to use this. Should also work with the same code if you aren't running cloudlinux or an account isn't caged. All accounts on our servers are caged so no way to test it. I'd assume it'd work because I just pilfered it out of another filter for virtual users. Was quicker than writing it and why rewrite what's already a few pages down :P

Code:
custom_central_filter:
    driver = redirect
    allow_filter
    no_check_local_user
    file = /etc/cpanel_exim_system_filter_custom
    directory_transport = address_directory
    file_transport = address_file
    domains = +user_domains
    pipe_transport = ${if forall{/bin/cagefs_enter:/usr/sbin/cagefsctl}{exists{$item}}{cagefs_virtual_address_pipe}{${if match{${extract{6}{:}{${lookup passwd{${lookup{$domain}lsearch*{/etc/userdomains}{$value}}}{$value}}}}}{\N(jail|no)shell\N}{jailed_virtual_address_pipe}{virtual_address_pipe}}}}
    reply_transport = address_reply
    router_home_directory = ${extract{5}{:}{${lookup passwd{${lookup{$domain}lsearch*{/etc/userdomains}{$value}}}{$value}}}}
    user = "${lookup{$domain}lsearch* {/etc/userdomains}{$value}}"
    allow_fail
    no_verify

Works like a charm with that update on CloudLinux! I really don't understand why this isn't done in cPanel. It's stupid to have to create a spam filter for EVERY new email address created.
 
Last edited:
  • Like
Reactions: fritolays

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,254
463
Works like a charm with that update on CloudLinux! I really don't understand why this isn't done in cPanel. It's stupid to have to create a spam filter for EVERY new email address created.
Hello :)

Thank you for posting the updated workaround instructions. Feel free to submit a feature request if you would like to see native support for this functionality:

Submit A Feature Request

Thank you.