#!/usr/bin/perl -w # # qrdate # John Simpson 2007-07-19 # # sorts "qmail-qread" output by date # ############################################################################### # # Copyright (C) 2007 John Simpson. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 or version 3 of the # license, at your option. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # ############################################################################### require 5.003 ; use strict ; use Getopt::Std ; my %mno = qw ( Jan 01 Feb 02 Mar 03 Apr 04 May 05 Jun 06 Jul 07 Aug 08 Sep 09 Oct 10 Nov 11 Dec 12 ) ; my ( %opt , %msg , $ckey ) ; ############################################################################### # # change date from "01 Jan 2007" to "2007-01-01" for sorting purposes sub dt($) { my @w = split ( /\s/ , $_[0] , 4 ) ; my $n = ( $mno{$w[1]} || $w[1] ) ; return "$w[2]-$n-$w[0] $w[3]" ; } ############################################################################### ############################################################################### ############################################################################### getopts ( "d" , \%opt ) ; $ckey = "" ; open ( I , "/var/qmail/bin/qmail-qread |" ) or die "Can't run qmail-qread: $!\n" ; while ( my $line = ) { if ( $line !~ /^\s/ ) { $ckey = dt ( $line ) ; $msg{$ckey} = ( $opt{"d"} ? $ckey : $line ) ; next ; } $msg{$ckey} .= $line ; } close I ; map { print $msg{$_} } sort keys %msg ;