The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Can you change the Spamassassin Spam Box folder

Discussion in 'E-mail Discussions' started by spadmin, Jul 31, 2011.

  1. spadmin

    spadmin Member

    Joined:
    Jul 31, 2011
    Messages:
    6
    Likes Received:
    2
    Trophy Points:
    1
    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?
     
  2. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    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 admin@domain.com. You'd want to enable a filter and then cat the file to see how the filter file looks typically at that location.
     
  3. spadmin

    spadmin Member

    Joined:
    Jul 31, 2011
    Messages:
    6
    Likes Received:
    2
    Trophy Points:
    1
    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
     
    #3 spadmin, Aug 3, 2011
    Last edited: Aug 3, 2011
    wired420 and Júlio César like this.
  4. wired420

    wired420 Active Member

    Joined:
    Nov 17, 2005
    Messages:
    34
    Likes Received:
    1
    Trophy Points:
    8
    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.
     
    #4 wired420, Mar 8, 2016
    Last edited: Mar 8, 2016
  5. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
Loading...

Share This Page