Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

script for an mbox

0 views
Skip to first unread message

Tony Heal

unread,
May 9, 2008, 12:59:25 PM5/9/08
to begi...@perl.org
I need to remove all messages older than X from a gigabyte size mbox. Anyone
got a script for this?

Tony Heal

Pace Systems Group, Inc.

800-624-5999 x9317

Gunnar Hjalmarsson

unread,
May 10, 2008, 9:50:52 AM5/10/08
to begi...@perl.org
Tony Heal wrote:
> I need to remove all messages older than X from a gigabyte size mbox. Anyone
> got a script for this?

Here is a quick-and-dirty script to start with:

use Date::Parse;

sub isOld {
my $date = shift;
my $time = str2time($date);
my $cmptime = '1210377600';
$time < $cmptime ? 1 : 0;
}

my $date_re = qr/^Date:\s*(.+)/m;

my $msg = <>;

while (<>) {
if ( /^From / ) {
my ($date) = $msg =~ $date_re;
print $msg unless isOld($date);
$msg = $_;
} else {
$msg .= $_;
}
}

my ($date) = $msg =~ $date_re;
print $msg unless isOld($date);

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Dr.Ruud

unread,
May 11, 2008, 6:47:14 AM5/11/08
to begi...@perl.org
"Tony Heal" schreef:

> I need to remove all messages older than X from a gigabyte size mbox.
> Anyone got a script for this?

You can use formail to split up the mbox, see `man formail`.

Then check the date in the postmark line (always the first line, the one
that starts with From<space>).
That date looks like this: Tue Oct 26 21:44:31 1999, so you should
convert to something like 1999-10-26T21:44:31 to make it string
comparable.

--
Affijn, Ruud

"Gewoon is een tijger."

0 new messages