Automatically Remove Emails After X Amount of Days

bobsthename

Verified User
Joined
Sep 23, 2009
Messages
42
Location
NZ
I was just wondering if it is possible to automatically remove emails from one imap email account after a certain amount of days/weeks/months?
 
Hello,

set a cron task (modify it first to meet you needs):

find /home/userbob/imap/domain.com/info/Maildir/cur -mtime +30 -type f -exec rm -f {} +

before to delete you can run this to list emails:

find /home/userbob/imap/domain.com/info/Maildir/cur -mtime +30 -type f -exec ls -la {} +

to remove emails older than 30 days from inbox of [email protected] of user userbob
 
Last edited:
I tried this, and I can see with du at commandline that the mail folders on disk are <20MB, but in the GUI they still show as >50MB after several days. How come?
 
Good point. But two questions to follow up:
- Which size does DirectAdmin show, compressed or uncompressed?
- The mailbox sizes shown in DirectAdmin are the same as before I ran the purge. Wouldn't that indicate that the purge didn't have any effect?

I also just looked at some individual files in Maildir/new with less and they actually don't look compressed.
 
Wouldn't that indicate that the purge didn't have any effect?

Check your folders visually. That's the simplest way to see how it works. I don't know how you executed the command, and whether or not you replaced words marked in bold with your real data. You might double-check it.

For server-wide check you might run:

Code:
find /home/*/imap/*/*/Maildir/{cur,new} -mtime +30 -type f -exec ls -la {} +

for printing a list of files of emails older than 30 days in a console. If you see non-empty results then you should really check command you use.

For deleting files server-wide:

Code:
find /home/*/imap/*/*/Maildir/{cur,new} -mtime +30 -type f -exec rm -f {} +
 
Back
Top