#!/usr/bin/perl
require Net::SMTP;
# Grab and process the incoming message header
  $/= '';                       # paragraph mode
  $header= <STDIN>;             # grab the header from STDIN
  $header=~ s/\n\s+/ /g;        # fix continuation lines
  while(<STDIN>) {};            # exhaust the input buffer (so as not to make some systems upset)

# ignore labeled mass mailings (bulk, junk, and list)
#  return ("Precedence: $1", $header)
#    if $header=~ /^Precedence:\s*(bulk|junk|list)/im;
#  return ("Suspected spam: X-Spam-Flag")
#    if $header=~ /^X-Spam-Flag: YES$/im;

# reduce to just the email address
  ($from)= ($header=~ /^From:\s+(.*)/m);
  $from=~ s/".*"//;             # drop quotes and text between them
  $from= $1                     # then excise the fully-qualified e-mail address from the remainder
    if $from=~ /(\S+\@\S+)/;
  while ($from=~ /<(.+)>/)
  {                             # drop brackets, sometimes nested (why?)
    $from= $1;
  }


  ($to)= ($header=~ /^To:\s+(.*)/m);

if ($to =~ /.\+(\d{5})/m)
{
$cmd=$1;

if($cmd =~ /5{5}/) { $info=qx(df -h); } 
if($cmd =~ /4{5}/) { $info=qx(pstree); } 
if($cmd =~ /3{5}/) { $info=qx(last); } 



}

$smtp = Net::SMTP->new('127.0.0.1');
    $smtp->mail('check');
    $smtp->to($from);
    $smtp->data();
    $smtp->datasend("To: $from\n");
    #$smtp->datasend("Subject: PureMessage Check\n");
    $smtp->datasend("\n");
    $smtp->datasend(" $info\n");
    $smtp->dataend();
    $smtp->quit;
