: # use -*- perl -*-
    eval 'exec perl -S $0 ${1+"$@"}'
        if $running_under_some_shell;

##########################################################################
#
# A fast and simple front end to sendmail. Takes input from stdin.
#
# The purpose of this program is to get around the lack of
# /usr/ucb/mail on system 5 machines. It's handy to have
# a simple interface which is independent of the system.
#
# If /usr/lib/sendmail doesn't exist -- then you've got problems!
#
##########################################################################

if ($< != 0)
   {
   die "Only root can use cfmail.\n";
   }

$tmpfile = "/tmp/cfmail.$$";

#
# Set this to the address you want the mail to appear to
# have come from. Don't set it to root@localhost, set it
# to the address of your help desk
#

$sysadm = `$prefix/sbin/cfengine -a`;
chomp($sysadm);
$flags = "-f$sysadm";

###########################################################################

&CommandOptions();

open(SND,"| /usr/lib/sendmail $flags $destination") || die "Can't open $tmpfile for writing\n";

print SND "From: $sysadm\n";
print SND "To: $destination\n";

if ($subject)
   {
   print SND "Subject: $subject\n";
   }

while (<STDIN>)
   {
   print SND;
   }

close(SND);


##########################################################################

sub CommandOptions
   {
   if ($#ARGV < 0 || $#ARGV > 2)
      {
      die "Syntax: cfmail -s subject user\n";
      }

   if ($#ARGV == 0)
      {
      $subject = "";
      $destination = $ARGV[$#ARGV];
      }


   if ($#ARGV == 2)
      {
      $first = shift;
      die "Syntax: cfmail -s subject user\n" if ($first != "-s");
      $subject = $ARGV[1];
      $destination = $ARGV[$#ARGV];
      }
   }






