#!/bin/ksh

# First parameter is file to be attached
# second parameter is optional email address.  Set _EMAIL_TARGET to be the default

_ATTACH_FILE="/tmp/osullm.attach.$$"
_BODY_FILE="/tmp/osullm.body.$$"
_DATESTAMP=$(date)
_EMAIL_ATTACHMENT=$(basename $1)
_EMAIL_TARGET="michael.o'sullivan@guardian.co.uk"

cat > ${_BODY_FILE} <<MOS
Hi,

This email has been sent to ${_EMAIL_TARGET},$2 and should contain the following
attachment:

$1

Kind regards,

The Automatic Email Attacher
on behalf of Michael O'Sullivan.

Date sent: ${_DATESTAMP}

MOS

cp $1 ${_ATTACH_FILE}
unix2dos ${_ATTACH_FILE} ${_ATTACH_FILE}

(
cat ${_BODY_FILE}
uuencode $1 $1 < ${_ATTACH_FILE}

) | mailx -r ${_EMAIL_TARGET} -s "${_EMAIL_ATTACHMENT} is attached for your information" ${_EMAIL_TARGET}

rm ${_ATTACH_FILE} ${_BODY_FILE}
