:
# @(#) addrem.sh 1.2 94/04/23
# addrem: write to reminder file or mail reminder
# 91/05/21 john h. dubois iii (john@armory.com)
# 91/05/28 changed to use hostname instead of hard-coded host name.
# 91/07/22 changed to use $REMIND if first arg is not "me" and
#          does not have a ! or @ in it.
# 92/11/08 Read from input if no reminder text given.
# 93/07/23 Changed name from remind to addrem to avoid conflict;
#          changed 'me' special name to '.'
# 94/01/21 Prepend date.
# 94/04/23 Use .addrem

remsubj=%%remind%%
me=.
name=addrem

help=\
"$name: write to reminder file or mail reminder.
Syntax: $name [$me|<user>] reminder-line
If the first argument is '$me', the reminder line is appended to the file
.reminder in your home directory.  If the first argument has a '!' or '@' in
it, it is taken as the name of a user to mail the reminder line to.  If not,
value of the REMIND environment variable is used if it is set.  REMIND can also
be set in the file .addrem in the invoking user's home directory, in the form
REMIND=user
The subject of the mail will be \"$remsubj\".  The current date will
be prepended to the reminder line.  The reminder line does not need to be
quoted unless it contains characters special to the shell.

To make reminders in this format that are mailed to you automatically be put
into your .reminder file instead of showing up in your mailbox, add the
following line to your .maildelivery file:
Subject	%%remind%% pipe	A /local/bin/procrem"

case $1 in
*[@!]*|$me) user=$1; shift;;
-h) echo "$help"; exit 0;;
*)    
    if [ -z "$REMIND" ]; then
	rc=$HOME/.addrem 
	[ -f $rc -a -r $rc ] && . $rc
    fi
    user=$REMIND
    ;;
esac

if [ -z "$user" ]; then
    echo "No destination.  Use -h for help.  Exiting." 1>&2
    exit 1
fi

# dirmail: invoke execmail directly.
# usage: dirmail <subject> <destination> <text>
dirmail() {
    echo \
"From: $USER@`hostname` ($NAME)
To: $2
Subject: $1
Date: `date`

$3" | /usr/lib/mail/execmail "$2"
}

if [ $# -lt 1 ]; then
    [ -t 0 ] && echo "Enter reminder text; end with ^D."
    text="`cat`"
else
    text=$*
fi

text="`date +%y/%m/%d` $text"

if [ "$user" = $me ]; then 
    echo "$text" >> $HOME/.reminder 
else
    dirmail "$remsubj" "$user" "$text"
fi
