Skip to content

Commit b825490

Browse files
committed
mail api 100% completed
1 parent f2133f9 commit b825490

24 files changed

+1159
-50
lines changed

bin/v_add_mail_account_alias

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# info: add mail account alias aka nickname
33
# options: user domain account alias
44
#
5-
# The function add new email account.
5+
# The function add new email alias.
66

77

88
#----------------------------------------------------------#

bin/v_add_mail_account_autoreply

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ is_object_valid 'mail' 'DOMAIN' "$domain"
3636
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
3737
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
3838
is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
39-
is_object_value_empty "mail/$domain" 'ACCOUNT' "$domain" '$AUTOREPLY'
39+
# is_object_value_empty "mail/$domain" 'ACCOUNT' "$account" '$AUTOREPLY'
4040

4141

4242
#----------------------------------------------------------#
@@ -55,7 +55,7 @@ chmod 660 $HOMEDIR/$user/conf/mail/$domain/autoreply.$account.msg
5555
# Adding vesta alias
5656
echo -e "$autoreply" > $USER_DATA/mail/$account@$domain.msg
5757
chmod 660 $USER_DATA/mail/$account@$domain.msg
58-
update_object_value "mail/$domain" 'ACCOUNT' "$domain" '$AUTOREPLY' 'yes'
58+
update_object_value "mail/$domain" 'ACCOUNT' "$account" '$AUTOREPLY' 'yes'
5959

6060
# Logging
6161
log_history "$EVENT"

bin/v_add_mail_account_forward

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
# info: add mail account forward address
3+
# options: user domain account forward
4+
#
5+
# The function add new email account.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=$1
14+
domain=$(idn -t --quiet -u "$2" )
15+
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
16+
domain_idn=$(idn -t --quiet -a "$domain")
17+
account=$3
18+
forward=$4
19+
20+
# Includes
21+
source $VESTA/conf/vesta.conf
22+
source $VESTA/func/shared.sh
23+
source $VESTA/func/domain.sh
24+
25+
26+
#----------------------------------------------------------#
27+
# Verifications #
28+
#----------------------------------------------------------#
29+
30+
check_args '4' "$#" 'user domain account forward'
31+
validate_format 'user' 'domain' 'account' 'forward'
32+
is_system_enabled "$MAIL_SYSTEM"
33+
is_object_valid 'user' 'USER' "$user"
34+
is_object_unsuspended 'user' 'USER' "$user"
35+
is_object_valid 'mail' 'DOMAIN' "$domain"
36+
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
37+
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
38+
is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
39+
fwd=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$FWD')
40+
if [ ! -z "$(echo $fwd | grep -w $forward)" ]; then
41+
echo "Error: forward $forward exists"
42+
log_event "$E_EXISTS $EVENT"
43+
exit $E_EXISTS
44+
fi
45+
46+
47+
#----------------------------------------------------------#
48+
# Action #
49+
#----------------------------------------------------------#
50+
51+
# Adding forward to exim
52+
if [ -z "$fwd" ]; then
53+
fwd="$forward"
54+
else
55+
fwd="$fwd,$forward"
56+
fi
57+
58+
sed -i "/^$account@$domain:/ d" $HOMEDIR/$user/conf/mail/$domain/aliases
59+
echo "$account@$domain:$fwd" >> $HOMEDIR/$user/conf/mail/$domain/aliases
60+
61+
62+
#----------------------------------------------------------#
63+
# Vesta #
64+
#----------------------------------------------------------#
65+
66+
# Updating config
67+
update_object_value "mail/$domain" 'ACCOUNT' "$account" '$FWD' "$fwd"
68+
69+
# Logging
70+
log_history "$EVENT"
71+
log_event "$OK" "$EVENT"
72+
73+
exit

