v-delete-mail-account-alias 2.2 KB

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