diff --git a/src/lib-sieve/sieve-validator.c b/src/lib-sieve/sieve-validator.c
index 29b3a936b98f58483b6219390d131a20af2918df..846ac147ea364fbc51e3cdaed74dcdb403e17a45 100644
--- a/src/lib-sieve/sieve-validator.c
+++ b/src/lib-sieve/sieve-validator.c
@@ -352,8 +352,16 @@ void sieve_validator_register_command
 static void sieve_validator_register_unknown_command
 (struct sieve_validator *valdtr, const char *command)
 {
-	(void)_sieve_validator_register_command
-		(valdtr, NULL, &unknown_command, command);
+	struct sieve_command_registration *cmd_reg =
+		sieve_validator_find_command_registration(valdtr, command);
+
+	if (cmd_reg == NULL) {
+		(void)_sieve_validator_register_command
+			(valdtr, NULL, &unknown_command, command);
+	} else {
+		i_assert(cmd_reg->cmd_def == NULL);
+		cmd_reg->cmd_def = &unknown_command;
+	}
 }
 
 /*const struct sieve_command *sieve_validator_find_command