#! /usr/bin/perl -w use strict; use Mail::Util qw(read_mbox); sub recurse ($) { my $file = shift; -d $file or return ($file); opendir DIR, $file or return ($file); my @contents = map { recurse("$file/$_") } grep !/^\.\.?$/, readdir DIR; closedir DIR; return @contents; } my @folders = recurse "$ENV{HOME}/mail"; foreach my $folder (@folders) { my @messages = read_mbox($folder); foreach my $message (@messages) { my $from; my $print_from = 0; my $scan = 0; foreach my $line (@$message) { last if $line =~ /^$/; if ($line =~ /^From:[ \t](.*)/) { $from = $1; } if ($line =~ /^(?:To|Cc)/) { $scan = 1; } elsif ($line !~ /^[ \t]/) { $scan = 0; } if ($scan) { if ($line =~ /cjw44|cjwatson/) { $print_from = 1; last; } } } print "$from\n" if $print_from and defined $from; } }