#!/afs/athena/contrib/perl/p

$count = 0;
open (SUBJECTS, ">subjects") || die "Can't open subject file: $!";
while (@ARGV) {
    $file = shift @ARGV;
    open (FILE, "<$file") || die "Can't open file $file: $!";
    ++$count; 
    $header = 1;
    open (FILEOUT, ">$count") || die "Can't open output file $count: $!";
    while (<FILE>) {
	$header = 1 if /^From /;
	print FILEOUT if ! $header;
	$header = 0 if /^$/;
	print FILEOUT if /^From:|^Date:|^Subject:|^$/;
	if (/^Subject:(.*)/) {
		print SUBJECTS "$1\n";
	}
    }
    close (FILE);
    print FILEOUT "\n";
    close (FILEOUT);
}
close (SUBJECTS);
