# $Id: sendmail.pl,v 1.1 1997/04/03 07:39:44 friedman Exp $

sub sendmail_open
{
  local ($handle) = &gen_filehandle ();
  local ($cmd) = '| sendmail -oi -t';

  open ($handle, $cmd) || &backtrace ("Cannot exec \"$cmd\": $!");
  return $handle;
}

sub sendmail_headers
{
  local ($handle, @args) = @_;
  local (@headers) = ('From', 'To', 'Cc', 'Bcc', 'Reply-To', 'Subject');
  local ($i) = -1;

  while (defined ($headers[++$i]))
    {
      printf ($handle "%s: %s\n", $headers[$i], $args[$i])
        if defined ($args[$i]);
    }
  print ($handle "\n");
}

sub sendmail_body
{
  local ($handle, @lines) = @_;
  foreach $line (@lines)
    {
      $line .= "\n" if ($line !~ /\n$/o);
      print $handle "$line";
    }
}

sub sendmail_close
{
  local ($handle) = @_;
  close ($handle);
}
