#!/usr/bin/perl # $Id: queue-cleaner.pl,v 1.1 2006/11/18 22:24:43 sra Exp $ # # Flush old bounce messages after some number of hours. I haven't yet # figured out a way to tell Postfix that bounce messages to strangers # should have a short lifetime, and such messages are usually a sign # of spam leakage in any case, so it may be worth raising a flag, but # I don't want to have to delete them by hand either, hence this. use strict; use DateTime; use DateTime::Format::HTTP; my $threshold = DateTime->now; $threshold->subtract(hours => 18); open(MAILQ, "-|", "/usr/local/bin/mailq") or die("Couldn't run mailq: $!"); while () { chomp; my ($id, $date) = /^([A-F0-9]+)\s+\d+\s+(.+?)\s+MAILER-DAEMON/ or next; my $t = DateTime::Format::HTTP->parse_datetime($date, "UTC"); system(qw(postsuper -d), $id) if (DateTime->compare($threshold, $t) > 0); } close(MAILQ);