#!/usr/bin/perl use warnings; use strict; die "Usage: ", $0 =~ /([^\/]+)$/, " [days]\n" unless -f $ARGV[0] && @ARGV >= 1 && @ARGV <= 2; my $days = $ARGV[1] || 3; pop if $ARGV[1]; my $cutoff = time - $days * 60 * 60 * 24; my ($found, $content); while (<>){ print && next if $found; if (/^From /../^$/){ $content .= $_; if (/^Date: ([-+:,)(\w ]+)$/){ my $mdate = `date --date="$1" "+%s"`; if ($mdate >= $cutoff){ $found++; print $content; } } } else { $content = ""; } }