#!/usr/bin/perl

$inbox = shift(@ARGV) or die "Usage: $0 <mbox file>\n";

print "From line of message to grab:\n";
$from = <STDIN>;

$/ = '';

open(MAIL,"$inbox");
open(OUT,">/tmp/$$.out");

my $test = 0;
my $msg = "";

while (<MAIL>) {
	if (/^From / && /$from/) {
		$msg = $_;
		while (<MAIL>) {
			last if /^From /;	# Hit the end of the message
			$msg .= $_;
		}
	}
}

print OUT $msg;

close(OUT);
close(MAIL);

print "Wrote ".length($msg)." bytes to file /tmp/$$.out\n";

