#!/bin/bash
# Richard Nelson <cowboy@debain.org>
# Socks5 support wrapper for sendmail

DAEMON=/usr/sbin/sendmail.real
RUNSOCKS=/usr/bin/runsocks
BASENAME=$(basename $0)

# Adjust command name based upon the presence of the socks5 wrapper
if [ -x $RUNSOCKS ]; then
   COMMAND="$RUNSOCKS $DAEMON"
else
   COMMAND="$DAEMON"
   fi
#echo "$BASENAME command="$COMMAND

# Exec the appropriate command
case "$BASENAME" in
    # These don't need socks support, and must be called by name
    "hoststat" | "mailq" | "newaliases" | "purgestat")
	exec -a $BASENAME $DAEMON "$@"
	;;
    # These need socks support
    "sendmail")
	exec -a $DAEMON $COMMAND "$@"
	;;
    # Help... shouldn't be here
    *)
	echo "panic, $BASENAME is not a valid alias for sendmail."
	;;
    esac
