v-delete-mail-account-forward 2.3 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=$(idn -t --quiet -u "$2" )
  12. domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
  13. domain_idn=$(idn -t --quiet -a "$domain")
  14. account=$3
  15. forward=$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 FORWARD'
  24. is_format_valid 'user' 'domain' 'account' 'forward'
  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. fwd=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$FWD')
  33. if [ -z "$(echo $fwd | grep -w $forward)" ]; then
  34. echo "Error: forward $forward doesn't exist"
  35. log_event "$E_NOTEXIST $ARGUMENTS"
  36. exit $E_NOTEXIST
  37. fi
  38. #----------------------------------------------------------#
  39. # Action #
  40. #----------------------------------------------------------#
  41. # Define new fwd string
  42. fwd=$(echo "$fwd" |\
  43. sed "s/,/\n/g"|\
  44. sed "s/^$forward$//g"|\
  45. sed "/^$/d"|\
  46. sed ':a;N;$!ba;s/\n/,/g')
  47. # Deleting exim forward
  48. if [[ "$MAIL_SYSTEM" =~ exim ]]; then
  49. sed -i "/^$account@$domain_idn:/ d" $HOMEDIR/$user/conf/mail/$domain/aliases
  50. echo "$account@$domain_idn:$fwd" >> $HOMEDIR/$user/conf/mail/$domain/aliases
  51. fi
  52. #----------------------------------------------------------#
  53. # Vesta #
  54. #----------------------------------------------------------#
  55. # Updating config
  56. update_object_value "mail/$domain" 'ACCOUNT' "$account" '$FWD' "$fwd"
  57. # Logging
  58. log_history "deleted $forward forward on $account@$domain"
  59. log_event "$OK" "$ARGUMENTS"
  60. exit