v-delete-mail-account-forward 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/bash
  2. # info: delete mail account forward
  3. # options: USER DOMAIN ACCOUNT EMAIL
  4. #
  5. # The function add delete email account forward address.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. user=$1
  11. domain=$2
  12. account=$3
  13. forward=$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 FORWARD'
  25. is_format_valid 'user' 'domain' 'account' 'forward'
  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. fwd=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$FWD')
  34. if [ -z "$(echo $fwd | grep -w $forward)" ]; then
  35. check_result $E_NOTEXIST "forward $forward doesn't exist"
  36. fi
  37. #----------------------------------------------------------#
  38. # Action #
  39. #----------------------------------------------------------#
  40. # Define new fwd string
  41. fwd=$(echo "$fwd" |\
  42. sed "s/,/\n/g"|\
  43. sed "s/^$forward$//g"|\
  44. sed "/^$/d"|\
  45. sed ':a;N;$!ba;s/\n/,/g')
  46. # Deleting exim forward
  47. if [[ "$MAIL_SYSTEM" =~ exim ]]; then
  48. sed -i "/^$account@$domain_idn:/ d" $HOMEDIR/$user/conf/mail/$domain/aliases
  49. echo "$account@$domain_idn:$fwd" >> $HOMEDIR/$user/conf/mail/$domain/aliases
  50. fi
  51. #----------------------------------------------------------#
  52. # Vesta #
  53. #----------------------------------------------------------#
  54. # Updating config
  55. update_object_value "mail/$domain" 'ACCOUNT' "$account" '$FWD' "$fwd"
  56. # Logging
  57. log_history "deleted $forward forward on $account@$domain"
  58. log_event "$OK" "$ARGUMENTS"
  59. exit