From owner-freebsd-questions@FreeBSD.ORG Wed Aug 17 15:02:25 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DE32316A41F for ; Wed, 17 Aug 2005 15:02:25 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from kane.otenet.gr (kane.otenet.gr [195.170.0.95]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3B99643D46 for ; Wed, 17 Aug 2005 15:02:24 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from flame.pc (aris.bedc.ondsl.gr [62.103.39.226]) by kane.otenet.gr (8.13.4/8.13.4/Debian-1) with SMTP id j7HF2LBr013990; Wed, 17 Aug 2005 18:02:21 +0300 Received: from flame.pc (flame [127.0.0.1]) by flame.pc (8.13.4/8.13.4) with ESMTP id j7HF88lP098019; Wed, 17 Aug 2005 18:08:08 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by flame.pc (8.13.4/8.13.4/Submit) id j7HF87o8098018; Wed, 17 Aug 2005 18:08:07 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Date: Wed, 17 Aug 2005 18:08:07 +0300 From: Giorgos Keramidas To: Matt Juszczak Message-ID: <20050817150806.GA92348@flame.pc> References: <43034EA2.4000206@atopia.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43034EA2.4000206@atopia.net> Cc: freebsd-questions@freebsd.org Subject: Re: OT: Removal of old 14+ mail from mbox-based mail spool (not maildir) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Aug 2005 15:02:26 -0000 On 2005-08-17 10:50, Matt Juszczak 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