+#### Find location of a program. Bourne shell just puts the name in
+#### $0 if it's found from the PATH, so search that if necessary.
+finddir() {
+ case $1 in
+ */*) dirname "$1" ;;
+ * ) IFS=:
+ for d in $PATH; do
+ [ -f "${d:=.}/$1" -a -x "$d/$1" ] && printf %s "$d" && break
+ done ;;
+ esac
+}
+
+die() {
+ printf '%s\n' "$usage"; exit ${1:-1}
+}
+
+bindir=`finddir $0`
+nmhbindir=`cd "$bindir" && pwd`
+nmhlibdir=`$nmhbindir/mhparam libdir`
+
+
+#### Process switches.
+compress= ## compress method
+compressarg=0 ## whether currently handling -compress
+delay= ## delay value
+delayarg=0 ## whether currently handling -delay
+from= ## From: contents
+fromarg=0 ## whether currently handling -from
+subject= ## Subject: contents
+subjectarg=0 ## whether currently handling -subject
+to= ## To: address
+toarg=0 ## whether currently handling -to
+for arg in "$@"; do
+ case $arg in
+ -c|-co|-com|-comp|-compr|-compre|-compres|-compress) compressarg=1 ;;
+ -d|-de|-del|-dela|-delay) delayarg=1 ;;
+ -[0-9]|-[0-9][0-9]|-[0-9][0-9][0-9]|-[0-9][0-9][0-9][0-9])
+ delay=`printf '%s\n' "$arg" | sed -e 's%-%%'` ;;
+ -f|-fr|-fro|-from) fromarg=1 ;;
+ #### Support -gzip for backward compatibility.
+ -gzip) compress=gzip ;;
+ -h|-he|-hel|-help) die 0 ;;
+ #### Support -none for backward compatibility.
+ -none) compress=none ;;
+ -s|-su|-sub|-subj|-subje|-subjec|-subject) subjectarg=1 ;;
+ -t|-to) toarg=1 ;;
+ -v|-ve|-ver|-vers|-versi|-versio|-version)
+ "$nmhlibdir/viamail" -version | sed 's/viamail/sendfiles/'; exit ;;
+ -*) die ;;
+ *) if [ $compressarg -eq 1 ]; then
+ compress="$arg"
+ compressarg=0
+ elif [ $delayarg -eq 1 ]; then
+ delay="$arg"
+ delayarg=0
+ elif [ $fromarg -eq 1 ]; then
+ from="$arg"
+ fromarg=0
+ elif [ $subjectarg -eq 1 ]; then
+ subject="$arg"
+ subjectarg=0
+ elif [ $toarg -eq 1 ]; then
+ to="$arg"
+ toarg=0
+ else
+ #### Argument doesn't apply to a switch, so we're done with switches.
+ break
+ fi ;;
+ esac
+ shift
+done
+
+#### Check for switch after non-switch argument.
+for arg in "$@"; do
+ case $arg in
+ -*) die ;;
+ esac
+done
+
+#### Check for required arguments (to, subject, file(s)).
+if [ x"$to" = x ]; then
+ if [ x"$subject" = x ]; then
+ if [ $# -ge 3 ]; then
+ to="$1"; shift
+ subject="$1"; shift
+ else
+ die
+ fi
+ else
+ die
+ fi
+else
+ [ x"$subject" = x -o $# -lt 1 ] && die