#!/usr/bin/env bash

# enqueue mails, and corresponding cmd line parameters
#
# a rip-off from msmtpq
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or (at
#  your option) any later version.
#
# Cobbled together by thb@documentfoundation.org
#

BASE_DIR=~/mail/outdir

# sanity checks
which safecat > /dev/null 2>&1 || {
    echo "You need safecat for this!"
	exit 1
}

umask 077 # get us secure permissions on created directories and files

# enqueue mail, and params.
QUEUE_NAME=`safecat $BASE_DIR/tmp $BASE_DIR/mails`
if [ $? -eq 0 ]; then
	echo -e "$QUEUE_NAME\n$@" | safecat $BASE_DIR/tmp $BASE_DIR/queue 1>/dev/null && exit 0
	rm $BASE_DIR/mails/$QUEUE_NAME
fi

exit 1
