#! /bin/sh
version=1.0
#
#	fmmail 1.0 6/6/87
#
#   Copyright (c) 1986-89 by Frame Technology Corp.
#   Steve Kirsch
#   Modified by Mike Takamoto to account for Sun OS 4.0
#
# This shell script allows you to mail binary files (like frame docs)
# to any sun machine using the regular mail. You must know the machine
# name you are sending to and the mail alias "decode" must exist there.
# This is the case for all Sun machines.

if [ $# -eq 0 ]; then
	echo "Format is: fmmail <filename1> <filename2>  ... <filenameN>

This program lets you send binary files through the mail to a remote machine.
You will be prompted for the recipient's machine address and his user id.

The file(s) you specify on the command line will be sent to the /usr/tmp
directory of the destination. The source file(s) can be full
pathnames, but the destination directory will always be /tmp.

Note that when prompted for the recipient's machine address, you
should normally use everything but the last part of the complete uucp
address, e.g., if you normally send e-mail messages to:
	sun!frame!tse
then you would use:
	sun!frame
as the machine address, and give:
	tse
as the user id. Note that this combination will get to Frame's
tech support engineering staff.

This script works by uuencoding the file and mailing it to the decode
alias on the target machine with a creation name in /tmp since
this is one of the few places where there is universal write
permission that is not cleared in a reboot. It also sends a mail
message to the person letting him know that the file has been created
and where to find it.  "
	exit 1
fi
ask(){
        answer=undefined
        until [ "$answer" = "y" -o "$answer" = "n" ];
        do
        echo -n "$1 [y or n]: "
        read answer
        done
       [ $answer = y ]
}
files=$*

echo -n "fmmail $version: Mails any file to /tmp of receiver.
Machine address of recipient: "
read machine

echo -n "User id of recipient: "
read userid
echo
if ask "Is this the correct full e-mail address of the recipient:
	$machine!$userid
"; then
	echo
else
	echo "Terminated."
	exit 1;
fi
	
	
for fname in $files 
do
    if [ -f $fname ]; then
	dest=`basename $fname`
	echo -n "Mailing $fname...."
	uuencode $fname /tmp/$dest | Mail $machine\!decode
	echo -n  "..."
	echo "Please move this to your home directory." |\
	Mail -s "/tmp/$dest was created on $machine" $machine\!$userid

	echo "done."
    else
	echo "Sorry, $fname is not a file."
    fi
done
echo
echo "fmmail finished."

