Date: Wed, 17 Aug 2005 18:08:07 +0300 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: Matt Juszczak <matt@atopia.net> Cc: freebsd-questions@freebsd.org Subject: Re: OT: Removal of old 14+ mail from mbox-based mail spool (not maildir) Message-ID: <20050817150806.GA92348@flame.pc> In-Reply-To: <43034EA2.4000206@atopia.net> References: <43034EA2.4000206@atopia.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2005-08-17 10:50, Matt Juszczak <matt@atopia.net> wrote: > Hi all, > Sorry this is off topic, just didn't really know where else to post > this other than to fellow sys-admins. > > I need a script that will analyze a mail spool file and remove email > from it that is more than 14 days old. I found a couple; however, > they require perl modules I couldn't seem to find. Does anyone have > any ideas? If not, I'll go ahead and write one. If you have procmail, you can roll your own with something like: $ formail -s procmail procmailrc-remove-old < mbox The ``procmailrc-remove-old'' ruleset can implement something like the logic of removing old messages, by piping the messages one by one through a shell script that uses date(1) on the envelope-from line. All messages in a Unix mbox file start with a line like this: From keramida@FreeBSD.ORG Fri Sep 3 18:19:29 2004 You can extract the timestamp and convert it to seconds since the UNIX Epoch time, with date(1): % message_time=$( echo 'From keramida@FreeBSD.ORG Fri Sep 3 18:19:29 2004' | \ % awk '{print $4,$5,$6,$7}' ) % message_seconds=$( date -j -f '%b %e %H:%M:%S %Y' "$message_time" '+%s' ) This should set $message_seconds to 1094224769. Then you can get the current time in seconds from the UNIX Epoch and perform ordinary numeric operations, i.e. subtract the number of seconds in a 14-day period. Messages with a $message_seconds value less than the current time minus the period of your choise, should be thrown away. The rest should be echoed back to procmail, which will deliver them as usual. This is just an idea of course, so you may want to look at existing mailers, like Mutt, before you start scripting. They usually include options to select message ranges based on the arrival date. - Giorgos
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050817150806.GA92348>