Dan White wrote: > On 20/02/10 16:53 -0800, Maria McKinley wrote: >> I have a mailbox that I send spam to, and I have been meaning to set >> up some filters, so that after a certain period of time, they get >> deleted. However, I got distracted, and now the inbox is very large. I >> was wondering if anyone has advice how to 1) get rid of all of the >> messages currently in the inbox that were sent before a certain date, >> and 2) how to set up a filter so that messages are moved to folders >> according to date, and then folders are deleted after a certain date. > > Please make sure you have a good backup of your mailstore before performing > any of the below. > > For 1), use ipurge. I have the following in my cyrus.conf on one of my > servers (in the EVENTS section): > > purgetrash cmd="/usr/sbin/ipurge -f -d 14 */Trash" at=0301 > > Which purges all messages older than 14 days, in all users' Trash folders > and runs every morning at 3:01am. See the man pages for ipurge and > cyrus.conf for more details. > > Sieve filters only act in incoming messages at time of delivery, and to my > knowledge can't be used to do 2). > > You could do what you're wanting in a roundabout way by renaming the > mailbox in a periodic basis, recreating the original box, and deleting the > rotated out box. > > For instance, you could run a script like this from crontab, once a month: > > #!/bin/sh > cat $HOME/last-rotated.txt | grep -q `date +%m%y` > if [ $? -eq 0 ]; then > exit > fi > MONTH=`date +%m` > echo "a01 delete user/jsmith/archive-$MONTH > a02 rename user/jsmith/archive user/jsmith/archive-$MONTH > a03 create user/jsmith/archive > a04 logout" | imtest -m plain -a cyrus -w <secret> localhost > date +%m%y > $HOME/last-rotated.txt > Got it working! In case anyone ever wants to do this, here is my setup. I have an account set up to collect all spam from all user accounts over some large spam number, so that users just have a small amount of spam (the stuff most likely to be incorrectly classified) in their spam folders. On this spam account, I have a sieve filter that puts all incoming mail into the archive folder. Then once a week I rotate the folders, deleting the folder from 4 weeks ago. So users have a month to complain to me about missing mail, and the folders are still almost manageable. Here is the script that I run once a week: #!/bin/sh cat $HOME/last-rotated.txt | grep -q `date +%U` if [ $? -eq 0 ]; then exit fi WEEK=`date +%U` DWEEK=`date --date='4 weeks ago' +%U` echo "a01 delete user.test.archive-$DWEEK a02 rename user.test.archive user.test.archive-$WEEK a03 create user.test.archive a04 logout" | imtest -m login -p imap -u cyrus -a cyrus -w <secret> localhost date +%U > $HOME/last-rotated.txt cheers, maria ---- Cyrus Home Page: http://cyrusimap.web.cmu.edu/ Cyrus Wiki/FAQ: http://cyrusimap.web.cmu.edu/twiki List Archives/Info: http://asg.web.cmu.edu/cyrus/mailing-list.html