#!/usr/bin/perl
# This summarizes new messages in a maildir.
# This file is under the Gnu General Public License. NO WARRANTY.

# The following associates maildir names with a short prefix. You should
# tune it to your setup.

$prefix{'/home/tom/email/Inbox/'} = "In:";
$prefix{'/home/tom/email/cpw/'} = "Cp:";


my $maildir = shift;
my $prefix = $prefix{$maildir};

opendir DIR, "$maildir/new/";
for $i (readdir(DIR)) {
	next if $i =~ /^\./;

	my %headers;

	open M, "$maildir/new/$i";
	
	while (<M>) {
		chomp;
		last unless $_;

		if (/^(\w+): (.*)$/) {
			$headers{lc $1} = $2;
		}
	}

	my $sub = $headers{subject};
	my $from = $headers{from};

	$from =~ s/\<.*\>//;
	$from =~ s/\s+$//g;

	my $tot = "$prefix $from: $sub";
	print substr($tot, 0, 79), "\n";

	close M;
}

