On Fri, Mar 16, 2007 at 12:16:21PM +1300, Malcolm Locke wrote: > On Thu, Mar 15, 2007 at 04:24:00PM -0600, Jason Bailey, Sun Advocate Webmaster wrote: > > Is it possible to set up a message retention policy that deletes email > > that is, say, over a year old from the mailboxes on the server? > > > > I know many IMAP servers do support message retention policies, but I > > have had difficult time finding thorough, concrete information on them > > regarding Cyrus. Does such a feature even exist? > > 2 things need to be in place: > > - The mailbox you want to have cleared out needs to have the 'expire' > annotation set. Easiest way is via cyradm, e.g. to set an expiry of > 30 days on joebloggs Trash folder. > > cyradm> mboxcfg user.joebloggs.Trash expire 30 > > - The cyr_expire command needs to be running in the EVENTS section of > cyrus.conf. I have: > > delprune cmd="cyr_expire -E 3" period=1440 > > Which causes the expired messages to be deleted every 24 hours. That's probably the easiest way. I tend to go for external controls, and would be more likely to implement a script running from cron that looked something like the following piece of Perl. This is guaranteed to hit all the folders (modulo domain split, etc) and doesn't depend on the annotations being kept up to date. It's not the most efficient piece of code in the world (no attempt to store flags on multiple messages at once), but it's simple and clear. This code is somewhat tested, though I replaced "user." with "user.brong." to restrict the output, and I didn't run the delete path! Bron. ------ # set up parameters here: my $Server = 'localhost'; my $Port = 143; my $Username = 'admin'; my $Password = ''; my $REALLYDELETE = 0; use warnings; use strict; use Date::Manip; use Mail::IMAPTalk; my $Lastyear = UnixTime("- 1 year", '%d-%b-%Y'); my $imap = Mail::IMAPTalk->new( Server => $Server, Port => $Port, Username => $Username, Password => $Password, Uid => 1, ); # look at every folder on the system as the admin user my @folders = $imap->list('user.', '*'); foreach my $folder (@folders) { my $foldername = $folder->[2]; $imap->select($foldername); my $messages = $imap->search('1:*', 'BEFORE', $Lastyear); my $n = @$messages; next unless $n; # remove this if you want 0 message notifications too! print "$foldername deleting $n messages older than $Lastyear\n"; if ($REALLYDELETE) { foreach my $uid (@$messages) { $imap->store($uid, '+flags', '(\\deleted)'); } $imap->expunge(); } } exit 0; ---- 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