|
| 1 | +#!/bin/bash |
| 2 | +# info: delete mail account alias aka nickname |
| 3 | +# options: user domain account alias |
| 4 | +# |
| 5 | +# The function deletes email account alias. |
| 6 | + |
| 7 | + |
| 8 | +#----------------------------------------------------------# |
| 9 | +# Variable&Function # |
| 10 | +#----------------------------------------------------------# |
| 11 | + |
| 12 | +# Argument defenition |
| 13 | +user=$1 |
| 14 | +domain=$(idn -t --quiet -u "$2" ) |
| 15 | +domain=$(echo $domain | tr '[:upper:]' '[:lower:]') |
| 16 | +domain_idn=$(idn -t --quiet -a "$domain") |
| 17 | +account=$3 |
| 18 | +malias=$4 |
| 19 | + |
| 20 | +# Includes |
| 21 | +source $VESTA/conf/vesta.conf |
| 22 | +source $VESTA/func/shared.sh |
| 23 | +source $VESTA/func/domain.sh |
| 24 | + |
| 25 | + |
| 26 | +#----------------------------------------------------------# |
| 27 | +# Verifications # |
| 28 | +#----------------------------------------------------------# |
| 29 | + |
| 30 | +check_args '4' "$#" 'user domain account alias' |
| 31 | +validate_format 'user' 'domain' 'account' 'malias' |
| 32 | +is_system_enabled "$MAIL_SYSTEM" |
| 33 | +is_object_valid 'user' 'USER' "$user" |
| 34 | +is_object_unsuspended 'user' 'USER' "$user" |
| 35 | +is_object_valid 'mail' 'DOMAIN' "$domain" |
| 36 | +is_object_unsuspended 'mail' 'DOMAIN' "$domain" |
| 37 | +is_object_valid "mail/$domain" 'ACCOUNT' "$account" |
| 38 | +is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account" |
| 39 | +aliases=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$ALIAS') |
| 40 | +if [ -z "$(echo $aliases | grep -w $malias)" ]; then |
| 41 | + echo "Error: alias $malias is not exist" |
| 42 | + log_event "$E_NOTEXIST $EVENT" |
| 43 | + exit $E_NOTEXIST |
| 44 | +fi |
| 45 | + |
| 46 | + |
| 47 | +#----------------------------------------------------------# |
| 48 | +# Action # |
| 49 | +#----------------------------------------------------------# |
| 50 | + |
| 51 | +sed -i "/^$malias@$domain:$account/d" $HOMEDIR/$user/conf/mail/$domain/aliases |
| 52 | +aliases=$(echo "$aliases" |\ |
| 53 | + sed -e "s/,/\n/g"|\ |
| 54 | + sed -e "s/^$malias$//g"|\ |
| 55 | + sed -e "/^$/d"|\ |
| 56 | + sed -e ':a;N;$!ba;s/\n/,/g') |
| 57 | + |
| 58 | + |
| 59 | +#----------------------------------------------------------# |
| 60 | +# Vesta # |
| 61 | +#----------------------------------------------------------# |
| 62 | + |
| 63 | +# Update config |
| 64 | +update_object_value "mail/$domain" 'ACCOUNT' "$account" '$ALIAS' "$aliases" |
| 65 | + |
| 66 | +# Logging |
| 67 | +log_history "$EVENT" |
| 68 | +log_event "$OK" "$EVENT" |
| 69 | + |
| 70 | +exit |
0 commit comments