Browse Source

Fix to the Localpart Mail validator so it can accept aliases starting and ending with -

Christoph Schläpfer 1 year ago
parent
commit
1302bc275d
2 changed files with 6 additions and 4 deletions
  1. 1 1
      bin/v-delete-mail-account-alias
  2. 5 3
      func/main.sh

+ 1 - 1
bin/v-delete-mail-account-alias

@@ -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"

+ 5 - 3
func/main.sh

@@ -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