#!/bin/bash
if [ -z $ERESSEA ]; then
  echo "You have to define the \$ERESSEA environment variable to run $0"
  exit -2
fi
source $HOME/bin/functions.sh
source $ERESSEA/etc/eressea.conf

TEMPLATE=report-mail.txt
if [ "$1" == "-Lde" ]
then
  TEMPLATE=report-mail.de.txt
  shift
fi

if [ "$1" == "-Lde" ]
then
  TEMPLATE=report-mail.en.txt
  shift
fi

EMAIL=$1
SUBJECT=$2
shift 2

ATTACHMENTS=""
while [ $# -gt 0 ]
do
  if [ -e "$1" ]; then
    ATTACHMENTS="-a $1 $ATTACHMENTS"
  fi
  shift
done

cat $ERESSEA/etc/$TEMPLATE | mutt -F $ERESSEA/etc/muttrc -s "$SUBJECT" $ATTACHMENTS -- $EMAIL