# BEGIN_MTA_ARGS
# MTA: sendmail
# command line parsing

if ($enable_relay eq "no") {

    if ($#untaint_ARGV < 3) {
	do_log(0, "Missing arguments to sendmail");
	do_exit($REGERR, __LINE__);
    }

    # Depending on the F= equate in the local mailer definition,
    # sendmail may prepend -f $g or -r $g to the local mailer
    # cmd line args
    #
    # If so, strip it off, and add it back in front of the remaining
    # arguments after we shift out the sender, recipient and LDA

    my $minusf = "";
    my $minusr = "";
    if ($untaint_ARGV[0] eq "-f") {
	if ($#untaint_ARGV < 5) {
	    do_log(0, "Missing arguments to sendmail"); 
	    do_exit($REGERR, __LINE__);
	}

	shift @untaint_ARGV;
	$minusf = shift @untaint_ARGV;
    } elsif ($untaint_ARGV[0] eq "-r") {
	if ($#untaint_ARGV < 5) {
	    do_log(0, "Missing arguments to sendmail");
	    do_exit($REGERR, __LINE__);
	}

	shift @untaint_ARGV;
	$minusr = shift @untaint_ARGV;
    }

    $SENDER = shift @untaint_ARGV;
    push(@RECIPS, shift @untaint_ARGV);
    $LDA = shift @untaint_ARGV;
    @LDAARGS = @untaint_ARGV;

    if ($minusf ne "") {
	unshift(@LDAARGS, $minusf);
	unshift(@LDAARGS, "-f");
    } elsif ($minusr ne "") {
	unshift(@LDAARGS, $minusr);
	unshift(@LDAARGS, "-r");
    }

} else {
    # relay config
    if ($#untaint_ARGV < 1) {
	do_log(0,"Missing arguments to sendmail");
	do_exit($REGERR, __LINE__);
    }

    $SENDER = shift @untaint_ARGV;
    push(@RECIPS, @untaint_ARGV);
    $LDA = $sendmail_wrapper;
    push(@LDAARGS, "-i");
    push(@LDAARGS, "-C$sendmail_cf_orig");
    push(@LDAARGS, "-f<$SENDER>");
    push(@LDAARGS, "@RECIPS");
}
# END_MTA_ARGS
