v-add-mail-account-alias 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. # info: add mail account alias aka nickname
  3. # options: USER DOMAIN ACCOUNT ALIAS
  4. #
  5. # The function add new email 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. is_mail_new "$malias"
  34. #----------------------------------------------------------#
  35. # Action #
  36. #----------------------------------------------------------#
  37. # Adding exim alias
  38. if [[ "$MAIL_SYSTEM" =~ exim ]]; then
  39. str="$malias@$domain_idn:$account@$domain_idn"
  40. echo "$str" >> $HOMEDIR/$user/conf/mail/$domain/aliases
  41. fi
  42. #----------------------------------------------------------#
  43. # Vesta #
  44. #----------------------------------------------------------#
  45. # Adding vesta alias
  46. aliases=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$ALIAS')
  47. if [ -z "$aliases" ]; then
  48. aliases="$malias"
  49. else
  50. aliases="$aliases,$malias"
  51. fi
  52. update_object_value "mail/$domain" 'ACCOUNT' "$account" '$ALIAS' "$aliases"
  53. # Logging
  54. log_history "added alias $malias to $account@$domain "
  55. log_event "$OK" "$ARGUMENTS"
  56. exit