#!/usr/bin/perl

use strict;

my $virus = (shift || "Virus alert");
my @mail = <>;
my $from = "";
my $body;

foreach (@mail) {
	chop;
	if (/^From:\s+".*"\s+<([^>]+)>$/) {
		$from = $1;
	}
}

open(M,'|/usr/sbin/sendmail -f user\@domain user\@domain')  || die 'can not open sendmail';
print M "From: user\@domain\n";
print M "To: user\@domain\n";
if ($from ne '') {
	print M "Subject: [Virus] $from ($virus)\n";
}else{
	print M "Subject: [Virus] $virus\n";
}
print M "\n\n";

print M "Virus alert.\n\n";

$body = 0;
foreach (@mail) {
	if ($body==0) {
		print M "$_\n";
	}else{
		print M ">>> $_\n";
	}
	$body = 1 if (/^$/);

}

close M;

exit 0;
