v_delete_mail_account_forward 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. # info: delte 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 defenition
  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/conf/vesta.conf
  18. source $VESTA/func/main.sh
  19. source $VESTA/func/domain.sh
  20. #----------------------------------------------------------#
  21. # Verifications #
  22. #----------------------------------------------------------#
  23. check_args '4' "$#" 'user domain account forward'
  24. validate_format 'user' 'domain' 'account' 'forward'
  25. is_system_enabled "$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 is not exist"
  35. log_event "$E_NOTEXIST $EVENT"
  36. exit $E_NOTEXIST
  37. fi
  38. #----------------------------------------------------------#
  39. # Action #
  40. #----------------------------------------------------------#
  41. fwd=$(echo "$fwd" |\
  42. sed -e "s/,/\n/g"|\
  43. sed -e "s/^$forward$//g"|\
  44. sed -e "/^$/d"|\
  45. sed -e ':a;N;$!ba;s/\n/,/g')
  46. sed -i "/^$account@$domain:/ d" $HOMEDIR/$user/conf/mail/$domain/aliases
  47. echo "$account@$domain:$fwd" >> $HOMEDIR/$user/conf/mail/$domain/aliases
  48. #----------------------------------------------------------#
  49. # Vesta #
  50. #----------------------------------------------------------#
  51. # Update config
  52. update_object_value "mail/$domain" 'ACCOUNT' "$account" '$FWD' "$fwd"
  53. # Logging
  54. log_history "$EVENT"
  55. log_event "$OK" "$EVENT"
  56. exit