Koozali.org: home of the SME Server

Legacy Forums => Experienced User Forum => Topic started by: Knuddi on July 12, 2004, 12:15:01 PM

Title: Automatic deletion of old spam emails in Junkmail folder
Post by: Knuddi on July 12, 2004, 12:15:01 PM
All,

I have now put a small perl script together that can delete older emails stored in the junkmail IMAP folder. This is the location where SpamAssassin places emails identified as spam. The script deletes all emails older than 20 days.

Howto Install:

# cd /root
# wget http://sme.swerts-knudsen.dk/downloads/SpamAssassin/delete_junkmail.pl
# install 755 /etc/cron.daily

Within the script you can specify whether you want a daily report or not. The script can also be disabled if needed.

Rgds,
Jesper
Title: Automatic deletion of old spam emails in Junkmail folder
Post by: Knuddi on July 12, 2004, 12:30:14 PM
A minor addition and correction.

Install command was wrong:

# install -m 0755 delete_junkmail.pl /etc/cron.daily/

Also this script only works on SME 6.0 and 6.0.1

Rgds,
Jesper
Title: Automatic deletion of old spam emails in Junkmail folder
Post by: Anonymous on July 12, 2004, 05:17:45 PM
Why can you only use this script on 6.0/6.0.1?

I've had a look through the code and unless I'm missing some thing it looks to run on earlier versions.

P.S. This looks like 10 days to me, not the previously mentioned 20!
Code: [Select]
$days_to_keep   = 10; #How many days to keep junkmail
Title: Automatic deletion of old spam emails in Junkmail folder
Post by: Knuddi on July 12, 2004, 08:07:34 PM
The script can only be used on 6.0x as the junkmail folder is located a slight different place on 5.6 (as far as I recall). On 5.6 the junkmail folder is not preceeded with ";" but that can obviously easily be changed in the script. If anyone can confirm that I recall right I can release that as well.

You are right about the 10 days vs. 20 - that was my setting when I tested but I decided to change it last minute.

Rgds,
Jesper
Title: Automatic deletion of old spam emails in Junkmail folder
Post by: genzil on July 12, 2004, 08:26:31 PM
Hi, on my 5.6 box the junkmail folder can be found at /home/e-smith/files/users/$USER/Mail/junkmail/{cur,new}

I'm interested in running this scrip on this box for a few weeks  (until I upgrade to 6.0.1 :-))

Thanks

Craig
Title: Automatic deletion of old spam emails in Junkmail folder
Post by: Knuddi on July 12, 2004, 09:19:22 PM
Hi Craig,

I have now made a 5.6 variant that you can try out.

http://sme.swerts-knudsen.dk/downloads/SpamAssassin/delete_junkmail56.pl

Please let me know whether it works as you expect. By the way have a look at the FAQ on my site if you want to change some of the parameters:

http://sme.swerts-knudsen.dk/howtos/howto_16.htm


Rgds,
Jesper
Title: Automatic deletion of old spam emails in Junkmail folder
Post by: genzil on July 13, 2004, 12:20:52 PM
Hi Jesper,
Thanks for that, I'll give it a go and let you know how I get on.
Title: Automatic deletion of old spam emails in Junkmail folder
Post by: genzil on July 13, 2004, 12:31:54 PM
I couldn't wait until tonight so I ran it manually and got the following error message:

Couldn't read directory /home/e-smith/files/users/talis/Mail/junkmail/new at ./delete_junkmail.pl line 58, <ORIGINAL> line 117.

That user doesn't have any folders at all as it simply used to give a friend ftp access.
I created the folders needed and it worked like a charm but prehaps some checking of dirs is needed to see if they exist.
Title: Re: Automatic deletion of old spam emails in Junkmail folder
Post by: k_graham on July 15, 2004, 08:21:29 AM
Quote from: "Knuddi"
All,

I have now put a small perl script together that can delete older emails stored in the junkmail IMAP folder. This is the location where SpamAssassin places emails identified as spam. The script deletes all emails older than 20 days.

Howto Install:

# cd /root
# wget http://sme.swerts-knudsen.dk/downloads/SpamAssassin/delete_junkmail.pl
# install 755 /etc/cron.daily

Within the script you can specify whether you want a daily report or not. The script can also be disabled if needed.

Rgds,
Jesper


Does this also purge the deleted mail otherwise its still there taking up space. I notice if users of a IMAP email system set the system to not show deleted messages then they can build for weeks and months. Not just in the spam folder but through the whole email system. The ideal would be a daily cron job to purge all deleted messages that have been deleted over 20 or 30 days ago.

Ken
Title: Automatic deletion of old spam emails in Junkmail folder
Post by: Jesper Knudsen on July 15, 2004, 08:58:47 AM
The script only deletes email in the junkmail folder and ALSO those which have been marked "deleted" in an IMAP environment.

It does not look in all folders and determine which emails have been deleted but not purged.

Rgds.
Jesper
Title: Contrib Feedback: Automatic deletion of old spam emails in J
Post by: wellsi on July 18, 2004, 08:52:56 PM
(Added to the How To Classification, and feedback pointed to this thread)

Automatic deletion of old spam emails in Junkmail folder

A small perl script which deletes all users emails stored in the junkmail IMAP folder if they are older than $days_to_keep (default 10). Very useful in combination with SpamAssassin. The script only deletes email in the junkmail folder and ALSO those which have been marked "deleted" in an IMAP environment.

Author(s): Jesper Knudsen at http://sme.swerts-knudsen.dk
Contributor(s): Abe Loveless
License: Unknown

How To Link: http://no.longer.valid/phpwiki/index.php/Automatic%20deletion%20of%20old%20spam%20emails
Topic Page: Spam (http://no.longer.valid/phpwiki/index.php/Spam)

This thread is for feedback specificaly related to this How To & Contrib.
Reports of success are welcome, as well as any problems and suggested improvements.
Title: Automatic deletion of old spam emails in Junkmail folder
Post by: mbachmann on July 19, 2004, 09:38:13 AM
Only success, thanks Jesper. Deletes and sents a nice junkmail deletion report at 4:00 h at night.
Title: Automatic deletion of old spam emails in Junkmail folder
Post by: wingman on July 19, 2004, 05:56:19 PM
Am I just too stupid to install this?

When I try the command "install 755 /etc/cron.daily" I get the following message:
install: cannot stat 755': No such file or directory

What am I doing wrong?
Thanks
Title: Automatic deletion of old spam emails in Junkmail folder
Post by: Knuddi on July 21, 2004, 09:24:37 AM
I posted a wrong install the first time - sorry. This is the right way for a 6.0.x server.

# cd /root
# wget http://sme.swerts-knudsen.dk/downloads/SpamAssassin/delete_junkmail.pl
# install -m 0755 delete_junkmail.pl /etc/cron.daily/

on SME 5.6 this is the right way:

# cd /root
# wget http://sme.swerts-knudsen.dk/downloads/SpamAssassin/delete_junkmail56.pl
# install -m 0755 delete_junkmail56.pl /etc/cron.daily/

Rgds,
Jesper Knudsen
Title: Automatic deletion of old spam emails in Junkmail folder
Post by: wingman on July 21, 2004, 02:29:04 PM
Thanks so much, Jesper!
That worked great.

Joe Burkhead