Skip to content

Commit 1302bc2

Browse files
author
Christoph Schläpfer
committed
Fix to the Localpart Mail validator so it can accept aliases starting and ending with -
1 parent 131dbc1 commit 1302bc2

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
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

0 commit comments

Comments
 (0)