vmail-stack/bin/vmail-forwards-del.sh

52 lines
1.3 KiB
Bash
Raw Normal View History

2021-02-16 13:27:27 -08: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)
2021-02-16 13:27:27 -08:00
2021-04-02 12:02:50 -07:00
# load include file
source $(dirname $0)/vmail.sh
2021-02-16 13:27:27 -08:00
help()
{
thisfilename=$(basename -- "$0")
echo "$thisfilename"
echo "Delete email forward from vmail database."
echo ""
2021-10-15 15:17:29 -07:00
echo "usage: $thisfilename -e email"
2021-02-16 13:27:27 -08:00
echo ""
echo " -h Print this help."
2021-10-15 15:17:29 -07:00
echo " -e <email> Email address to remove forwarding from."
2021-02-16 13:27:27 -08:00
exit
}
2021-10-15 15:17:29 -07:00
vmail:getoptions "$@"
2021-02-16 13:27:27 -08:00
2021-10-15 15:17:29 -07:00
# check for email
if [[ -z $email ]]; then
echo "email name is required"
exit
fi
2021-02-16 13:27:27 -08:00
# 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 forward id which also works to confirm alias exists
dbquery="SELECT id FROM vm_forwards WHERE mbox='$mbox' AND domain='$domain';"
forwards_id=`$dbcmd $dbcmdopts "$dbquery"`
2021-02-16 13:27:27 -08:00
2022-11-29 16:33:15 -08:00
if [[ -z $forwards_id ]]; then
2021-02-16 13:27:27 -08:00
echo "ERROR: Forward for $email does not exist."
exit 1
2022-11-29 16:33:15 -08:00
elif [[ $forwards_id -gt '0' ]]; then
dbquery="DELETE FROM vm_forwards WHERE id='$forwards_id';"
2021-02-16 13:27:27 -08:00
eval $dbcmd $dbcmdopts \"$dbquery\"
echo "SUCCESS: Forward for $email removed from system."
exit 0
else
echo "ERROR: System error querying vmail database"
exit 1
fi