Go Back   cPanel Forums > cPanel® and WHM® (for Linux® and FreeBSD® Servers) > cPanel and WHM Discussions

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-14-2009, 09:53 AM
Registered User
 
Join Date: Feb 2004
Location: Montreal
Posts: 62
ramystyle
Arrow how to auto delete all emails older than 2 years (cpanel)? Any scripts?

Hello,

I remember there used to be an Email Aging option in cPanel that is no longer available. I'm looking for something similar that I can apply to all accounts.

Basically, I would like to be able to delete all emails on the server that are older than 2 years.

Any scripts or way of doing this ?

Thank you.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 06-14-2009, 12:37 PM
Spiral's Avatar
Registered User
 
Join Date: Jun 2005
Location: Area 51
Posts: 1,479
Spiral is on a distinguished road
Lightbulb

Quote:
Originally Posted by ramystyle View Post
Basically, I would like to be able to delete all emails on the server that are older than 2 years.

Any scripts or way of doing this ?
You can simply run a find against all the standard mail folders
for mail that is older than two years:
Code:
 find -P /home/*/mail/*/*/cur -mtime '+729'
 find -P /home/*/mail/*/*/new -mtime '+729'
The above will give you a list of all the mail files older than two years
and you can either pipe that into 'xargs' for a very quick and dirty way
of doing that pipe into a file and then have a script parse the file to
do whatever you would like. Here is a very basic example:

Code:
#!/bin/bash
IFS="$"

cd /home

find -P /home/*/mail/*/*/* -mindepth 1 -maxdepth 1 -mtime '+729' | while read OLDMAIL; do
  echo "Now deleting ${OLDMAIL} ..."
  rm -f "${OLDMAIL}"
done
(Incidentally the 729 is the number of days old the file must be greater)

You could delete the "echo" line and add this basic code to a cronjob
and have your server auto delete all mail older than 2 years or
whatever length of time that you want.

Last edited by Spiral; 06-14-2009 at 12:46 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to delete all mails on server older than X years.. ramystyle cPanel and WHM Discussions 1 04-07-2008 03:29 AM
Forward emails and auto delete from inbox. lazydayz Mail 4 12-18-2007 02:07 PM
how to auto reject and delete emails like this? roby2k cPanel and WHM Discussions 5 02-07-2007 08:59 AM
Spamassassin Auto Delete Spam Emails cheemin cPanel and WHM Discussions 3 09-01-2006 12:15 AM
Delete emails from spam box older than x days Netmaking cPanel and WHM Discussions 4 12-02-2004 09:05 AM


All times are GMT -5. The time now is 04:49 PM.


Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© cPanel Inc