Script: delete spam older than x days

kke

Verified User
Joined
Apr 4, 2006
Messages
207
Location
Thailand
Shell script to delete spam in the users spam folder (.INBOX.spam) in the Maildir system that older than n days (default 30 days)

Put it in cron (weekly should be ok) eg.
10 0 * * 0 root scriptpath/cleanspam.sh

edit the script and set
DAYS=n
logfile=/var/log/whatyouneed

Tested on
FreeBSD 5.4 / DA / Spam Assassin / Dovecot (Maildir)

Download here http://www.directadmin.com/forum/attachment.php?s=&postid=89814
 
Last edited:
Thank you...

Tested on CentOS - works fine. I upped the time to 90 days, just cause it scared the bejeezus outta me to play with clients email, but the script does what it's intended to.
 
Been thinking/working on something very similiar.

What I want is rather then deleting the messages out of spam folder older then say 30 days I want them moved after ~14 days too:

/drive2/arch_spam

Folder and each message file name appended with user_domain.com. Then I have another script that will delete anything in this folder older then say 90 days. That way there out of the users quotta but not gone for good quite yet.

Nice script for deleting files older then X days out of given directory is here:

http://forum.ensim.com/archive/index.php?t-11345.html

Don't suppose you could modify to work that way? ;<)

Next project on the burner is script run daily that emails them a report of all the new messages in there SPAM folder that have arrived in last 24 hours.

Ugh, if only I had more time.

Matthew
 
Major Bug Fix 25 Dec 2006

Duplicate path in script, no spam file will be deleted only log file generated.

Please replace with this attachment.
 

Attachments

  • cleanspam.sh.gz
    937 bytes · Views: 631
Is this is correct output of the logfile ?

-------------------------------------------------

CHECKING USER : admin

-------------------------------------------------

CHECKING USER: goliath

-------------------------------------------------


etc etc ?

And is it possible to do the same trick to the folder .INBOX.trash ?

thanks
 
Last edited:
Goliath said:
Is this is correct output of the logfile ?

-------------------------------------------------

CHECKING USER : admin

-------------------------------------------------

CHECKING USER: goliath

-------------------------------------------------


etc etc ?

And is it possible to do the same trick to the folder .INBOX.trash ?

thanks

This is showing that there are no spam folder for that user

If spam folder existing it's will show 2 lines for that user


CHECKING USER : admin

CHECKING FOR : admin

and if there are some spam deleted it's will also keep in log

CHECKING USER : admin

CHECKING FOR : admin

DELETE : /home/admin/Maildir/.INBOX.spam/new/1157220775.668.mbox :Return-path: <[email protected]>
DELETE : /home/admin/Maildir/.INBOX.spam/new/1157220776.668.mbox :Return-path: <[email protected]>


1. Please make sure that you are using MAILDIR system (Have converted to Dovecot)
2. Spamassassin has been enabled
3. Some user may not have spam folder, this should not the problem, because we checking only user that have spam folder
4. If you see some DELETE: line in log file then the script is working fine.

and yes, you can do the same trick for .INBOX.trash
 
Back
Top