#!/bin/bash # # vmail-stack # https://git.stack-source.com/msb/vmail-stack # Copyright (c) 2022 Matthew Saunders Brown # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # load include file source $(dirname $0)/vmail.sh help() { thisfilename=$(basename -- "$0") echo "$thisfilename" echo "Modify autoresponder" echo "" echo "usage: $thisfilename -e [-u ] [-b ] [-o ] [-s <0|1>] [-h]" echo "" echo " -h Print this help." echo " -e Email address of the autoresponder." echo " -u Subject of autresponder emails." echo " -b Body of autresponder emails." echo " -o 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" echo " have double back slash like this \\\' and all newlines should be encoded as \n." 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 echo "One or more options to update must be specified." exit 1 fi # build query dbcmd="mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE" dbcmdopts="-s -r -N -e" # 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\"` if [[ -z $autoresponder_id ]]; then # autoresponder does not exist echo "ERROR: Autoresponder for $email does not exists, can't edit. Add new autoresponder instead." exit 1 else # 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\;\" fi