#!/bin/sh

# $1 - To, $2 - Key, $3 info, $4 filename, $5 path/filename

SENDMAIL="/usr/sbin/sendmail"

if [ ! -x ${SENDMAIL} ]; then
	exit 1
fi
if [ x"$1" = x  -o  x"$2" = x  -o  x"$3" = x  -o  x"$4" = x ]; then
	exit 2
fi
if [ ! -f "$5" ]; then
	exit 3
fi

FROM=`cat /usr/local/lib/dionis.email`
if [ x"$FROM" = x ]; then
	exit 4
fi

(
echo "From: $FROM
To: $1
Errors-To: $FROM
X-Mailer: Dionis by <dzo@simtreas.ru> (U; Linux 2.2.21 i686)
X-Dionis: $2
Subject: Авторассылка от системы Дионис
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=____boundary____

This is a multi-part message in MIME format.
--____boundary____
Content-Type: text/plain; charset=koi8-r
Content-Transfer-Encoding: 8bit

$3
--____boundary____
Content-Type: application/octet-stream;
 name=\"$4\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename=\"$4\"
"
base64 "$5"
echo '--____boundary____--'
) | ${SENDMAIL} "$1"
