#!/usr/local//bin/perl
##########################################################################
#
# A fast an 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.
#

$flags = "-fSYSADM\@MYDOMAIN";

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

&CommandOptions();

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

print SND "From: SYSADM\@MYDOMAIN\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];
      }

   }