bin/v_change_mail_account_password

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
# info: change mail account password
3+
# options: user domain account password
4+
#
5+
# The function changes email account password.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=$1
14+
domain=$(idn -t --quiet -u "$2" )
15+
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
16+
domain_idn=$(idn -t --quiet -a "$domain")
17+
account=$3
18+
password=$4
19+
20+
# Includes
21+
source $VESTA/conf/vesta.conf
22+
source $VESTA/func/shared.sh
23+
source $VESTA/func/domain.sh
24+
25+
26+
#----------------------------------------------------------#
27+
# Verifications #
28+
#----------------------------------------------------------#
29+
30+
check_args '4' "$#" 'user domain account password'
31+
validate_format 'user' 'domain' 'account' 'password'
32+
is_system_enabled "$MAIL_SYSTEM"
33+
is_object_valid 'user' 'USER' "$user"
34+
is_object_unsuspended 'user' 'USER' "$user"
35+
is_object_valid 'mail' 'DOMAIN' "$domain"
36+
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
37+
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
38+
is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
39+
40+
41+
#----------------------------------------------------------#
42+
# Action #
43+
#----------------------------------------------------------#
44+
md5=$(/usr/sbin/dovecotpw -s md5 -p "$password")
45+
sed -i "/^$account:/d" $HOMEDIR/$user/conf/mail/$domain/passwd
46+
str="$account:$md5:$user:mail::$HOMEDIR/$user:$quota"
47+
echo $str >> $HOMEDIR/$user/conf/mail/$domain/passwd
48+
49+
50+
#----------------------------------------------------------#
51+
# Vesta #
52+
#----------------------------------------------------------#
53+
54+
# Update md5
55+
update_object_value "mail/$domain" 'ACCOUNT' "$account" '$MD5' "$md5"
56+
57+
# Hiding password
58+
EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT'"
59+
EVENT="$EVENT ARGUMENTS='$user $domain *****'"
60+
61+
# Logging
62+
log_history "$EVENT"
63+
log_event "$OK" "$EVENT"
64+
65+
exit

bin/v_change_mail_account_quota

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
# info: change mail account quota
3+
# options: user domain account quota
4+
#
5+
# The function changes email account disk quota.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=$1
14+
domain=$(idn -t --quiet -u "$2" )
15+
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
16+
domain_idn=$(idn -t --quiet -a "$domain")
17+
account=$3
18+
quota=$4
19+
20+
# Includes
21+
source $VESTA/conf/vesta.conf
22+
source $VESTA/func/shared.sh
23+
source $VESTA/func/domain.sh
24+
25+
26+
#----------------------------------------------------------#
27+
# Verifications #
28+
#----------------------------------------------------------#
29+
30+
check_args '4' "$#" 'user domain account quota'
31+
validate_format 'user' 'domain' 'account' 'quota'
32+
is_system_enabled "$MAIL_SYSTEM"
33+
is_object_valid 'user' 'USER' "$user"
34+
is_object_unsuspended 'user' 'USER' "$user"
35+
is_object_valid 'mail' 'DOMAIN' "$domain"
36+
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
37+
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
38+
is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
39+
40+
41+
#----------------------------------------------------------#
42+
# Action #
43+
#----------------------------------------------------------#
44+
45+
md5=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$MD5')
46+
sed -i "/^$account:/d" $HOMEDIR/$user/conf/mail/$domain/passwd
47+
str="$account:$md5:$user:mail::$HOMEDIR/$user:$quota"
48+
echo $str >> $HOMEDIR/$user/conf/mail/$domain/passwd
49+
50+
51+
#----------------------------------------------------------#
52+
# Vesta #
53+
#----------------------------------------------------------#
54+
55+
# Update quota
56+
update_object_value "mail/$domain" 'ACCOUNT' "$account" '$QUOTA' "$quota"
57+
58+
# Logging
59+
log_history "$EVENT"
60+
log_event "$OK" "$EVENT"
61+
62+
exit

