Koozali.org: home of the SME Server

how to automatically empty trash in all mail accounts?

Offline lightman

  • ***
  • 75
  • +0/-0
how to automatically empty trash in all mail accounts?
« on: March 09, 2011, 09:32:02 PM »
Hello.
I was looking for a way to automatically empty trash in all accounts.
we have around 100 users that just forget to do it and the size of the mails increases a lot!.

I have seen an old post (didn't reply there because it's 3 year old), How to automatically delete spam  it is not exactly what I need but very close :D

Can anyone please give me a hint of how to do that?, I don't want a free easy solution, just an explanation of how, so I can write my own script :), well, what ever you can tell me will help for sure :)

thank you A LOT! in advance   :D
Leo

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Re: how to automatically empty trash in all mail accounts?
« Reply #1 on: March 10, 2011, 07:17:13 PM »
Why not configure all your users mail clients to purge trash on exit? What mail clients are you using?
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)

Offline lightman

  • ***
  • 75
  • +0/-0
Re: how to automatically empty trash in all mail accounts?
« Reply #2 on: March 11, 2011, 03:06:32 AM »
Why not configure all your users mail clients to purge trash on exit? What mail clients are you using?

Hi!, thank you for answer.
Most of my users (about 90%) use only webmail.

if we had figure this out in the beginning, it would have been easy, but now, with +200 webmail users, have to get in and configure in every user, will be almost impossible! :(

Even a way to purge all trash of all users at one given time, done by the admin, will be enough, but just can't figure it out how to do it.

thank you
light

Offline elmarconi

  • ***
  • 139
  • +0/-0
Re: how to automatically empty trash in all mail accounts?
« Reply #3 on: March 13, 2011, 05:30:13 PM »
You might wanna take a look at /etc/e-smith/events/actions/purge-junkmail-folders

This is called from /etc/crond.d

To do this nicely use the template system.



...

Offline Knuddi

  • *
  • 540
  • +0/-0
    • http://www.scanmailx.com
Re: how to automatically empty trash in all mail accounts?
« Reply #4 on: March 13, 2011, 10:04:38 PM »
The challenge here is that the deleted emails have not been moved to a specific folder as junkmail. The filename has just been changed so that it has a "T" for trashed in the end.

So you want to make a script that finds the "T" files that are older than Y days.

Content that is more than 30 days old within the .Trash directories made by Thunderbird can be cleaned like this (at own risk...)

Code: [Select]
find /home/e-smith/files/users/ -regex '.*/\.\(Trash\|Junk\)\(/.*\)?\/\(cur\|new\)/.*' -type f  -ctime +30 -delete
Dovecot:
http://cr.yp.to/proto/maildir.html


« Last Edit: March 13, 2011, 10:49:51 PM by Knuddi »

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Re: how to automatically empty trash in all mail accounts?
« Reply #5 on: March 15, 2011, 10:14:41 AM »
The challenge here is that the deleted emails have not been moved to a specific folder as junkmail. The filename has just been changed so that it has a "T" for trashed in the end.
Then this won't do you any good:

Code: [Select]
find /home/e-smith/files/users/ -regex '.*/\.\(Trash\|Junk\)\(/.*\)?\/\(cur\|new\)/.*' -type f  -ctime +30 -delete

If deleted files have a T at the end and are not in specific folders you can do something like this in a script:

Code: [Select]
#!/bin/sh

# Location of the Maildir folder(s)
MAILDIR=/home/e-smith/files/users/*/Maildir/

# Age of the files in days
RETENTION_TIME=30

# Delete them (yes) or only list them (no)
DELETE=no

find $MAILDIR -type f -name *T -ctime $RETENTION_TIME $(if [ "$DELETE" == "yes" ]; then echo " -delete"; fi)

Remark:Since you stated you are using webmail, which is backed by a MySQL database for it's data I am not sure if this will work to full satisfaction as I am not sure which data is stored in the MySQL database and what is read from the filesystem. If the state of e-mails is also stored, it might be that the interface is showing mail that might not be there after you have run the script.
« Last Edit: March 15, 2011, 10:21:29 AM by cactus »
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)