2022-05-23 15:49:49 -07:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# vmail-stack
|
|
|
|
# https://git.stack-source.com/msb/vmail-stack
|
2022-08-22 13:34:20 -07:00
|
|
|
# Copyright (c) 2022 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
2022-05-23 15:49:49 -07:00
|
|
|
|
|
|
|
# load include file
|
|
|
|
source $(dirname $0)/vmail.sh
|
|
|
|
|
|
|
|
help()
|
|
|
|
{
|
|
|
|
thisfilename=$(basename -- "$0")
|
|
|
|
echo "$thisfilename"
|
|
|
|
echo "Modify autoresponder"
|
|
|
|
echo ""
|
|
|
|
echo "usage: $thisfilename -e <email> [-u <subject>] [-b <body>] [-o <mode>] [-s <0|1>] [-h]"
|
|
|
|
echo ""
|
|
|
|
echo " -h Print this help."
|
|
|
|
echo " -e <email> Email address of the autoresponder."
|
|
|
|
echo " -u <subject> Subject of autresponder emails."
|
|
|
|
echo " -b <body> Body of autresponder emails."
|
|
|
|
echo " -o <mode> Mode - either Autoresponder or Vacation."
|
|
|
|
echo " -s <0|1> Status. 0 = disabled/off, 1 = enabled/on. Default is 1."
|
|
|
|
echo ""
|
|
|
|
echo " The body must be single quoted and escaped. All single quotes in the body must"
|
2022-05-24 15:26:09 -07:00
|
|
|
echo " have double back slash like this \\\' and all newlines should be encoded as \n."
|
2022-05-23 15:49:49 -07:00
|
|
|
echo " In Vacaion mode only the first email from a specific address is replied to,"
|
|
|
|
echo " in Autoresponder mode every incoming email, including repeats, get a response."
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
|
|
|
vmail:getoptions "$@"
|
|
|
|
|
|
|
|
# check for email
|
|
|
|
if [[ -z $email ]]; then
|
|
|
|
echo "email is required"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# check for options
|
|
|
|
if [[ -z $subject && -z $body && -z $mode && -z $status ]]; then
|
2022-11-29 16:33:15 -08:00
|
|
|
echo "One or more options to update must be specified."
|
2022-05-23 15:49:49 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# build query
|
|
|
|
dbcmd="mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE"
|
|
|
|
dbcmdopts="-s -r -N -e"
|
|
|
|
|
2022-11-29 16:33:15 -08:00
|
|
|
# get autoresponder id, which also verfies that the autoresponder exists
|
|
|
|
dbquery="SELECT id FROM vm_autoresponders WHERE mbox='$mbox' AND domain='$domain';"
|
|
|
|
autoresponder_id=`eval $dbcmd $dbcmdopts \"$dbquery\"`
|
2022-05-23 15:49:49 -07:00
|
|
|
|
2022-11-29 16:33:15 -08:00
|
|
|
if [[ -z $autoresponder_id ]]; then
|
|
|
|
# autoresponder does not exist
|
|
|
|
echo "ERROR: Autoresponder for $email does not exists, can't edit. Add new autoresponder instead."
|
2022-05-23 15:49:49 -07:00
|
|
|
exit 1
|
|
|
|
else
|
2022-11-29 16:33:15 -08:00
|
|
|
# build update query (set id is just to facilitate building query)
|
|
|
|
dbquery="UPDATE vm_autoresponders SET id='$autoresponder_id'"
|
|
|
|
if [ ! -z "$subject" ]; then
|
|
|
|
dbquery="$dbquery, subject='$subject'"
|
|
|
|
fi
|
|
|
|
if [ ! -z "$body" ]; then
|
|
|
|
dbquery="$dbquery, body='$body'"
|
|
|
|
fi
|
|
|
|
if [ ! -z $mode ]; then
|
|
|
|
dbquery="$dbquery, mode='$mode'"
|
|
|
|
fi
|
|
|
|
if [ ! -z $status ]; then
|
|
|
|
dbquery="$dbquery, status='$status'"
|
|
|
|
fi
|
|
|
|
dbquery="$dbquery WHERE id='$autoresponder_id'"
|
|
|
|
eval $dbcmd $dbcmdopts \"$dbquery\;\"
|
2022-05-23 15:49:49 -07:00
|
|
|
fi
|