v-delete-mail-account 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. # info: delete mail account
  3. # options: USER DOMAIN ACCOUNT
  4. #
  5. # The function deletes email account.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. user=$1
  11. domain=$2
  12. account=$3
  13. # Includes
  14. source $VESTA/func/main.sh
  15. source $VESTA/func/domain.sh
  16. source $VESTA/conf/vesta.conf
  17. # Additional argument formatting
  18. format_domain
  19. format_domain_idn
  20. #----------------------------------------------------------#
  21. # Verifications #
  22. #----------------------------------------------------------#
  23. check_args '3' "$#" 'USER DOMAIN ACCOUNT'
  24. is_format_valid 'user' 'domain' 'account'
  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. #----------------------------------------------------------#
  33. # Action #
  34. #----------------------------------------------------------#
  35. if [[ "$MAIL_SYSTEM" =~ exim ]]; then
  36. aliases=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$ALIAS')
  37. for al in ${aliases//,/ }; do
  38. sed -i "/^$al@$domain_idn:$account/d" \
  39. $HOMEDIR/$user/conf/mail/$domain/aliases
  40. done
  41. sed -i "/^$account@$domain_idn:/d" $HOMEDIR/$user/conf/mail/$domain/aliases
  42. sed -i "/^$account:/d" $HOMEDIR/$user/conf/mail/$domain/passwd
  43. rm -rf $HOMEDIR/$user/mail/$domain/$account
  44. fi
  45. #----------------------------------------------------------#
  46. # Vesta #
  47. #----------------------------------------------------------#
  48. # Update config
  49. sed -i "/ACCOUNT='$account'/d" $USER_DATA/mail/$domain.conf
  50. # Decrease mail accounts counter
  51. accounts=$(wc -l $USER_DATA/mail/$domain.conf | cut -f 1 -d ' ')
  52. decrease_user_value "$user" '$U_MAIL_ACCOUNTS'
  53. update_object_value 'mail' 'DOMAIN' "$domain" '$ACCOUNTS' "$accounts"
  54. # Logging
  55. log_history "deleted $account@$domain mail account"
  56. log_event "$OK" "$ARGUMENTS"
  57. exit