[Dovecot] replacement for IMAP_EMPTYTRASH=Trash:7
Benjamin R. Haskell
dovecot at benizi.com
Fri Feb 8 19:11:23 EET 2008
On Fri, 8 Feb 2008, Ed W wrote:
> Hi
>
>> Therefore, i wrote a script that dives into the user's directories and
>> their maildirs. It looks like this
>
> Just for reference I actually read the find manual one evening and figured
> out the syntax (wahey!), then 10 mins later had forgotten it all again...
>
> However, in the intervening mins I wrote this little script (watch out for
> line breaks, find command should all be on one line). The -ls just means
> that I can see it working and for debugging it means that at least you can
> spot if it's gone off the rails... Remove the -ls and stick it in cron when
> you are happy (obviously fix the start dir in this script though....)
>
> #!/bin/bash
> find . \( -wholename "*/.Spam/cur/*" -type f -mtime +7 -delete -ls \) , \(
> -wholename "*/.Spam/new/*" -type f -mtime +7 -delete -ls \) , \( -wholename
> "*/.Trash/cur/*" -type f -delete -ls \) , \( -wholename "*/.Trash/new/*"
> -type f -delete -ls \)
>
> I think the issue with mtime is that it gets reset when users open a folder
> and mail moves from /new to /cur ?
>
> Incidently here is a recipe to clean up large Sent Items folders... Use with
> caution... It demonstrates finding files based on size, date and also
> excluding one folder from being pruned...
>
> find . \( -wholename "*/.Sent\ Items/cur/*" \! -wholename
> "*/exclude_this_user/*" -type f -mtime +30 -size +5M -ls -delete \) , \(
> -wholename "*/.Sent\ Items/new/*" \! -wholename "*/exclude_this_user/*" -type
> f -mtime +30 -size +5M -ls -delete \)
>
For what it's worth, here's the cron script I run nightly: (No capital
'o's, they're zeros. That's to deal with spaces in filenames.)
# go through all users' Maildirs and delete deleted messages
# (*:?,*T*) - T is for Trash (Maildir flag)
# that are at least 30 days old
getent passwd | cut -d: -f6 | sort | uniq \
| perl -l0nwe '$_.="/Maildir"; print if -d' \
| xargs -0 -iI find I -type d -name cur -print0 \
| xargs -0 -iI find I -type f -name '*:?,*T*' -mtime +30 -delete
# delete all messages in Spam/Junk folders that are at least 14 days old
# (Note: doesn't look in '/new' -- procmail drops things directly to '/cur')
getent passwd | cut -d: -f6 | sort | uniq \
| perl -l0nwe '$_.="/Maildir"; print if -d' \
| xargs -0 -iI find I -type d \( -name '.Spam*' -o -name '.Junk*' \) -print0 \
| xargs -0 -iI find I -type d -name cur -print0 \
| xargs -0 -iI find I -type f -mtime +14 -delete
Best,
Ben
More information about the dovecot
mailing list