Skip to content

Commit c538920

Browse files
authored
Merge pull request hestiacp#4351 from Anuril/fix-mail-alias-error
2 parents 695029e + 56f9a93 commit c538920

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

bin/v-delete-mail-account-alias

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ is_object_valid 'user' 'USER' "$user"
4242
is_object_valid 'mail' 'DOMAIN' "$domain"
4343
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
4444
aliases=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$ALIAS')
45-
if [ -z "$(echo $aliases | grep -w $malias)" ]; then
45+
if [ -z "$(echo $aliases | grep -w -e $malias)" ]; then
4646
echo "Error: alias $malias doesn't exist"
4747
log_event "$E_NOTEXIST $ARGUMENTS"
4848
exit "$E_NOTEXIST"

func/main.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -707,17 +707,19 @@ sync_cron_jobs() {
707707
# Validates Local part email and mail alias
708708
is_localpart_format_valid() {
709709
if [ ${#1} -eq 1 ]; then
710-
if ! [[ "$1" =~ ^^[[:alnum:]]$ ]]; then
710+
if ! [[ "$1" =~ ^[[:alnum:]]$ ]]; then
711711
check_result "$E_INVALID" "invalid $2 format :: $1"
712712
fi
713713
else
714714
if [ -n "$3" ]; then
715715
maxlenght=$(($3 - 2))
716-
if ! [[ "$1" =~ ^[[:alnum:]][-|\.|_[:alnum:]]{0,$maxlenght}[[:alnum:]]$ ]]; then
716+
# Allow leading and trailing special characters by adjusting the regex
717+
if ! [[ "$1" =~ ^[[:alnum:]_.-][[:alnum:]_.-]{0,$maxlenght}[[:alnum:]_.-]$ ]]; then
717718
check_result "$E_INVALID" "invalid $2 format :: $1"
718719
fi
719720
else
720-
if ! [[ "$1" =~ ^[[:alnum:]][-|\.|_[:alnum:]]{0,28}[[:alnum:]]$ ]]; then
721+
# Allow leading and trailing special characters by adjusting the regex
722+
if ! [[ "$1" =~ ^[[:alnum:]_.-][[:alnum:]_.-]{0,28}[[:alnum:]_.-]$ ]]; then
721723
check_result "$E_INVALID" "invalid $2 format :: $1"
722724
fi
723725
fi

test/test.bats

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,13 +1701,21 @@ function check_ip_not_banned(){
17011701
}
17021702

17031703
@test "MAIL: Add account alias Invalid length" {
1704-
run v-add-mail-account-alias $user $domain test 'hestiacp-realy-rocks-but-i-want-to-have-feature-xyz-and-i-want-it-now'
1704+
run v-add-mail-account-alias $user $domain test 'hestiacp-really-rocks-but-i-want-to-have-feature-xyz-and-i-want-it-now'
17051705
assert_failure $E_INVALID
17061706
}
17071707
@test "MAIL: Add account alias Invalid" {
1708-
run v-add-mail-account-alias $user $domain test '-test'
1708+
run v-add-mail-account-alias $user $domain test 'test+123'
17091709
assert_failure $E_INVALID
17101710
}
1711+
@test "MAIL: Add account alias starting with -" {
1712+
run v-add-mail-account-alias $user $domain test '-test'
1713+
assert_success
1714+
}
1715+
@test "MAIL: Add account alias ending with -" {
1716+
run v-add-mail-account-alias $user $domain test 'test-'
1717+
assert_success
1718+
}
17111719
@test "MAIL: Add account alias Invalid 2" {
17121720
run v-add-mail-account-alias $user $domain test 'hestia@test'
17131721
assert_failure $E_INVALID

0 commit comments

Comments
 (0)