> -----Original Message-----
> From: Tom Collins [mailto:t...@tomlogic.com] 
> Sent: November-12-12 1:51 PM
> To: qmailadmin@inter7.com
> Subject: Re: [qmailadmin] [SPAM] Auto-empty trash items older 
> then a certain age
> 
> Just want to throw out there that different email clients 
> will use different names for their deleted items.
> 
> I'm using a cron job to clean up the "Trash", "Deleted 
> Messages" and "Deleted Items" folders, including any folder 
> that starts with those strings.  Survey your system and see 
> what variations you find.
> 
> I decided not to share my Perl script, since it uses the file 
> date (Perl's "-M" which returns days between script start 
> time and file modification time), not the date it was moved 
> into the Trash folder.  Hmm.  I just did some quick tests and 
> it looks like I should use -C (days since file change time) 
> to trigger of the timestamp of when the file was moved to the trash.
> 
> So, here's my script.  Interested in feedback.  I have it in 
> my /etc/cron.daily so it runs every night.  The file globs 
> take care of directory hashing for both domains and users.
> 
> I figured this was more efficient than recursing through the 
> domain list, getting a domain's home directory, recursing 
> through the user list and then processing the files.
> 
> -Tom
> 
> #!/usr/bin/perl
> 
> $|++;
> $days = 45;
> 
> @globs = (
>       '*/*/Maildir/.Trash*/{cur,new}',
>       '?/*/*/Maildir/.Trash*/{cur,new}',
>       '*/?/*/Maildir/.Trash*/{cur,new}',
>       '?/*/?/*/Maildir/.Trash*/{cur,new}',
> 
>       '*/*/Maildir/.Deleted\ {Messages,Items}*/{cur,new}',
>       '?/*/*/Maildir/.Deleted\ {Messages,Items}*/{cur,new}',
>       '*/?/*/Maildir/.Deleted\ {Messages,Items}*/{cur,new}',
>       '?/*/?/*/Maildir/.Deleted\ {Messages,Items}*/{cur,new}'
> );
> 
> $c = 0;
> 
> print "Deleting mail in .Trash and .Deleted Messages folders, 
> over $days days old.\n";
> 
> foreach $path (@globs)
> {
>       while ($name = glob ('/home/vpopmail/domains/' . $path))
>       {
>               opendir (D, $name) or print "failed to open $name\n";
>               while ($f = readdir(D))
>               {
>                       # skip non-files
>                       next if (! -f "$name/$f");
>                       $t = -C "$name/$f";
>                       if ($t > $days)
>                       {
>                               unlink "$name/$f";
>                               $c++;
>                       }
>               }
>       }
> }
> 
> print "Deleted $c messages over $days days old\n";

Not sure if you saw some of the responses I got, but apparently if you don't
use the expunge command, your quotas will not update. Someone can correct me
if I misinterpreted this. Ofcourse if you're not using quotas, that won't
matter. Otherwise your script seems to make sense based on my limited
programming knowledge. In my case, I only want to empty the Trash that
Squirrelmail uses for now, since its usually users that forget to purge it
once they delete messages that I'm concerned with to start. In the rare case
that they moved a message there by accident, I'll give it a 90 day window
before its expunged.

Matt


!DSPAM:50a6391133991782415209!

Reply via email to