52 lines
1.4 KiB
Bash
Executable File
52 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# vmail-stack
|
|
# https://git.stack-source.com/msb/vmail-stack
|
|
# 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)
|
|
|
|
# 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
|
|
dbquery="SELECT id FROM vm_autoresponders WHERE mbox='$mbox' AND 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
|