#!/tmp/perl

$responses = '/tmp/foo';
$mailcommand = '|/bin/mail';

$/ = '';
$mail = (<>);

$mail =~ /\nSubject: (.+)/;
$subject = $1;

$mail =~ /\nFrom: (.+)/;
$from = $1;

chdir($responses);
@files = (<*>);

srand;
$file = $files[rand($#files+1)];

open(FILE, $file);
$response = (<FILE>);
$response =~ s/SUBJECT/$subject/;

open(MAIL, "$mailcommand $from");
print(MAIL, "$response");
close(MAIL);
