initial vmail-mboxes-del.sh
This commit is contained in:
parent
c851e72c57
commit
818a659ec6
11
bin/vmail-mboxes-del.sh
Normal file → Executable file
11
bin/vmail-mboxes-del.sh
Normal file → Executable file
|
@ -30,7 +30,7 @@ if [ -n "$1" ]; then
|
||||||
email=$1
|
email=$1
|
||||||
shift
|
shift
|
||||||
if [[ $email =~ "@" ]] ; then
|
if [[ $email =~ "@" ]] ; then
|
||||||
local_part=${email%@*}
|
mbox=${email%@*}
|
||||||
domain=${email##*@}
|
domain=${email##*@}
|
||||||
if ! vmail::validate_domain $domain; then
|
if ! vmail::validate_domain $domain; then
|
||||||
echo "ERROR: $domain is not a valid domain name."
|
echo "ERROR: $domain is not a valid domain name."
|
||||||
|
@ -63,7 +63,7 @@ dbcmd="mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE"
|
||||||
dbcmdopts="-s -r -N -e"
|
dbcmdopts="-s -r -N -e"
|
||||||
|
|
||||||
# get email address id which also works to confirm address exists
|
# get email address id which also works to confirm address exists
|
||||||
dbquery="SELECT vm_mboxes.id FROM vm_mboxes, vm_domains WHERE vm_mboxes.mbox='$local_part' AND vm_mboxes.domain_id=vm_domains.id AND vm_domains.domain='$domain'"
|
dbquery="SELECT vm_mboxes.id FROM vm_mboxes, vm_domains WHERE vm_mboxes.mbox='$mbox' AND vm_mboxes.domain_id=vm_domains.id AND vm_domains.domain='$domain'"
|
||||||
mboxes_id=`$dbcmd $dbcmdopts "$dbquery"`
|
mboxes_id=`$dbcmd $dbcmdopts "$dbquery"`
|
||||||
|
|
||||||
if [ -z "$mboxes_id" ]; then
|
if [ -z "$mboxes_id" ]; then
|
||||||
|
@ -71,6 +71,7 @@ if [ -z "$mboxes_id" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
elif [ "$mboxes_id" -gt '0' ]; then
|
elif [ "$mboxes_id" -gt '0' ]; then
|
||||||
if [ -n "$force" ] || vmail::yesno "Delete $email now?"; then
|
if [ -n "$force" ] || vmail::yesno "Delete $email now?"; then
|
||||||
|
# once ON DELETE CASCADE is set only this first query is needed for vm_* tables
|
||||||
dbquery="DELETE FROM vm_mboxes WHERE vm_mboxes.id='$mboxes_id'"
|
dbquery="DELETE FROM vm_mboxes WHERE vm_mboxes.id='$mboxes_id'"
|
||||||
echo $dbcmd $dbcmdopts "\"$dbquery\""
|
echo $dbcmd $dbcmdopts "\"$dbquery\""
|
||||||
dbquery="DELETE FROM sa_userpref WHERE username='$email'"
|
dbquery="DELETE FROM sa_userpref WHERE username='$email'"
|
||||||
|
@ -85,12 +86,14 @@ elif [ "$mboxes_id" -gt '0' ]; then
|
||||||
echo $dbcmd $dbcmdopts "\"$dbquery\""
|
echo $dbcmd $dbcmdopts "\"$dbquery\""
|
||||||
dbquery="DELETE FROM vm_greylisting WHERE recipient='$email'"
|
dbquery="DELETE FROM vm_greylisting WHERE recipient='$email'"
|
||||||
echo $dbcmd $dbcmdopts "\"$dbquery\""
|
echo $dbcmd $dbcmdopts "\"$dbquery\""
|
||||||
dbquery="DELETE FROM vm_greylisting WHERE recipient LIKE '$local_part+%@$domain'"
|
dbquery="DELETE FROM vm_greylisting WHERE recipient LIKE '$mbox+%@$domain'"
|
||||||
echo $dbcmd $dbcmdopts "\"$dbquery\""
|
echo $dbcmd $dbcmdopts "\"$dbquery\""
|
||||||
# this should be sufficient for rc due to ON DELETE CASCADE foreign key references
|
# this should be sufficient for rc due to ON DELETE CASCADE foreign key references
|
||||||
dbquery="DELETE FROM rc_users WHERE username='$email'"
|
dbquery="DELETE FROM rc_users WHERE username='$email'"
|
||||||
echo $dbcmd $dbcmdopts "\"$dbquery\""
|
echo $dbcmd $dbcmdopts "\"$dbquery\""
|
||||||
echo "rm -r $VMAIL_DIR/$domain/$local_part"
|
if [ -d "$VMAIL_DIR/$domain/$mbox" ]; then
|
||||||
|
echo "rm -r $VMAIL_DIR/$domain/$mbox"
|
||||||
|
fi
|
||||||
echo "SUCCESS: $email removed from system."
|
echo "SUCCESS: $email removed from system."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue
Block a user