bin/v_delete_mail_account

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
# info: delete mail account
3+
# options: user domain account
4+
#
5+
# The function deletes email account.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=$1
14+
domain=$(idn -t --quiet -u "$2" )
15+
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
16+
domain_idn=$(idn -t --quiet -a "$domain")
17+
account=$3
18+
19+
# Includes
20+
source $VESTA/conf/vesta.conf
21+
source $VESTA/func/shared.sh
22+
source $VESTA/func/domain.sh
23+
24+
25+
#----------------------------------------------------------#
26+
# Verifications #
27+
#----------------------------------------------------------#
28+
29+
check_args '3' "$#" 'user domain account'
30+
validate_format 'user' 'domain' 'account'
31+
is_system_enabled "$MAIL_SYSTEM"
32+
is_object_valid 'user' 'USER' "$user"
33+
is_object_unsuspended 'user' 'USER' "$user"
34+
is_object_valid 'mail' 'DOMAIN' "$domain"
35+
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
36+
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
37+
is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
38+
39+
40+
#----------------------------------------------------------#
41+
# Action #
42+
#----------------------------------------------------------#
43+
aliases=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$ALIAS')
44+
for al in ${aliases//,/ }; do
45+
sed -i "/^$al@$domain:$account/d" $HOMEDIR/$user/conf/mail/$domain/aliases
46+
done
47+
48+
sed -i "/^$account@$domain:/d" $HOMEDIR/$user/conf/mail/$domain/aliases
49+
sed -i "/^$account:/d" $HOMEDIR/$user/conf/mail/$domain/passwd
50+
rm -rf $HOMEDIR/$user/mail/$domain/$account
51+
52+
53+
#----------------------------------------------------------#
54+
# Vesta #
55+
#----------------------------------------------------------#
56+
57+
# Update config
58+
sed -i "/ACCOUNT='$account'/d" $USER_DATA/mail/$domain.conf
59+
60+
61+
# Logging
62+
log_history "$EVENT"
63+
log_event "$OK" "$EVENT"
64+
65+
exit

bin/v_delete_mail_account_alias

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
# info: delete mail account alias aka nickname
3+
# options: user domain account alias
4+
#
5+
# The function deletes email account alias.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=$1
14+
domain=$(idn -t --quiet -u "$2" )
15+
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
16+
domain_idn=$(idn -t --quiet -a "$domain")
17+
account=$3
18+
malias=$4
19+
20+
# Includes
21+
source $VESTA/conf/vesta.conf
22+
source $VESTA/func/shared.sh
23+
source $VESTA/func/domain.sh
24+
25+
26+
#----------------------------------------------------------#
27+
# Verifications #
28+
#----------------------------------------------------------#
29+
30+
check_args '4' "$#" 'user domain account alias'
31+
validate_format 'user' 'domain' 'account' 'malias'
32+
is_system_enabled "$MAIL_SYSTEM"
33+
is_object_valid 'user' 'USER' "$user"
34+
is_object_unsuspended 'user' 'USER' "$user"
35+
is_object_valid 'mail' 'DOMAIN' "$domain"
36+
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
37+
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
38+
is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
39+
aliases=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$ALIAS')
40+
if [ -z "$(echo $aliases | grep -w $malias)" ]; then
41+
echo "Error: alias $malias is not exist"
42+
log_event "$E_NOTEXIST $EVENT"
43+
exit $E_NOTEXIST
44+
fi
45+
46+
47+
#----------------------------------------------------------#
48+
# Action #
49+
#----------------------------------------------------------#
50+
51+
sed -i "/^$malias@$domain:$account/d" $HOMEDIR/$user/conf/mail/$domain/aliases
52+
aliases=$(echo "$aliases" |\
53+
sed -e "s/,/\n/g"|\
54+
sed -e "s/^$malias$//g"|\
55+
sed -e "/^$/d"|\
56+
sed -e ':a;N;$!ba;s/\n/,/g')
57+
58+
59+
#----------------------------------------------------------#
60+
# Vesta #
61+
#----------------------------------------------------------#
62+
63+
# Update config
64+
update_object_value "mail/$domain" 'ACCOUNT' "$account" '$ALIAS' "$aliases"
65+
66+
# Logging
67+
log_history "$EVENT"
68+
log_event "$OK" "$EVENT"
69+
70+
exit

0 commit comments

Comments
 (0)