#!/bin/bash
#Dummy helper to send email to arch-dev
# It does nothing if no output

set -eE -o pipefail
# Load $LIST and $FROM from the config file
. "$(dirname "$(readlink -e "$0")")/../config"

SUBJECT="Repository Maintenance $(date +"%d-%m-%Y")"
if (( $# >= 1 )); then
	SUBJECT="$1 $(date +"%d-%m-%Y")"
fi

if (( $# >= 2 )); then
	LIST="$2"
fi

stdin="$(cat)"
#echo used to strip whitespace for checking for actual data
if [[ -n "$(echo $stdin)" ]]; then

	echo "Subject: $SUBJECT
To: $LIST
From: $FROM

$stdin" | /usr/sbin/sendmail -F"$FROM" "$LIST"

fi
