Subject: Auto mail expiry?

From: Roman Czyborra <[email-masked]>
Date: Thu, 16 Dec 1993 02:16:55 +0100

Here is a self-written expirer:

#! /usr/local/bin/gawk -f
# using GNU version 2.15 of awk: This filter deletes all messages
# older than expire days from a Unix mailbox. Sample call:
# gawk -f expire.awk expire=21 box > new && mv new box

BEGIN {

	# We need a little calendar:
	months= "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec";
	split(  "0   31  59  90  120 151 181 212 243 273 304 334", offset);

	# Default expire is 14 days:
	expire = 14;

	# This is the timezone for Central Europe. Let's forget about DST.
	timezone = +01;
	now=systime();
}

NR==1 || !inparagraph && $0 ~ /^From / {

	# The envelope has this form:
	# $1   $2                       $3  $4  $5 $6       $7
	# From [email-masked] Thu Dec 16 00:22:43 1993

	month = 1 + int (index(months, $4) / 4);
	date = $5; year = $7 - 1900;

	days = date - 1 + offset[month] + year * 365;

	# Leap year calculation: This will get one day off track
	# in 2100 AD. I'll be dead by then. We may already run
	# into an integer overflow in 2038:
	days += int (year / 4) + (month < 3 && year % 4 == 0 ? -1 : 0);

	# Days were since Jan 1, 1900, we need 1970 instead:
	days -= 70 * 365 + 17;
        
	split($6, time, ":"); hour = time[1] - timezone;
	timestamp = days * 86400 + hour * 3600 + time[2] * 60 + time[3];

	expired = now - timestamp > expire * 86400 ? 1 : 0;
}

{
	if (!expired) print;

	# Messages must be preceded by a blank line (length == 0)
	inparagraph = length;
}