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 "Delete autoresponder."
|
|
|
|
echo ""
|
|
|
|
echo "usage: $thisfilename -e email [-h]"
|
|
|
|
echo ""
|
|
|
|
echo " -h Print this help."
|
|
|
|
echo " -e <email> 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
|
2022-11-29 16:33:15 -08:00
|
|
|
dbquery="SELECT id FROM vm_autoresponders WHERE mbox='$mbox' AND domain='$domain';"
|
2022-05-23 15:49:49 -07:00
|
|
|
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
|