#!/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 "Delete autoresponder." echo "" echo "usage: $thisfilename -e email [-h]" echo "" echo " -h Print this help." echo " -e Email address to remove autoresponder from." exit } vmail:getoptions "$@" # check for email if [[ -z $email ]]; then echo "email is required" exit 1 fi # build query dbcmd="mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE" dbcmdopts="-s -r -N -e" # get autoresponders id which also works to confirm autoresponder exists dbquery="SELECT vm_autoresponders.id FROM vm_autoresponders, vm_mboxes, vm_domains WHERE vm_autoresponders.mbox_id=vm_mboxes.id AND vm_mboxes.mbox='$mbox' AND vm_mboxes.domain_id=vm_domains.id AND vm_domains.domain='$domain';" vm_autoresponders_id=`$dbcmd $dbcmdopts "$dbquery"` if [ -z "$vm_autoresponders_id" ]; then echo "ERROR: Autoresponder for $email does not exist." exit 1 elif [ "$vm_autoresponders_id" -gt '0' ]; then dbquery="DELETE FROM vm_autoresponders WHERE vm_autoresponders.id='$vm_autoresponders_id';" eval $dbcmd $dbcmdopts \"$dbquery\" echo "SUCCESS: Autoresponder for $email removed from system." exit 0 else echo "ERROR: System error querying vmail database" exit 1 fi