v-delete-mail-account-alias 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. user=$1
  11. domain=$(idn -t --quiet -u "$2" )
  12. domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
  13. domain_idn=$(idn -t --quiet -a "$domain")
  14. account=$3
  15. malias=$4
  16. # Includes
  17. source $VESTA/func/main.sh
  18. source $VESTA/func/domain.sh
  19. source $VESTA/conf/vesta.conf
  20. #----------------------------------------------------------#
  21. # Verifications #
  22. #----------------------------------------------------------#
  23. check_args '4' "$#" 'USER DOMAIN ACCOUNT ALIAS'
  24. is_format_valid 'user' 'domain' 'account' 'malias'
  25. is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
  26. is_object_valid 'user' 'USER' "$user"
  27. is_object_unsuspended 'user' 'USER' "$user"
  28. is_object_valid 'mail' 'DOMAIN' "$domain"
  29. is_object_unsuspended 'mail' 'DOMAIN' "$domain"
  30. is_object_valid "mail/$domain" 'ACCOUNT' "$account"
  31. is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
  32. aliases=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$ALIAS')
  33. if [ -z "$(echo $aliases | grep -w $malias)" ]; then
  34. echo "Error: alias $malias doesn't exist"
  35. log_event "$E_NOTEXIST $ARGUMENTS"
  36. exit $E_NOTEXIST
  37. fi
  38. #----------------------------------------------------------#
  39. # Action #
  40. #----------------------------------------------------------#
  41. if [[ "$MAIL_SYSTEM" =~ exim ]]; then
  42. sed -i "/^$malias@$domain_idn:$account/d" \
  43. $HOMEDIR/$user/conf/mail/$domain/aliases
  44. fi
  45. aliases=$(echo "$aliases" |\
  46. sed "s/,/\n/g"|\
  47. sed "s/^$malias$//g"|\
  48. sed "/^$/d"|\
  49. sed ':a;N;$!ba;s/\n/,/g')
  50. #----------------------------------------------------------#
  51. # Vesta #
  52. #----------------------------------------------------------#
  53. # Update config
  54. update_object_value "mail/$domain" 'ACCOUNT' "$account" '$ALIAS' "$aliases"
  55. # Logging
  56. log_history "deleted alias $malias on $account@$domain"
  57. log_event "$OK" "$ARGUMENTS"
  58. exit