# get aliases id which also works to confirm alias exists
dbquery="SELECT vm_aliases.id FROM vm_aliases, vm_mboxes, vm_domains WHERE vm_aliases.alias='$alias' AND vm_aliases.mbox_id=vm_mboxes.id AND vm_mboxes.mbox='$mbox' AND vm_mboxes.domain_id=vm_domains.id AND vm_domains.domain='$domain'"
vm_aliases_id=`$dbcmd$dbcmdopts"$dbquery"`
if[[ -z $vm_aliases_id]];then
echo"ERROR: Alias $alias@$domain -> $email does not exist."
exit1
elif["$vm_aliases_id" -gt '0'];then
dbquery="DELETE FROM vm_aliases WHERE vm_aliases.id='$vm_aliases_id'"
echo$dbquery
eval$dbcmd$dbcmdopts"\"$dbquery\""
echo"SUCCESS: Alias $alias@$domain -> $email removed from system."
exit0
else
echo"ERROR: System error querying vmail database"
exit1
fi
# if domain set then delete any and all aliases
elif[[ -n $domain]];then
# get alias id array
dbquery="SELECT vm_aliases.id FROM vm_aliases, vm_mboxes, vm_domains WHERE vm_aliases.alias='$alias' AND vm_aliases.mbox_id=vm_mboxes.id AND vm_mboxes.domain_id=vm_domains.id AND vm_domains.domain='$domain'"