HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Tips/Tricks/Mods (http://www.howtoforge.com/forums/forumdisplay.php?f=19)
-   -   Move junk mail to a folder instead of deleting (http://www.howtoforge.com/forums/showthread.php?t=15704)

grant 22nd September 2007 18:25

Move junk mail to a folder instead of deleting
 
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 Code:

{SPAM_COMMENT}/dev/null 

Change it to:
PHP Code:

{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 Code:

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 Code:

# 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 Code:

$wb["accept"] = 'accept';
$wb["discard"] = 'discard'

Change them to:
PHP Code:

$wb["accept"] = 'Leave in Inbox';
$wb["discard"] = 'Move to Junk'

Edit /home/admispconfig/ispconfig/web/mailuser/lib/lang/en.lng
Find the lines:
PHP Code:

$wb["txt_accept"] = "accept";
$wb["txt_discard"] = "discard"

Change them to:
PHP Code:

$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.

madmucho 13th October 2007 23:30

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 ?

chancer 17th October 2007 18:34

Quote:

(The forums are doing some weird wrapping on that code. The 3 if statements should be on 1 line each.)
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.

ramansivia 19th November 2007 05:48

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

jbravo 19th November 2007 11:56

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!

ramansivia 20th November 2007 05:02

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:

jbravo 21st November 2007 19:38

Quote:

Originally Posted by ramansivia
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

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

Quote:

Originally Posted by ramansivia
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:

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;)

MTvermoes 7th January 2008 10:01

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

grafzahl 17th January 2008 19:49

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

MTvermoes 20th January 2008 17:43

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


All times are GMT +2. The time now is 12:20.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.