# command line parsing, sendmail version

if ($enable_relay eq "no") {

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

	# Depending in 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 ($ARGV[0] eq "-f") {
		if ($#ARGV < 5) {
			do_log(0, "Missing arguments to sendmail"); 
			do_exit($REGERR, __LINE__);
		}

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

		shift @ARGV;
		$minusr = shift @ARGV;
	}

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

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

} else {
	# relay config

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

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

# End sendmail cmd line parsing
