Skip to content

Commit

Permalink
Merge pull request hestiacp#4351 from Anuril/fix-mail-alias-error
Browse files Browse the repository at this point in the history
  • Loading branch information
jaapmarcus authored Apr 4, 2024
2 parents 695029e + 56f9a93 commit c538920
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bin/v-delete-mail-account-alias
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ is_object_valid 'user' 'USER' "$user"
is_object_valid 'mail' 'DOMAIN' "$domain"
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
aliases=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$ALIAS')
if [ -z "$(echo $aliases | grep -w $malias)" ]; then
if [ -z "$(echo $aliases | grep -w -e $malias)" ]; then
echo "Error: alias $malias doesn't exist"
log_event "$E_NOTEXIST $ARGUMENTS"
exit "$E_NOTEXIST"
Expand Down
8 changes: 5 additions & 3 deletions func/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -707,17 +707,19 @@ sync_cron_jobs() {
# Validates Local part email and mail alias
is_localpart_format_valid() {
if [ ${#1} -eq 1 ]; then
if ! [[ "$1" =~ ^^[[:alnum:]]$ ]]; then
if ! [[ "$1" =~ ^[[:alnum:]]$ ]]; then
check_result "$E_INVALID" "invalid $2 format :: $1"
fi
else
if [ -n "$3" ]; then
maxlenght=$(($3 - 2))
if ! [[ "$1" =~ ^[[:alnum:]][-|\.|_[:alnum:]]{0,$maxlenght}[[:alnum:]]$ ]]; then
# Allow leading and trailing special characters by adjusting the regex
if ! [[ "$1" =~ ^[[:alnum:]_.-][[:alnum:]_.-]{0,$maxlenght}[[:alnum:]_.-]$ ]]; then
check_result "$E_INVALID" "invalid $2 format :: $1"
fi
else
if ! [[ "$1" =~ ^[[:alnum:]][-|\.|_[:alnum:]]{0,28}[[:alnum:]]$ ]]; then
# Allow leading and trailing special characters by adjusting the regex
if ! [[ "$1" =~ ^[[:alnum:]_.-][[:alnum:]_.-]{0,28}[[:alnum:]_.-]$ ]]; then
check_result "$E_INVALID" "invalid $2 format :: $1"
fi
fi
Expand Down
12 changes: 10 additions & 2 deletions test/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1701,13 +1701,21 @@ function check_ip_not_banned(){
}

@test "MAIL: Add account alias Invalid length" {
run v-add-mail-account-alias $user $domain test 'hestiacp-realy-rocks-but-i-want-to-have-feature-xyz-and-i-want-it-now'
run v-add-mail-account-alias $user $domain test 'hestiacp-really-rocks-but-i-want-to-have-feature-xyz-and-i-want-it-now'
assert_failure $E_INVALID
}
@test "MAIL: Add account alias Invalid" {
run v-add-mail-account-alias $user $domain test '-test'
run v-add-mail-account-alias $user $domain test 'test+123'
assert_failure $E_INVALID
}
@test "MAIL: Add account alias starting with -" {
run v-add-mail-account-alias $user $domain test '-test'
assert_success
}
@test "MAIL: Add account alias ending with -" {
run v-add-mail-account-alias $user $domain test 'test-'
assert_success
}
@test "MAIL: Add account alias Invalid 2" {
run v-add-mail-account-alias $user $domain test 'hestia@test'
assert_failure $E_INVALID
Expand Down

0 comments on commit c538920

Please sign in to comment.