[Dovecot] replacement for IMAP_EMPTYTRASH=Trash:7
While running dovecot on debian etch using version 1.0.rc15-2etch3, i wonder the following:
If i read the config files correctly, dovecot seems to have no equivalent of courier's IMAP_EMPTYTRASH=Trash:7 setting. Therefore, i wrote a script that dives into the user's directories and their maildirs. It looks like this:
#!/bin/bash
for pad1 in $(ls /home) do if [ -e "/home/$pad1/Maildir/.Prullenbak" ] then find "/home/$pad1/Maildir/.Prullenbak/cur" -mtime +2 -type f -delete find "/home/$pad1/Maildir/.Prullenbak/new" -mtime +2 -type f -delete fi if [ -e "/home/$pad1/Maildir/.Allerlei.Spam" ] then find "/home/$pad1/Maildir/.Allerlei.Spam/cur" -mtime +2 -type f -delete find "/home/$pad1/Maildir/.Allerlei.Spam/new" -mtime +2 -type f -delete fi done
Now, can i just put a script like this in /etc/hourly or do i have to add things like stopping the dovecot deamon (i sure hope not!) in order to prevent file-corruption?
Or has dovecot in the meantime got a config option that does this just like courier does?
Rody
Use mail-expire.
On Feb 7, 2008 5:58 PM, Rody <rody@xs4all.nl> wrote:
While running dovecot on debian etch using version 1.0.rc15-2etch3, i wonder the following:
If i read the config files correctly, dovecot seems to have no equivalent of courier's IMAP_EMPTYTRASH=Trash:7 setting. Therefore, i wrote a script that dives into the user's directories and their maildirs. It looks like this:
#!/bin/bash
for pad1 in $(ls /home) do if [ -e "/home/$pad1/Maildir/.Prullenbak" ] then find "/home/$pad1/Maildir/.Prullenbak/cur" -mtime +2 -type f -delete find "/home/$pad1/Maildir/.Prullenbak/new" -mtime +2 -type f -delete fi if [ -e "/home/$pad1/Maildir/.Allerlei.Spam" ] then find "/home/$pad1/Maildir/.Allerlei.Spam/cur" -mtime +2 -type f -delete find "/home/$pad1/Maildir/.Allerlei.Spam/new" -mtime +2 -type f -delete fi done
Now, can i just put a script like this in /etc/hourly or do i have to add things like stopping the dovecot deamon (i sure hope not!) in order to prevent file-corruption?
Or has dovecot in the meantime got a config option that does this just like courier does?
Rody
Op vrijdag 8 februari 2008 00:43, schreef Steve Annessa:
Use mail-expire.
According to http://linuxappfinder.com/package/mail-expire this is an app for mbox files. I'm using maildir folders, so it doesn't look like it's usable in my case.
Rody
On Feb 7, 2008 5:58 PM, Rody <rody@xs4all.nl> wrote:
While running dovecot on debian etch using version 1.0.rc15-2etch3, i wonder the following:
If i read the config files correctly, dovecot seems to have no equivalent of courier's IMAP_EMPTYTRASH=Trash:7 setting. Therefore, i wrote a script that dives into the user's directories and their maildirs. It looks like this:
#!/bin/bash
for pad1 in $(ls /home) do if [ -e "/home/$pad1/Maildir/.Prullenbak" ] then find "/home/$pad1/Maildir/.Prullenbak/cur" -mtime +2 -type f -delete find "/home/$pad1/Maildir/.Prullenbak/new" -mtime +2 -type f -delete fi if [ -e "/home/$pad1/Maildir/.Allerlei.Spam" ] then find "/home/$pad1/Maildir/.Allerlei.Spam/cur" -mtime +2 -type f -delete find "/home/$pad1/Maildir/.Allerlei.Spam/new" -mtime +2 -type f -delete fi done
Now, can i just put a script like this in /etc/hourly or do i have to add things like stopping the dovecot deamon (i sure hope not!) in order to prevent file-corruption?
Or has dovecot in the meantime got a config option that does this just like courier does?
Rody
Rody wrote:
While running dovecot on debian etch using version 1.0.rc15-2etch3, i wonder the following:
If i read the config files correctly, dovecot seems to have no equivalent of courier's IMAP_EMPTYTRASH=Trash:7 setting. Therefore, i wrote a script that dives into the user's directories and their maildirs. It looks like this:
#!/bin/bash
for pad1 in $(ls /home) do if [ -e "/home/$pad1/Maildir/.Prullenbak" ] then find "/home/$pad1/Maildir/.Prullenbak/cur" -mtime +2 -type f -delete find "/home/$pad1/Maildir/.Prullenbak/new" -mtime +2 -type f -delete fi if [ -e "/home/$pad1/Maildir/.Allerlei.Spam" ] then find "/home/$pad1/Maildir/.Allerlei.Spam/cur" -mtime +2 -type f -delete find "/home/$pad1/Maildir/.Allerlei.Spam/new" -mtime +2 -type f -delete fi done
Now, can i just put a script like this in /etc/hourly or do i have to add things like stopping the dovecot deamon (i sure hope not!) in order to prevent file-corruption?
Or has dovecot in the meantime got a config option that does this just like courier does?
I do something similar with a nightly cron job running a perl script. There is no locking for Maildir, so you don't have to worry about that. Some previous discussion on this list suggested that ctime might be better than mtime.
Mark
Op vrijdag 8 februari 2008 03:26, schreef Mark Nienberg:
Rody wrote:
While running dovecot on debian etch using version 1.0.rc15-2etch3, i wonder the following:
If i read the config files correctly, dovecot seems to have no equivalent of courier's IMAP_EMPTYTRASH=Trash:7 setting. Therefore, i wrote a script that dives into the user's directories and their maildirs. It looks like this:
#!/bin/bash
for pad1 in $(ls /home) do if [ -e "/home/$pad1/Maildir/.Prullenbak" ] then find "/home/$pad1/Maildir/.Prullenbak/cur" -mtime +2 -type f -delete find "/home/$pad1/Maildir/.Prullenbak/new" -mtime +2 -type f -delete fi if [ -e "/home/$pad1/Maildir/.Allerlei.Spam" ] then find "/home/$pad1/Maildir/.Allerlei.Spam/cur" -mtime +2 -type f -delete find "/home/$pad1/Maildir/.Allerlei.Spam/new" -mtime +2 -type f -delete fi done
Now, can i just put a script like this in /etc/hourly or do i have to add things like stopping the dovecot deamon (i sure hope not!) in order to prevent file-corruption?
Or has dovecot in the meantime got a config option that does this just like courier does?
I do something similar with a nightly cron job running a perl script. There is no locking for Maildir, so you don't have to worry about that. Some previous discussion on this list suggested that ctime might be better than mtime.
Mark
That makes sence. I just realize that the mtime method does not garantee that only mails exist in the mailbox which are not older than 3 days.
Rody
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 \)
Ed W
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
participants (5)
-
Benjamin R. Haskell
-
Ed W
-
Mark Nienberg
-
Rody
-
Steve Annessa