Skip to content

Commit d6beef8

Browse files
authored
Fix is_mail_new function (hestiacp#3785)
* Add new tests for mail * Fix is_new_mail function in domain.sh
1 parent 386a033 commit d6beef8

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

func/domain.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -679,14 +679,16 @@ is_mail_domain_new() {
679679
is_mail_new() {
680680
check_acc=$(grep "ACCOUNT='$1'" $USER_DATA/mail/$domain.conf)
681681
if [ -n "$check_acc" ]; then
682-
check_result "$E_EXISTS" "mail account $1 is already exists"
682+
check_result "$E_EXISTS" "mail account $1 already exists"
683683
fi
684684
check_als=$(awk -F "ALIAS='" '{print $2}' $USER_DATA/mail/$domain.conf)
685-
match=$(echo $check_als | cut -d "'" -f1)
686-
parse_object_kv_list $(grep "ALIAS='$match'" $USER_DATA/mail/$domain.conf)
687-
check_als=$(echo ",$ALIAS," | grep ",$1,")
688-
if [ -n "$check_als" ]; then
689-
check_result "$E_EXISTS" "mail alias $1 is already exists"
685+
match=$(echo "$check_als" | cut -f 1 -d "'" | grep $1)
686+
if [ -n "$match" ]; then
687+
parse_object_kv_list $(grep "ALIAS='$match'" $USER_DATA/mail/$domain.conf)
688+
check_als=$(echo ",$ALIAS," | grep ",$1,")
689+
if [ -n "$check_als" ]; then
690+
check_result "$E_EXISTS" "mail alias $1 already exists"
691+
fi
690692
fi
691693
}
692694

test/test.bats

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,13 +1571,49 @@ function check_ip_not_banned(){
15711571
assert_failure $E_EXISTS
15721572
}
15731573

1574+
@test "MAIL: Add account 2" {
1575+
run v-add-mail-account $user $domain random "$userpass2"
1576+
assert_success
1577+
assert_file_contains /etc/exim4/domains/$domain/limits "random@$domain"
1578+
refute_output
1579+
}
1580+
15741581
@test "MAIL: Add account alias" {
15751582
run v-add-mail-account-alias $user $domain test hestiacprocks
15761583
assert_success
15771584
assert_file_contains /etc/exim4/domains/$domain/aliases "hestiacprocks@$domain"
15781585
refute_output
15791586
}
15801587

1588+
@test "MAIL: Add account alias 2" {
1589+
run v-add-mail-account-alias $user $domain test hestiacprocks2
1590+
assert_success
1591+
assert_file_contains /etc/exim4/domains/$domain/aliases "hestiacprocks2@$domain"
1592+
refute_output
1593+
}
1594+
1595+
@test "MAIL: Add account alias 3" {
1596+
run v-add-mail-account-alias $user $domain test hestiacp
1597+
assert_success
1598+
assert_file_contains /etc/exim4/domains/$domain/aliases "hestiacp@$domain"
1599+
refute_output
1600+
}
1601+
1602+
@test "MAIL: Add account 3" {
1603+
run v-add-mail-account $user $domain hestia "$userpass2"
1604+
assert_success
1605+
assert_file_contains /etc/exim4/domains/$domain/limits "hestia@$domain"
1606+
refute_output
1607+
}
1608+
1609+
@test "MAIL: Add account 4" {
1610+
run v-add-mail-account $user $domain hestiarocks3 "$userpass2"
1611+
assert_success
1612+
assert_file_contains /etc/exim4/domains/$domain/limits "hestiarocks3@$domain"
1613+
refute_output
1614+
}
1615+
1616+
15811617
@test "MAIL: Add account alias Invalid length" {
15821618
run v-add-mail-account-alias $user $domain test 'hestiacp-realy-rocks-but-i-want-to-have-feature-xyz-and-i-want-it-now'
15831619
assert_failure $E_INVALID

0 commit comments

Comments
 (0)