vesta/bin/v-list-mail-account-autoreply
2013-10-27 13:54:31 +02:00

73 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
# info: list mail account autoreply
# options: USER DOMAIN ACCOUNT [FORMAT]
#
# The function of obtainin mail account autoreply message.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
domain=$2
account=$3
format=${4-shell}
# Includes
source $VESTA/func/main.sh
# Json function
json_list_msg() {
i='1' # iterator
echo '{'
echo -e "\t\"$account\": {"
echo " \"MSG\": \"$msg\""
echo -e "\t}\n}"
}
# Shell function
shell_list_msg() {
if [ ! -z "$msg" ]; then
echo -e "$msg"
fi
}
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER DOMAIN [FORMAT]'
is_object_valid 'user' 'USER' "$user"
is_object_valid 'mail' 'DOMAIN' "$domain"
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
if [ -e "$USER_DATA/mail/$account@$domain.msg" ]; then
msg=$(cat $USER_DATA/mail/$account@$domain.msg |\
sed ':a;N;$!ba;s/\n/\\n/g' )
fi
# Listing domains
case $format in
json) json_list_msg ;;
plain) nohead=1; shell_list_msg ;;
shell) shell_list_msg ;;
*) check_args '1' '0' '[FORMAT]'
esac
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
exit