Move junk mail to a folder instead of deleting

Discussion in 'Tips/Tricks/Mods' started by grant, Sep 22, 2007.

  1. grant

    grant New Member

    With SpamAssassin turned on, the default spam strategy options let you either leave junk mail in your inbox (accept), or delete it completely (discard).

    I hate having my mail deleted for me. I rarely have false positives, but I'd rather see the junk mail I'm getting to be able to make sure.

    These changes allow you to change the behavior to either:
    • Leave it in your inbox
    • Move it to the Junk folder

    This guide also assumes that your clients are using IMAP to access their mail, or at least have access to a web client that is using IMAP, so they can see the Junk folder. It also assumes that you are using Maildirs.


    First change the behavior of spamassassin. Edit /root/ispconfig/isp/conf/spamassassin.rc.master.
    Find the line:
    PHP:
    {SPAM_COMMENT}/dev/null
    Change it to:
    PHP:
    {SPAM_COMMENT}.Junk/

    Now make sure that the Junk folders are created automatically. We can't move mail to a folder that doesn't exist. Edit /root/ispconfig/scripts/lib/classes/ispconfig_procmail.lib.php.
    Find the line (around 107) that reads:
    PHP:
    if(!is_dir($web_path."/user/".$user_username."/Maildir")) $mod->log->caselog("maildirmake ".$web_path."/user/".$user_username."/Maildir &> /dev/null""maildirmake ".$web_path."/user/".$user_username."/Maildir &> /dev/null"__LINE__);
    Below it add:

    PHP:
    # Create Junk, Send, Trash folders
             
    if(!is_dir($web_path."/user/".$user_username."/Maildir/.Junk")) $mod->log->caselog("maildirmake -f Junk ".$web_path."/user/".$user_username."/Maildir &> /dev/null""maildirmake -f Junk ".$web_path."/user/".$user_username."/Maildir &> /dev/null"__LINE__);
            if(!
    is_dir($web_path."/user/".$user_username."/Maildir/.Sent")) $mod->log->caselog("maildirmake -f Sent ".$web_path."/user/".$user_username."/Maildir &> /dev/null""maildirmake -f Send ".$web_path."/user/".$user_username."/Maildir &> /dev/null"__LINE__);
            if(!
    is_dir($web_path."/user/".$user_username."/Maildir/.Trash")) $mod->log->caselog("maildirmake -f Trash ".$web_path."/user/".$user_username."/Maildir &> /dev/null""maildirmake -f Trash ".$web_path."/user/".$user_username."/Maildir &> /dev/null"__LINE__);
    (The forums are doing some weird wrapping on that code. The 3 if statements should be on 1 line each.)

    Edit /home/admispconfig/ispconfig/web/isp_manager/lib/lang/en.lng
    Find the lines:
    PHP:
    $wb["accept"] = 'accept';
    $wb["discard"] = 'discard';
    Change them to:
    PHP:
    $wb["accept"] = 'Leave in Inbox';
    $wb["discard"] = 'Move to Junk';
    Edit /home/admispconfig/ispconfig/web/mailuser/lib/lang/en.lng
    Find the lines:
    PHP:
    $wb["txt_accept"] = "accept";
    $wb["txt_discard"] = "discard";
    Change them to:
    PHP:
    $wb["txt_accept"] = "Leave in Inbox";
    $wb["txt_discard"] = "Move to Junk";
    Now make a small change to in ISPConfig to make it refresh all your users. It should automatically create Junk, Sent and Trash folders for everyone. When then change their spam settings, they will now see the options "Leave in Inbox" and "Move to Junk" instead of accept and discard.
     
  2. madmucho

    madmucho Member

    That is exaclty what i looking for :) thanks :)

    Any idea how to add this in listbox and extend default configuration?
    accept
    discard
    move to junk ?
     
  3. chancer

    chancer New Member

    They do when you copy and paste them into a text editor - but they do wrap because they are very long.

    Very useful mod, thanks. Exactly what I was alluding to in my original thread.
     
  4. ramansivia

    ramansivia New Member

    Re Not Working

    Hello, I have followed Step By Step

    But i still have no luck with moving spam to junk folder, Even "Junk" folder is not created on webmail,

    in Admin page i do see , it is changed from Accpect lo leaveg in inbox and move to junk , but when i make it move junk that spam message jst get deleted nothing comes in Junk folder even if i create Junk folder by my self

    what could be worng ?

    I really like the idea , and i would like it to work i'm using 2.18 of ispconfig and i just followed setting that was put by ispconfig site to install the ispconfig

    thanks
     
  5. jbravo

    jbravo Member

    Works like a charm (ISPConfig 2.2.18, squirreloutlook 1.4.8)! Had to subscribe new folders in squirreloutlook user interface after login and setup them (deleted mails -> trash, sent mails -> sent).

    Big thanks!
     
  6. ramansivia

    ramansivia New Member

    JUNK Folder No Luck

    Thanks for reply ,

    I do see sent, trash, inbox, and i see its in user infer.. but there is no option for junk folder,

    1) when i make new email account, Junk folder is not created

    2) when i choice option to move spam to junk folder, rather then redirect mail to junk it just delete it message, (as it should do according to ISP setup, either mail in inbox or delete it )

    Is there something wrong in my setup , or i'm missing something
    thanks

    Raman:confused:
     
  7. jbravo

    jbravo Member

    They don't appear on webmail at the beginning (i'm using sqiuirrel). Check via shell login what's inside user's Maildir.

    I'm missing someting? There should be choice to leave in inbox or move to junk - not move/redirect.

    Also check twice steps described in posts above and make edited files backup first;)
     
  8. MTvermoes

    MTvermoes New Member

    Auto Remove Junk Older than 14 Days

    I have implemented the move spam to Junk, and ran into a problem :
    Users getting their mail with pop3 don't see all the spam in .Junk Folder.
    The size of the junk folder will soon exeed the users disk quota.
    So i found a little script on the net, and modified it a bit for use with ISPConfig.
    It will remove Messages older than 14 days from users .Junk folder.
    I run it daily via cron.

    cat /etc/cron.daily/purge.junk
    Code:
    #!/bin/sh
    
    HOURS=$((2 * 24 * 7))
    
    for domain in /var/www/*
    do
            if [ -d "$domain"/user ]
                    then
                            cd $domain/user
                            for user in *
                            do
                                    if [ -d "$user/Maildir/.Junk" ]
                                    then
                                            tmpwatch -m $HOURS $user/Maildir/.Junk/{cur,new}
                                    fi
                            done
                            cd /var/www
            fi
    done
    
    Edit(11 Jan 2008):

    You might want to add :
    /etc/init.d/dovecot restart
    to the script, to make dovecot rebuild message indexes.



    /Mark
     
    Last edited: Jan 11, 2008
  9. grafzahl

    grafzahl New Member

    Hello,

    unfortunately there are no tmpwatch rpm for SuSe Linux and tmpwatch sources are hard to find.

    My way for SuSe 10.1 is to replace
    Code:
    tmpwatch -m $HOURS $user/Maildir/.Junk/{cur,new}
    with
    Code:
    find $user/Maildir/.Spam/cur -mtime +30 -exec rm {} \;
    find $user/Maildir/.Spam/new -mtime +30 -exec rm {} \;
    The "+30" in code mean 30 days. So you don´t need variable HOURS.

    Greets from Germany
    Grafzahl
     
  10. MTvermoes

    MTvermoes New Member

    To install tmpwatch from source :
    Code:
    cd /usr/src
    wget http://linux.bononline.nl/linux/tmpwatch/src/tmpwatch-2.9.0.tar.gz
    tar xvzf tmpwatch-2.9.0.tar.gz
    cd tmpwatch-2.9.0
    make
    make install
    
    This will install tmpwatch with Prefix /usr/local

    /Mark
     
  11. apex

    apex New Member

    Has anyone tried this with UebiMiau?

    I've followed the steps myself. If I list the contents of the folder via the shell I can see .Junk, however I cannot see it while logged into UebiMiau.
     
  12. deathshadow

    deathshadow New Member

    On Debian tmpreaper should be used instead of tmpwatch since tmpreaper is in the repositories (attempting to apt-get tmpwatch will warn and throw, mentioning tmpreaper)...

    Apart from that this appears to work GREAT... and is a WAY simpler solution to the problem than I've been seeing elsewhere. Spam moved to .Junk, purging of .Junk - server side so no hassles regardless of client software.

    Plugs a functionality hole as I was thinking on using roundcube - but the lack of message filtering kept sending me back to SquirrelMail.
     
  13. b00gz

    b00gz New Member

    First off I want to say that this posting is amazing! ... With that said I am using Squirrel-Outlook and am unable to figure out how to auto-subscribe .Junk folder. Does anyone have a good solution for this?
     
  14. deathshadow

    deathshadow New Member

    Addendum

    In walking a buddy through setting this up on his server (I pointed him here, he got lost), we had real issues getting the purge script to run despite being (I thought) the same setup (Debian Etch perfect with ISPConfig as per this site) as my own server.

    The script was throwing couldn't find directory errors and wouldn't work until I filled out the directory values the whole way.

    So for debian etch, that should read (this is set to 3 days, the admin account for my buddies server sees 1500 spam a day):

    Code:
    #!/bin/sh
    
    hours=$((24*3))
    
    for domain in /var/www/*
    do
      if [ -d "$domain"/user ]
      then
        for user in *
        do
          if [ -d "$domain/user/$user/Maildir/.Junk" ]
          then
            # change tmpreaper to tmpwatch for some distros
            tmpreaper -m $hours $domain/user/$user/Maildir/.Junk/{cur,new}
          fi
        done
      fi
    done
    Oh, and a little 'tip' for nubes that isn't mentioned here (came up while instructing my buddy, who's greener than moldy cheese) - chmod 775 this purge.junk file or cron won't execute it. With *nix heads this is one of those 'assumed' things that really should be mentioned so people new to bash and *nix have a clue.

    I switched my own server to this file to verify it worked there too. No difference either way between my previous and this one - though I'm going with this one since it seems to work better across multiple distros (and doesn't burn time executing chdir)
     
  15. hairydog2

    hairydog2 Member

    That's really helpful, but I'd like to offer three options:

    1. Allow it into the mailbox
    2. Move it to the junk folder
    3. Delete it immediately

    Would this be easy to add as an option?
     
  16. mumbly

    mumbly Member

    It works with the tutorial on Howtoforge.com (http://www.howtoforge.com/how-to-add-a-move-to-spam-option-to-your-ispconfig-installation).
    BUT it seems to work on for account that is admin with ISPConfig 2.2.25, roundcubemail and Hardy heron Ubuntu Gnu/Linux server.
    I've tried everything i could : no way ! :(
    In fact, for the account that is selected as "admin" of a domain, spam go all in the Junk forlder.
    But for the other mail accounts of this same domain, spam go in the receive box as before.
    Of course, i've selected the "move" option in the ispconfig panel ... but no luck ...

    UPDATE :
    Parse error: syntax error, unexpected ',' in /root/ispconfig/scripts/lib/classes/ispconfig_procmail.lib.php on line 419

    UPDATE 2 :
    Several mails go now in my server user account...

    "You have new mail.
    $ mail
    Mail version 8.1.2 01/15/2001. Type ? for help.
    "/var/mail/olivier": 34 messages 34 new ..."
     
    Last edited: Sep 25, 2008
  17. JeGr

    JeGr Member

    Did you use the patch with users created before patching? Did you create mailboxes afterwards and check these? It seems to me, that the users you select the new "move" option on, don't have a junk folder. That is the patch on the ispconfig_procmail.lib.php, to create all needed folders for future users. If you have users before who have NO junk folder, it doesn't get created out of the blue. I would advide to set roundcube to create those folders on first connection per default (I think Hans already set the roundcube package up that way) and log into that users via RC to create those missing boxes.
    Another possibility would be to create them by hand but watch your permissions closely then!
     
  18. mumbly

    mumbly Member

    Thanx Grey !
    But i've found a simpler solution by just editing the spamassassin.rc file for my user and telling procmail to not put the spam to /dev/null but to .Junk/ folder.
    That's very simple but it works like a charm ... and this is what i was looking for ! :)
    Thanx for all !
     
  19. JeGr

    JeGr Member

    That, too, only works if and only IF a Junk folder exists, what is - without the modifications of my howto - not the case if you create a new user out of the box. That user needs to login first with Roundcube or an IMAP Client to create those folders, if you don't do that for him. If that folder doesn't exist, that will result in further problems.

    With that solution in this thread you don't have to edit that much files, but it's still important, that the folders (.Junk, .Trash) exist.
     
    Last edited: Sep 26, 2008
  20. mumbly

    mumbly Member

    Ok !
    Thanx again anyway ! ;)
     

Share This Page